Skip to content

Commit

Permalink
Improve UX for changing settings.
Browse files Browse the repository at this point in the history
Signed-off-by: Yaohai Zheng <[email protected]>
  • Loading branch information
yaohaizh committed Jan 30, 2019
1 parent 33d26eb commit 60c5e2f
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 31 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ The following settings are supported:
* `java.import.gradle.enabled` : Enable/disable the Gradle importer.
* `java.import.maven.enabled` : Enable/disable the Maven importer.
* `java.autobuild.enabled` : Enable/disable the 'auto build'.
* `java.maxConcurrentBuilds`: Set max simultaneous project builds.
* `java.completion.favoriteStaticMembers` : Defines a list of static members or types with static members.
* `java.completion.importOrder` : Defines the sorting order of import statements.
* `java.progressReports.enabled` : [Experimental] Enable/disable progress reports from background processes on the server.
Expand All @@ -91,8 +92,8 @@ The following settings are supported:
* `java.completion.guessMethodArguments` : When set to true, method arguments are guessed when a method is selected from as list of code assist proposals.
* `java.completion.enabled` : Enable/disable code completion support.

*New in 0.36.0:*
* `java.maxConcurrentBuilds`: Set max simultaneous project builds.
*New in 0.38.0:*
* `java.configuration.excludeProjectSettingsFiles`: Exclude the extension generated project setting files(.classpath, .project, .settings) from the file explorer. When set to false, it will not revert the changes made on the setting.json file(s).


Troubleshooting
Expand Down
26 changes: 13 additions & 13 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,10 @@
"description": "Specifies the severity of the message when the classpath is incomplete for a Java file",
"scope": "window"
},
"java.configuration.excludeProjectSettingFiles": {
"java.configuration.excludeProjectSettingsFiles": {
"type": "boolean",
"default": true,
"description": "Exclude the extension generated project setting files from file explorer.",
"description": "Exclude the extension generated project setting files from the file explorer. When set false, it will not revert the changes made on the setting.json file(s).",
"scope": "window"
},
"java.configuration.updateBuildConfiguration": {
Expand Down
4 changes: 2 additions & 2 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { ExtensionAPI } from './extension.api';
import * as buildpath from './buildpath';
import * as net from 'net';
import { getJavaConfiguration } from './utils';
import { onConfigurationChange, excludeProjectSettingFiles } from './setting';
import { onConfigurationChange, excludeProjectSettingsFiles } from './setting';

let lastStatus;
let languageClient: LanguageClient;
Expand Down Expand Up @@ -303,7 +303,7 @@ export function activate(context: ExtensionContext): Promise<ExtensionAPI> {
workspace.registerTextDocumentContentProvider('jdt', provider);
if (workspace.workspaceFolders) {
workspace.workspaceFolders.map((folder) => {
excludeProjectSettingFiles(folder.uri);
excludeProjectSettingsFiles(folder.uri);
});
}
});
Expand Down
40 changes: 28 additions & 12 deletions src/setting.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
'use strict';

import { window, Uri, workspace, WorkspaceConfiguration, commands } from 'vscode';
import { window, Uri, workspace, WorkspaceConfiguration, commands, ConfigurationTarget } from 'vscode';
import { LanguageClient } from 'vscode-languageclient';
import { Commands } from './commands';
import { getJavaConfiguration } from './utils';


const DEFAULT_HIIDEN_FILES: string[] = ['**/.classpath', '**/.project', '**/.settings'];
const DEFAULT_HIDDEN_FILES: string[] = ['**/.classpath', '**/.project', '**/.settings'];

let oldConfig = getJavaConfiguration();
let oldConfig: WorkspaceConfiguration = getJavaConfiguration();

export function onConfigurationChange() {
return workspace.onDidChangeConfiguration(params => {
if (!params.affectsConfiguration('java')) {
return;
}
let newConfig = getJavaConfiguration();
if (hasJavaConfigChanged(oldConfig, newConfig)) {
let msg = 'Java Language Server configuration changed, please restart VS Code.';
Expand All @@ -27,22 +30,35 @@ export function onConfigurationChange() {
});
}

export function excludeProjectSettingFiles(workspaceUri: Uri) {
if (getJavaConfiguration().get<Boolean>('configuration.excludeProjectSettingFiles')) {
export function excludeProjectSettingsFiles(workspaceUri: Uri) {
const excudedConfig = getJavaConfiguration().get('configuration.excludeProjectSettingsFiles');
if (excudedConfig) {
const config = workspace.getConfiguration('files', workspaceUri);
const excludeValue: Object = config.get('exclude');
const excludedValue: Object = config.get('exclude');
const needExcludeFiles: Object = {};

for (const hiddenFiles of DEFAULT_HIIDEN_FILES) {
if (!excludeValue.hasOwnProperty(hiddenFiles)) {
excludeValue[hiddenFiles] = true;
let needUpdate = false;
for (const hiddenFiles of DEFAULT_HIDDEN_FILES) {
if (!excludedValue.hasOwnProperty(hiddenFiles)) {
needExcludeFiles[hiddenFiles] = true;
needUpdate = true;
}

}
config.update('exclude', excludeValue);
if (needUpdate) {
window.showInformationMessage('Do you want to exclude the VSCode Java project settings files(.classpath, .project. .settings) from the file explorer.', 'Always', 'Workspace', 'Never').then((result) => {
if (result === 'Always') {
config.update('exclude', needExcludeFiles, ConfigurationTarget.Global);
} if (result === 'Workspace') {
config.update('exclude', needExcludeFiles, ConfigurationTarget.Workspace);
} else if (result === 'Never') {
getJavaConfiguration().update('configuration.excludeProjectSettingsFiles', false, ConfigurationTarget.Global);
}
});
}
}
}

function hasJavaConfigChanged(oldConfig, newConfig) {
function hasJavaConfigChanged(oldConfig: WorkspaceConfiguration, newConfig: WorkspaceConfiguration) {
return hasConfigKeyChanged('home', oldConfig, newConfig)
|| hasConfigKeyChanged('jdt.ls.vmargs', oldConfig, newConfig)
|| hasConfigKeyChanged('progressReports.enabled', oldConfig, newConfig);
Expand Down

0 comments on commit 60c5e2f

Please sign in to comment.