Skip to content

Commit 1a13ed8

Browse files
LeonovecSergeyfbricon
authored andcommitted
Make one pop-up dialog asking for reload.
Use regular expression to check java build file names. Signed-off-by: Siarhei Leanavets <Siarhei_Leanavets1@epam.com> Signed-off-by: Siarhei Leanavets <Siarhei_Leanavets1@epam.com>
1 parent 43c13eb commit 1a13ed8

5 files changed

Lines changed: 27 additions & 42 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
"main": "./dist/extension",
3737
"contributes": {
3838
"javaBuildFilePatterns": [
39-
"pom.xml", ".gradle"
39+
"^pom.xml$", ".*\\.gradle$"
4040
],
4141
"semanticTokenTypes": [
4242
{

schemas/package.schema.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"markdownDescription": "Java build file patterns",
2020
"items": {
2121
"type": "string",
22-
"description": "Specific build file patterns"
22+
"description": "Regular expressions for specifying build file"
2323
}
2424
}
2525
}

src/plugin.ts

Lines changed: 18 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -46,65 +46,46 @@ export function collectBuildFilePattern(extensions: readonly vscode.Extension<an
4646
}
4747

4848
export function onExtensionChange(extensions: readonly vscode.Extension<any>[]) {
49-
updateExistingExtensions(extensions);
50-
updateExistinguildFilePatterns(extensions);
51-
49+
if (isExistingExtensionsUpdated(extensions) || isExistingBuildFilePatternsUpdated(extensions)) {
50+
const msg = `Java Extension Contributions changed, reloading ${vscode.env.appName} is required for the changes to take effect.`;
51+
const action = 'Reload';
52+
const restartId = Commands.RELOAD_WINDOW;
53+
vscode.window.showWarningMessage(msg, action).then((selection) => {
54+
if (action === selection) {
55+
vscode.commands.executeCommand(restartId);
56+
}
57+
});
58+
}
5259
}
5360

54-
function updateExistingExtensions(extensions: readonly vscode.Extension<any>[]) {
61+
function isExistingExtensionsUpdated(extensions: readonly vscode.Extension<any>[]) {
5562
if (!existingExtensions) {
56-
return;
63+
return false;
5764
}
5865
const oldExtensions = new Set(existingExtensions.slice());
5966
const newExtensions = collectJavaExtensions(extensions);
60-
let hasChanged = ( oldExtensions.size !== newExtensions.length);
67+
const hasChanged = ( oldExtensions.size !== newExtensions.length);
6168
if (!hasChanged) {
6269
for (const newExtension of newExtensions) {
6370
if (!oldExtensions.has(newExtension)) {
64-
hasChanged = true;
65-
break;
71+
return true;
6672
}
6773
}
6874
}
69-
70-
if (hasChanged) {
71-
const msg = `Extensions to the Java Language Server changed, reloading ${vscode.env.appName} is required for the changes to take effect.`;
72-
const action = 'Reload';
73-
const restartId = Commands.RELOAD_WINDOW;
74-
vscode.window.showWarningMessage(msg, action).then((selection) => {
75-
if (action === selection) {
76-
vscode.commands.executeCommand(restartId);
77-
}
78-
});
79-
}
80-
8175
}
8276

83-
function updateExistinguildFilePatterns(extensions: readonly vscode.Extension<any>[]) {
77+
function isExistingBuildFilePatternsUpdated(extensions: readonly vscode.Extension<any>[]) {
8478
if (!existingBuildFilePatterns) {
85-
return;
79+
return false;
8680
}
8781
const oldPatterns = new Set(existingBuildFilePatterns.slice());
8882
const newPatterns = collectBuildFilePattern(extensions);
89-
let hasChanged = ( oldPatterns.size !== newPatterns.length);
83+
const hasChanged = ( oldPatterns.size !== newPatterns.length);
9084
if (!hasChanged) {
9185
for (const newPattern of newPatterns) {
9286
if (!oldPatterns.has(newPattern)) {
93-
hasChanged = true;
94-
break;
87+
return true;
9588
}
9689
}
9790
}
98-
99-
if (hasChanged) {
100-
const msg = `Java build file patterns changed, reloading ${vscode.env.appName} is required for the changes to take effect.`;
101-
const action = 'Reload';
102-
const restartId = Commands.RELOAD_WINDOW;
103-
vscode.window.showWarningMessage(msg, action).then((selection) => {
104-
if (action === selection) {
105-
vscode.commands.executeCommand(restartId);
106-
}
107-
});
108-
}
109-
11091
}

src/standardLanguageClient.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -467,9 +467,10 @@ function projectConfigurationUpdate(languageClient: LanguageClient, uri?: Uri) {
467467
}
468468
}
469469

470-
function isJavaConfigFile(path: String) {
471-
return buildFilePatterns.filter((pattern: String) => path.toLowerCase().endsWith(pattern.toLowerCase()))
472-
.length > 0;
470+
function isJavaConfigFile(path: string) {
471+
const fileName = require("path").basename(path);
472+
const regEx = new RegExp(buildFilePatterns.map(r => `(${r})`).join('|'), 'i');
473+
return regEx.test(fileName);
473474
}
474475

475476
function setProjectConfigurationUpdate(languageClient: LanguageClient, uri: Uri, status: FeatureStatus) {

test/resources/packageExample.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
"contributes": {
1515
"javaExtensions": [
1616
"./bin/java.extend.jar"
17+
],
18+
"javaBuildFilePatterns": [
19+
"^pom.xml$", ".*\\.gradle$"
1720
]
1821
},
1922
"extensionDependencies": [

0 commit comments

Comments
 (0)