Skip to content

Commit

Permalink
Refine change behavior.
Browse files Browse the repository at this point in the history
Signed-off-by: Yaohai Zheng <[email protected]>
  • Loading branch information
yaohaizh authored and fbricon committed Jan 31, 2019
1 parent bb3c18c commit c7c94a5
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 29 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Change Log

## 0.38.0 (January 30th, 2019)
## 0.38.0 (January 31st, 2019)
* enhancement - new dialog asking to hide java project settings files on startup. See [#776](https://github.com/redhat-developer/vscode-java/pull/776).
* bug fix - pick up gradle properties updates when doing full build. See [#758](https://github.com/redhat-developer/vscode-java/issues/758).
* bug fix - fixed inactive autocompletion after inserting a snippet in some cases. See [#768](https://github.com/redhat-developer/vscode-java/issues/768).

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ The following settings are supported:
* `java.completion.enabled` : Enable/disable code completion support.

*New in 0.38.0:*
* `java.configuration.excludeProjectSettingsFiles`: Exclude the extension generated project setting files(.classpath, .project, .settings, .factorypath) from the file explorer. When set to false, it will not revert the changes made on the setting.json file(s).
* `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`.


Troubleshooting
Expand Down
28 changes: 21 additions & 7 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.excludeProjectSettingsFiles": {
"java.configuration.checkProjectSettingsExclusions": {
"type": "boolean",
"default": true,
"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).",
"description": "Checks if the extension-generated project settings files (.project, .classpath, .factorypath, .settings/) should be excluded from the file explorer.",
"scope": "window"
},
"java.configuration.updateBuildConfiguration": {
Expand Down
6 changes: 1 addition & 5 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -300,11 +300,7 @@ export function activate(context: ExtensionContext): Promise<ExtensionAPI> {
}
};
workspace.registerTextDocumentContentProvider('jdt', provider);
if (workspace.workspaceFolders) {
workspace.workspaceFolders.map((folder) => {
excludeProjectSettingsFiles(folder.uri);
});
}
excludeProjectSettingsFiles();
});

let cleanWorkspaceExists = fs.existsSync( path.join(workspacePath, cleanWorkspaceFileName));
Expand Down
61 changes: 48 additions & 13 deletions src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ import { getJavaConfiguration } from './utils';

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

const changeItem = {
global: 'Exclude globally',
workspace: 'Exclude in workspace',
never: 'Never'
};

const EXCLUDE_FILE_CONFIG = 'configuration.checkProjectSettingsExclusions';

let oldConfig: WorkspaceConfiguration = getJavaConfiguration();

export function onConfigurationChange() {
Expand All @@ -16,6 +24,9 @@ export function onConfigurationChange() {
return;
}
let newConfig = getJavaConfiguration();
if (newConfig.get(EXCLUDE_FILE_CONFIG)) {
excludeProjectSettingsFiles();
}
if (hasJavaConfigChanged(oldConfig, newConfig)) {
let msg = 'Java Language Server configuration changed, please restart VS Code.';
let action = 'Restart Now';
Expand All @@ -30,28 +41,52 @@ export function onConfigurationChange() {
});
}

export function excludeProjectSettingsFiles(workspaceUri: Uri) {
const excudedConfig = getJavaConfiguration().get('configuration.excludeProjectSettingsFiles');
export function excludeProjectSettingsFiles() {
if (workspace.workspaceFolders && workspace.workspaceFolders.length) {
workspace.workspaceFolders.forEach((folder) => {
excludeProjectSettingsFilesForWorkspace(folder.uri);
});
}
}

function excludeProjectSettingsFilesForWorkspace(workspaceUri: Uri) {
const excudedConfig = getJavaConfiguration().get(EXCLUDE_FILE_CONFIG);
if (excudedConfig) {
const config = workspace.getConfiguration('files', workspaceUri);
const excludedValue: Object = config.get('exclude');
const needExcludeFiles: Object = {};
const needExcludeFiles: string[] = [];

let needUpdate = false;
for (const hiddenFiles of DEFAULT_HIDDEN_FILES) {
if (!excludedValue.hasOwnProperty(hiddenFiles)) {
needExcludeFiles[hiddenFiles] = true;
for (const hiddenFile of DEFAULT_HIDDEN_FILES) {
if (!excludedValue.hasOwnProperty(hiddenFile)) {
needExcludeFiles.push(hiddenFile);
needUpdate = true;
}
}
if (needUpdate) {
window.showInformationMessage('Do you want to exclude the VSCode Java project settings files(.classpath, .project. .settings, .factorypath) 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);
const excludedInspectedValue = config.inspect('exclude');
const items = [changeItem.workspace, changeItem.never];
// Workspace file.exclude is undefined
if (!excludedInspectedValue.workspaceValue) {
items.unshift(changeItem.global);
}

window.showInformationMessage('Do you want to exclude the VS Code Java project settings files (.classpath, .project. .settings, .factorypath) from the file explorer?', ...items).then((result) => {
if (result === changeItem.global) {
excludedInspectedValue.globalValue = excludedInspectedValue.globalValue || {};
for (const hiddenFile of needExcludeFiles) {
excludedInspectedValue.globalValue[hiddenFile] = true;
}
config.update('exclude', excludedInspectedValue.globalValue, ConfigurationTarget.Global);
} if (result === changeItem.workspace) {
excludedInspectedValue.workspaceValue = excludedInspectedValue.workspaceValue || {};
for (const hiddenFile of needExcludeFiles) {
excludedInspectedValue.workspaceValue[hiddenFile] = true;
}
config.update('exclude', excludedInspectedValue.workspaceValue, ConfigurationTarget.Workspace);
} else if (result === changeItem.never) {
const storeInWorkspace = getJavaConfiguration().inspect(EXCLUDE_FILE_CONFIG).workspaceValue;
getJavaConfiguration().update(EXCLUDE_FILE_CONFIG, false, storeInWorkspace?ConfigurationTarget.Workspace:ConfigurationTarget.Global);
}
});
}
Expand Down

0 comments on commit c7c94a5

Please sign in to comment.