Skip to content

Commit 01c1612

Browse files
authored
always exclude project settings files by default (#1779)
* always exclude project settings files by default Signed-off-by: Yan Zhang <[email protected]> * address comments Signed-off-by: Yan Zhang <[email protected]>
1 parent 5733ef1 commit 01c1612

File tree

3 files changed

+19
-27
lines changed

3 files changed

+19
-27
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ The following settings are supported:
111111
* `java.trace.server` : Traces the communication between VS Code and the Java language server.
112112
* `java.configuration.updateBuildConfiguration` : Specifies how modifications on build files update the Java classpath/configuration. Supported values are `disabled` (nothing happens), `interactive` (asks about updating on every modification), `automatic` (updating is automatically triggered).
113113
* `java.configuration.maven.userSettings` : Path to Maven's user settings.xml.
114-
* `java.configuration.checkProjectSettingsExclusions`: Checks if the extension-generated project settings files (`.project`, `.classpath`, `.factorypath`, `.settings/`) should be excluded from the file explorer. Defaults to `true`.
114+
* `java.configuration.checkProjectSettingsExclusions`: Controls whether to exclude extension-generated project settings files (`.project`, `.classpath`, `.factorypath`, `.settings/`) from the file explorer. Defaults to `true`.
115115
* `java.referencesCodeLens.enabled` : Enable/disable the references code lenses.
116116
* `java.implementationsCodeLens.enabled` : Enable/disable the implementations code lenses.
117117
* `java.signatureHelp.enabled` : Enable/disable signature help support (triggered on `(`).

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@
137137
"java.configuration.checkProjectSettingsExclusions": {
138138
"type": "boolean",
139139
"default": true,
140-
"description": "Checks if the extension-generated project settings files (.project, .classpath, .factorypath, .settings/) should be excluded from the file explorer.",
140+
"description": "Controls whether to exclude extension-generated project settings files (.project, .classpath, .factorypath, .settings/) from the file explorer.",
141141
"scope": "window"
142142
},
143143
"java.configuration.updateBuildConfiguration": {

src/settings.ts

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,9 @@ export function excludeProjectSettingsFiles() {
5656
}
5757

5858
function excludeProjectSettingsFilesForWorkspace(workspaceUri: Uri) {
59-
const excudedConfig = getJavaConfiguration().get(EXCLUDE_FILE_CONFIG);
60-
if (excudedConfig) {
59+
const javaConfig = getJavaConfiguration();
60+
const checkExclusionConfig = javaConfig.get(EXCLUDE_FILE_CONFIG);
61+
if (checkExclusionConfig) {
6162
const config = workspace.getConfiguration('files', workspaceUri);
6263
const excludedValue: Object = config.get('exclude');
6364
const needExcludeFiles: string[] = [];
@@ -71,30 +72,21 @@ function excludeProjectSettingsFilesForWorkspace(workspaceUri: Uri) {
7172
}
7273
if (needUpdate) {
7374
const excludedInspectedValue = config.inspect('exclude');
74-
const items = [changeItem.workspace, changeItem.never];
75-
// Workspace file.exclude is undefined
76-
if (!excludedInspectedValue.workspaceValue) {
77-
items.unshift(changeItem.global);
78-
}
79-
80-
window.showInformationMessage(`Do you want to exclude the ${env.appName} Java project settings files (.classpath, .project, .settings, .factorypath) from the file explorer?`, ...items).then((result) => {
81-
if (result === changeItem.global) {
82-
excludedInspectedValue.globalValue = excludedInspectedValue.globalValue || {};
83-
for (const hiddenFile of needExcludeFiles) {
84-
excludedInspectedValue.globalValue[hiddenFile] = true;
85-
}
86-
config.update('exclude', excludedInspectedValue.globalValue, ConfigurationTarget.Global);
87-
} if (result === changeItem.workspace) {
88-
excludedInspectedValue.workspaceValue = excludedInspectedValue.workspaceValue || {};
89-
for (const hiddenFile of needExcludeFiles) {
90-
excludedInspectedValue.workspaceValue[hiddenFile] = true;
91-
}
92-
config.update('exclude', excludedInspectedValue.workspaceValue, ConfigurationTarget.Workspace);
93-
} else if (result === changeItem.never) {
94-
const storeInWorkspace = getJavaConfiguration().inspect(EXCLUDE_FILE_CONFIG).workspaceValue;
95-
getJavaConfiguration().update(EXCLUDE_FILE_CONFIG, false, storeInWorkspace ? ConfigurationTarget.Workspace : ConfigurationTarget.Global);
75+
const checkExclusionInWorkspace = javaConfig.inspect(EXCLUDE_FILE_CONFIG).workspaceValue;
76+
if (checkExclusionInWorkspace) {
77+
const workspaceValue = excludedInspectedValue.workspaceValue || {};
78+
for (const hiddenFile of needExcludeFiles) {
79+
workspaceValue[hiddenFile] = true;
9680
}
97-
});
81+
config.update('exclude', workspaceValue, ConfigurationTarget.Workspace);
82+
} else {
83+
// by default save to global settings
84+
const globalValue = excludedInspectedValue.globalValue = excludedInspectedValue.globalValue || {};
85+
for (const hiddenFile of needExcludeFiles) {
86+
globalValue[hiddenFile] = true;
87+
}
88+
config.update('exclude', globalValue, ConfigurationTarget.Global);
89+
}
9890
}
9991
}
10092
}

0 commit comments

Comments
 (0)