-
Notifications
You must be signed in to change notification settings - Fork 456
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Hide java project setting files by default. #776
Changes from 3 commits
33d26eb
60c5e2f
7cb7c9b
bb3c18c
c7c94a5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
'use strict'; | ||
|
||
import { window, Uri, workspace, WorkspaceConfiguration, commands, ConfigurationTarget } from 'vscode'; | ||
import { LanguageClient } from 'vscode-languageclient'; | ||
import { Commands } from './commands'; | ||
import { getJavaConfiguration } from './utils'; | ||
|
||
|
||
const DEFAULT_HIDDEN_FILES: string[] = ['**/.classpath', '**/.project', '**/.settings', '**/.factorypath']; | ||
|
||
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.'; | ||
let action = 'Restart Now'; | ||
let restartId = Commands.RELOAD_WINDOW; | ||
oldConfig = newConfig; | ||
window.showWarningMessage(msg, action).then((selection) => { | ||
if (action === selection) { | ||
commands.executeCommand(restartId); | ||
} | ||
}); | ||
} | ||
}); | ||
} | ||
|
||
export function excludeProjectSettingsFiles(workspaceUri: Uri) { | ||
const excudedConfig = getJavaConfiguration().get('configuration.excludeProjectSettingsFiles'); | ||
if (excudedConfig) { | ||
const config = workspace.getConfiguration('files', workspaceUri); | ||
const excludedValue: Object = config.get('exclude'); | ||
const needExcludeFiles: Object = {}; | ||
|
||
let needUpdate = false; | ||
for (const hiddenFiles of DEFAULT_HIDDEN_FILES) { | ||
if (!excludedValue.hasOwnProperty(hiddenFiles)) { | ||
needExcludeFiles[hiddenFiles] = true; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no, this will always store a subset of the files, overriding existing settings. |
||
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); | ||
} | ||
}); | ||
} | ||
} | ||
} | ||
|
||
function hasJavaConfigChanged(oldConfig: WorkspaceConfiguration, newConfig: WorkspaceConfiguration) { | ||
return hasConfigKeyChanged('home', oldConfig, newConfig) | ||
|| hasConfigKeyChanged('jdt.ls.vmargs', oldConfig, newConfig) | ||
|| hasConfigKeyChanged('progressReports.enabled', oldConfig, newConfig); | ||
} | ||
|
||
function hasConfigKeyChanged(key, oldConfig, newConfig) { | ||
return oldConfig.get(key) !== newConfig.get(key); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
'use strict'; | ||
|
||
import { workspace, WorkspaceConfiguration } from 'vscode'; | ||
|
||
export function getJavaConfiguration(): WorkspaceConfiguration { | ||
return workspace.getConfiguration('java'); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we want to check that if configuration.excludeProjectSettingsFiles is true, but it was false before, then excludeProjectSettingsFiles should be called.
Be aware that oldConfig is only changed if the "java configuration" changed, so it makes things a bit trickier.