Skip to content

Commit

Permalink
Should explicitly report the fatal settings error
Browse files Browse the repository at this point in the history
Signed-off-by: Snjezana Peco <[email protected]>
  • Loading branch information
snjeza committed May 13, 2022
1 parent 20f66cc commit f07e7e2
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 7 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@
},
"java.format.settings.url": {
"type": "string",
"markdownDescription": "Specifies the url or file path to the [Eclipse formatter xml settings](https://github.com/redhat-developer/vscode-java/wiki/Formatter-settings).",
"markdownDescription": "Specifies the url or file path to the Eclipse formatter xml. \n\nFor example: \n\n`\"java.format.settings.url\":\"file://home/myuser/format.xml\"`\n\n `\"java.format.settings.url\": \"https://raw.githubusercontent.com/google/styleguide/gh-pages/eclipse-java-google-style.xml\"`\n\n`\"java.format.settings.url\":\".vscode/format.xml\"`\n\n `\"java.format.settings.url\":\".vscode\\\\format.xml\" (Windows)` \n\n`\"java.format.settings.url\":\"file:///C:/Users/MyUser/format.xml\" (Windows)` \n\n`\"java.format.settings.url\":\"C:\\\\Users\\\\MyUser\\\\format.xml\" (Windows)` \n\nSee [Eclipse formatter xml settings](https://github.com/redhat-developer/vscode-java/wiki/Formatter-settings).",
"default": null,
"scope": "window"
},
Expand Down Expand Up @@ -839,7 +839,7 @@
},
"java.settings.url": {
"type": "string",
"markdownDescription": "Specifies the url or file path to the workspace Java settings. See [Setting Global Preferences](https://github.com/redhat-developer/vscode-java/wiki/Settings-Global-Preferences)",
"markdownDescription": "Specifies the url or file path to the workspace Java settings. \n\nFor example: \n\n`\"java.settings.url\":\"file://home/myuser/settings.prefs\"`\n\n`\"java.settings.url\":\".vscode/settings.prefs\"`\n\n `\"java.settings.url\":\".vscode\\\\settings.prefs\" (Windows)` \n\n`\"java.settings.url\":\"file:///C:/Users/MyUser/settings.prefs\" (Windows)` \n\n`\"java.settings.url\":\"C:\\\\Users\\\\MyUser\\\\settings.prefs\" (Windows)` \n\nSee [Setting Global Preferences](https://github.com/redhat-developer/vscode-java/wiki/Settings-Global-Preferences)",
"default": null,
"scope": "window"
},
Expand Down
10 changes: 5 additions & 5 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { initialize as initializeRecommendation } from './recommendation';
import { Commands } from './commands';
import { ExtensionAPI, ClientStatus } from './extension.api';
import { getJavaConfiguration, deleteDirectory, getBuildFilePatterns, getInclusionPatternsFromNegatedExclusion, convertToGlob, getExclusionBlob, ensureExists } from './utils';
import { onConfigurationChange, getJavaServerMode, ServerMode, ACTIVE_BUILD_TOOL_STATE, handleTextBlockClosing } from './settings';
import { onConfigurationChange, getJavaServerMode, ServerMode, ACTIVE_BUILD_TOOL_STATE, handleTextBlockClosing, checkJavaPreferences, checkSettings, isRemote } from './settings';
import { logger, initializeLogFile } from './log';
import glob = require('glob');
import { SyntaxLanguageClient } from './syntaxLanguageClient';
Expand Down Expand Up @@ -185,6 +185,10 @@ export function activate(context: ExtensionContext): Promise<ExtensionAPI> {

cleanJavaWorkspaceStorage();

checkSettings('format.settings.url');

checkSettings('settings.url');

serverStatusBarProvider.initialize();

return requirements.resolveRequirements(context).catch(error => {
Expand Down Expand Up @@ -856,10 +860,6 @@ function openDocument(extensionPath, formatterUrl, defaultFormatter, relativePat
});
}

function isRemote(f) {
return f !== null && f.startsWith('http:/') || f.startsWith('https:/') || f.startsWith('file:/');
}

async function addFormatter(extensionPath, formatterUrl, defaultFormatter, relativePath) {
const options: InputBoxOptions = {
value: (relativePath ? relativePath : formatterUrl),
Expand Down
39 changes: 39 additions & 0 deletions src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import * as fs from 'fs';
import * as path from 'path';
import * as url from 'url';
import { window, Uri, workspace, WorkspaceConfiguration, commands, ConfigurationTarget, env, ExtensionContext, TextEditor, Range, Disposable, WorkspaceFolder, TextDocument, Position, SnippetString, TextLine } from 'vscode';
import { Commands } from './commands';
import { cleanWorkspaceFileName } from './extension';
Expand Down Expand Up @@ -55,6 +56,8 @@ export function onConfigurationChange(workspacePath: string) {
}
// update old config
oldConfig = newConfig;
checkSettings('format.settings.url');
checkSettings('settings.url');
});
}

Expand Down Expand Up @@ -319,3 +322,39 @@ export function handleTextBlockClosing(document: TextDocument, changes: readonly
}
}
}

export function checkSettings(preferenceName) {
const preference: string = getJavaConfiguration().get(preferenceName);
let show = false;
if (isRemote(preference)) {
try {
const fileUrl = new url.URL(preference);
const protocol = fileUrl.protocol;
if (protocol === 'file:' && fs.existsSync(fileUrl)) {
show = !preference.startsWith("file:///") && (preference.startsWith("file://") || !preference.startsWith("file:/"));
}
} catch (err) {
show = true;
}
} else if (preference !== null && !fs.existsSync(preference)) {
show = true;
}
if (show) {
const msg = `The 'java.${preferenceName}=${preference}' preference is not valid.`;
const action = 'Open settings';
const restartId = Commands.OPEN_JSON_SETTINGS;
window.showWarningMessage(msg, action).then((selection) => {
if (action === selection) {
commands.executeCommand(restartId, `java.${preferenceName}`);
}
});
}
}

export function isRemote(f) {
if (f !== null) {
const protocol = url.parse(f).protocol;
return protocol !== null && (protocol === 'file:' || protocol === 'http:' || protocol === 'https:');
}
return false;
}

0 comments on commit f07e7e2

Please sign in to comment.