Skip to content
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

Merged
merged 5 commits into from
Jan 31, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@
"description": "Specifies the severity of the message when the classpath is incomplete for a Java file",
"scope": "window"
},
"java.configuration.excludeProjectSettingFiles": {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hideProjectSettingsFiles

"type": "boolean",
"default": true,
"description": "Exclude the extension generated project setting files from file explorer.",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

settings from the file explorer

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need to explain setting it to false won't remove the exclusions

"scope": "window"
},
"java.configuration.updateBuildConfiguration": {
"type": [
"string"
Expand Down
42 changes: 8 additions & 34 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ SourceAttachmentRequest, SourceAttachmentResult, SourceAttachmentAttribute } fro
import { ExtensionAPI } from './extension.api';
import * as buildpath from './buildpath';
import * as net from 'net';
import { getJavaConfiguration } from './utils';
import { onConfigurationChange, excludeProjectSettingFiles } from './setting';

let oldConfig;
let lastStatus;
let languageClient: LanguageClient;
let jdtEventEmitter = new EventEmitter<Uri>();
Expand Down Expand Up @@ -82,7 +83,6 @@ export function activate(context: ExtensionContext): Promise<ExtensionAPI> {
item.command = Commands.OPEN_OUTPUT;
let progressBar = window.createStatusBarItem(StatusBarAlignment.Left, Number.MIN_VALUE+1);

oldConfig = getJavaConfiguration();
let serverOptions;
let port = process.env['SERVER_PORT'];
if (!port) {
Expand Down Expand Up @@ -301,6 +301,11 @@ export function activate(context: ExtensionContext): Promise<ExtensionAPI> {
}
};
workspace.registerTextDocumentContentProvider('jdt', provider);
if (workspace.workspaceFolders) {
workspace.workspaceFolders.map((folder) => {
excludeProjectSettingFiles(folder.uri);
});
}
});

let cleanWorkspaceExists = fs.existsSync( path.join(workspacePath, cleanWorkspaceFileName));
Expand Down Expand Up @@ -435,34 +440,6 @@ function isJavaConfigFile(path: String) {
return path.endsWith('pom.xml') || path.endsWith('.gradle');
}

function onConfigurationChange() {
return workspace.onDidChangeConfiguration(params => {
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);
}
});
}
});
}

function hasJavaConfigChanged(oldConfig, newConfig) {
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);
}


function getTempWorkspace() {
return path.resolve(os.tmpdir(), 'vscodesws_' + makeRandomHexString(5));
}
Expand All @@ -477,9 +454,6 @@ function makeRandomHexString(length) {
return result;
}

function getJavaConfiguration(): WorkspaceConfiguration {
return workspace.getConfiguration('java');
}

async function cleanWorkspace(workspacePath) {
const doIt = 'Restart and delete';
Expand Down Expand Up @@ -746,4 +720,4 @@ function isPrefix(parentPath: string, childPath: string): boolean {
}
const relative = path.relative(parentPath, childPath);
return !!relative && !relative.startsWith('..') && !path.isAbsolute(relative);
}
}
53 changes: 53 additions & 0 deletions src/setting.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
'use strict';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

settings.ts


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


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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HIDDEN


let oldConfig = getJavaConfiguration();

export function onConfigurationChange() {
return workspace.onDidChangeConfiguration(params => {
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 excludeProjectSettingFiles(workspaceUri: Uri) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

excludeProjectSettingsFiles

if (getJavaConfiguration().get<Boolean>('configuration.excludeProjectSettingFiles')) {
const config = workspace.getConfiguration('files', workspaceUri);
const excludeValue: Object = config.get('exclude');

for (const hiddenFiles of DEFAULT_HIIDEN_FILES) {
if (!excludeValue.hasOwnProperty(hiddenFiles)) {
excludeValue[hiddenFiles] = true;
}

}
config.update('exclude', excludeValue);
}
}

function hasJavaConfigChanged(oldConfig, newConfig) {
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);
}
7 changes: 7 additions & 0 deletions src/utils.ts
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');
}