Skip to content

Commit ce6a11d

Browse files
committed
Should explicitly report the fatal settings error
Signed-off-by: Snjezana Peco <[email protected]>
1 parent 20f66cc commit ce6a11d

File tree

3 files changed

+49
-7
lines changed

3 files changed

+49
-7
lines changed

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,7 @@
543543
},
544544
"java.format.settings.url": {
545545
"type": "string",
546-
"markdownDescription": "Specifies the url or file path to the [Eclipse formatter xml settings](https://github.com/redhat-developer/vscode-java/wiki/Formatter-settings).",
546+
"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).",
547547
"default": null,
548548
"scope": "window"
549549
},
@@ -839,7 +839,7 @@
839839
},
840840
"java.settings.url": {
841841
"type": "string",
842-
"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)",
842+
"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)",
843843
"default": null,
844844
"scope": "window"
845845
},

src/extension.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { initialize as initializeRecommendation } from './recommendation';
1414
import { Commands } from './commands';
1515
import { ExtensionAPI, ClientStatus } from './extension.api';
1616
import { getJavaConfiguration, deleteDirectory, getBuildFilePatterns, getInclusionPatternsFromNegatedExclusion, convertToGlob, getExclusionBlob, ensureExists } from './utils';
17-
import { onConfigurationChange, getJavaServerMode, ServerMode, ACTIVE_BUILD_TOOL_STATE, handleTextBlockClosing } from './settings';
17+
import { onConfigurationChange, getJavaServerMode, ServerMode, ACTIVE_BUILD_TOOL_STATE, handleTextBlockClosing, checkJavaPreferences, checkSettings, isRemote } from './settings';
1818
import { logger, initializeLogFile } from './log';
1919
import glob = require('glob');
2020
import { SyntaxLanguageClient } from './syntaxLanguageClient';
@@ -185,6 +185,10 @@ export function activate(context: ExtensionContext): Promise<ExtensionAPI> {
185185

186186
cleanJavaWorkspaceStorage();
187187

188+
checkSettings('format.settings.url');
189+
190+
checkSettings('settings.url');
191+
188192
serverStatusBarProvider.initialize();
189193

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

859-
function isRemote(f) {
860-
return f !== null && f.startsWith('http:/') || f.startsWith('https:/') || f.startsWith('file:/');
861-
}
862-
863863
async function addFormatter(extensionPath, formatterUrl, defaultFormatter, relativePath) {
864864
const options: InputBoxOptions = {
865865
value: (relativePath ? relativePath : formatterUrl),

src/settings.ts

+42
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import * as fs from 'fs';
44
import * as path from 'path';
5+
import * as url from 'url';
56
import { window, Uri, workspace, WorkspaceConfiguration, commands, ConfigurationTarget, env, ExtensionContext, TextEditor, Range, Disposable, WorkspaceFolder, TextDocument, Position, SnippetString, TextLine } from 'vscode';
67
import { Commands } from './commands';
78
import { cleanWorkspaceFileName } from './extension';
@@ -55,6 +56,8 @@ export function onConfigurationChange(workspacePath: string) {
5556
}
5657
// update old config
5758
oldConfig = newConfig;
59+
checkSettings('format.settings.url');
60+
checkSettings('settings.url');
5861
});
5962
}
6063

@@ -319,3 +322,42 @@ export function handleTextBlockClosing(document: TextDocument, changes: readonly
319322
}
320323
}
321324
}
325+
326+
export function checkSettings(preferenceName) {
327+
const preference: string = getJavaConfiguration().get(preferenceName);
328+
let show = false;
329+
if (isRemote(preference)) {
330+
try {
331+
const fileUrl = new url.URL(preference);
332+
const protocol = fileUrl.protocol;
333+
if (protocol === 'file:') {
334+
show = !fs.existsSync(fileUrl);
335+
if (!show) {
336+
show = !preference.startsWith("file:///") && (preference.startsWith("file://") || !preference.startsWith("file:/"));
337+
}
338+
}
339+
} catch (err) {
340+
show = true;
341+
}
342+
} else if (preference !== null && !fs.existsSync(preference)) {
343+
show = true;
344+
}
345+
if (show) {
346+
const msg = `The 'java.${preferenceName}=${preference}' preference is not valid.`;
347+
const action = 'Open settings';
348+
const restartId = Commands.OPEN_JSON_SETTINGS;
349+
window.showWarningMessage(msg, action).then((selection) => {
350+
if (action === selection) {
351+
commands.executeCommand(restartId, `java.${preferenceName}`);
352+
}
353+
});
354+
}
355+
}
356+
357+
export function isRemote(f) {
358+
if (f !== null) {
359+
const protocol = url.parse(f).protocol;
360+
return protocol !== null && (protocol === 'file:' || protocol === 'http:' || protocol === 'https:');
361+
}
362+
return false;
363+
}

0 commit comments

Comments
 (0)