Skip to content

Commit ca9e8cc

Browse files
committed
Ensure that client-side commands do not clash with server-side.
- Some client-side commands that call their server-side counterparts via. java.execute.workspaceCommand clash with the same command when it gets registered again via client/registerCapability - Fixes #2331 Signed-off-by: Roland Grunberg <rgrunber@redhat.com>
1 parent 8fbc1fa commit ca9e8cc

File tree

7 files changed

+37
-27
lines changed

7 files changed

+37
-27
lines changed

package.json

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -877,7 +877,7 @@
877877
"category": "Java"
878878
},
879879
{
880-
"command": "java.project.import",
880+
"command": "java.project.import.command",
881881
"title": "%java.project.import%",
882882
"category": "Java"
883883
},
@@ -912,22 +912,22 @@
912912
"category": "Java"
913913
},
914914
{
915-
"command": "java.project.updateSourceAttachment",
915+
"command": "java.project.updateSourceAttachment.command",
916916
"title": "%java.project.updateSourceAttachment%",
917917
"category": "Java"
918918
},
919919
{
920-
"command": "java.project.addToSourcePath",
920+
"command": "java.project.addToSourcePath.command",
921921
"title": "%java.project.addToSourcePath%",
922922
"category": "Java"
923923
},
924924
{
925-
"command": "java.project.removeFromSourcePath",
925+
"command": "java.project.removeFromSourcePath.command",
926926
"title": "%java.project.removeFromSourcePath%",
927927
"category": "Java"
928928
},
929929
{
930-
"command": "java.project.listSourcePaths",
930+
"command": "java.project.listSourcePaths.command",
931931
"title": "%java.project.listSourcePaths%",
932932
"category": "Java"
933933
},
@@ -999,18 +999,18 @@
999999
},
10001000
{
10011001
"when": "explorerResourceIsFolder&&javaLSReady",
1002-
"command": "java.project.addToSourcePath",
1002+
"command": "java.project.addToSourcePath.command",
10031003
"group": "1_javaactions@1"
10041004
},
10051005
{
10061006
"when": "explorerResourceIsFolder&&javaLSReady",
1007-
"command": "java.project.removeFromSourcePath",
1007+
"command": "java.project.removeFromSourcePath.command",
10081008
"group": "1_javaactions@2"
10091009
}
10101010
],
10111011
"editor/context": [
10121012
{
1013-
"command": "java.project.updateSourceAttachment",
1013+
"command": "java.project.updateSourceAttachment.command",
10141014
"when": "editorReadonly && editorLangId == java",
10151015
"group": "1_javaactions"
10161016
},
@@ -1036,7 +1036,7 @@
10361036
"when": "javaLSReady"
10371037
},
10381038
{
1039-
"command": "java.project.import",
1039+
"command": "java.project.import.command",
10401040
"when": "javaLSReady"
10411041
},
10421042
{
@@ -1048,7 +1048,7 @@
10481048
"when": "javaLSReady"
10491049
},
10501050
{
1051-
"command": "java.project.listSourcePaths",
1051+
"command": "java.project.listSourcePaths.command",
10521052
"when": "javaLSReady"
10531053
},
10541054
{
@@ -1072,15 +1072,15 @@
10721072
"when": "false"
10731073
},
10741074
{
1075-
"command": "java.project.updateSourceAttachment",
1075+
"command": "java.project.updateSourceAttachment.command",
10761076
"when": "false"
10771077
},
10781078
{
1079-
"command": "java.project.addToSourcePath",
1079+
"command": "java.project.addToSourcePath.command",
10801080
"when": "false"
10811081
},
10821082
{
1083-
"command": "java.project.removeFromSourcePath",
1083+
"command": "java.project.removeFromSourcePath.command",
10841084
"when": "false"
10851085
},
10861086
{

src/buildpath.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export interface ListCommandResult extends Result {
2121
}
2222

2323
export function registerCommands(context: ExtensionContext) {
24-
context.subscriptions.push(commands.registerCommand(Commands.ADD_TO_SOURCEPATH, async (uri: Uri) => {
24+
context.subscriptions.push(commands.registerCommand(Commands.ADD_TO_SOURCEPATH_CMD, async (uri: Uri) => {
2525
const result = await <any>commands.executeCommand(Commands.EXECUTE_WORKSPACE_COMMAND, Commands.ADD_TO_SOURCEPATH, uri.toString());
2626
if (result.status) {
2727
if (result.sourcePaths) {
@@ -33,7 +33,7 @@ export function registerCommands(context: ExtensionContext) {
3333
}
3434
}));
3535

36-
context.subscriptions.push(commands.registerCommand(Commands.REMOVE_FROM_SOURCEPATH, async (uri: Uri) => {
36+
context.subscriptions.push(commands.registerCommand(Commands.REMOVE_FROM_SOURCEPATH_CMD, async (uri: Uri) => {
3737
const result = await <any>commands.executeCommand(Commands.EXECUTE_WORKSPACE_COMMAND, Commands.REMOVE_FROM_SOURCEPATH, uri.toString());
3838
if (result.status) {
3939
if (result.sourcePaths) {
@@ -45,7 +45,7 @@ export function registerCommands(context: ExtensionContext) {
4545
}
4646
}));
4747

48-
context.subscriptions.push(commands.registerCommand(Commands.LIST_SOURCEPATHS, async() => {
48+
context.subscriptions.push(commands.registerCommand(Commands.LIST_SOURCEPATHS_CMD, async() => {
4949
const result: ListCommandResult = await commands.executeCommand<ListCommandResult>(Commands.EXECUTE_WORKSPACE_COMMAND, Commands.LIST_SOURCEPATHS);
5050
if (result.status) {
5151
if (!result.data || !result.data.length) {

src/commands.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,27 +104,37 @@ export namespace Commands {
104104
export const CLEAN_WORKSPACE = 'java.clean.workspace';
105105
/**
106106
* Update the source attachment for the selected class file
107+
* client-side & server-side commands
107108
*/
109+
export const UPDATE_SOURCE_ATTACHMENT_CMD = 'java.project.updateSourceAttachment.command';
108110
export const UPDATE_SOURCE_ATTACHMENT = 'java.project.updateSourceAttachment';
109111
/**
110112
* Resolve the source attachment information for the selected class file
111113
*/
112114
export const RESOLVE_SOURCE_ATTACHMENT = 'java.project.resolveSourceAttachment';
113115
/**
114116
* Mark the folder as the source root of the closest project.
117+
* client-side & server-side commands
115118
*/
119+
export const ADD_TO_SOURCEPATH_CMD = 'java.project.addToSourcePath.command';
116120
export const ADD_TO_SOURCEPATH = 'java.project.addToSourcePath';
117121
/**
118122
* Unmark the folder as the source root of the project.
123+
* client-side & server-side commands
119124
*/
125+
export const REMOVE_FROM_SOURCEPATH_CMD = 'java.project.removeFromSourcePath.command';
120126
export const REMOVE_FROM_SOURCEPATH = 'java.project.removeFromSourcePath';
121127
/**
122128
* List all recognized source roots in the workspace.
129+
* client-side & server-side commands
123130
*/
131+
export const LIST_SOURCEPATHS_CMD = 'java.project.listSourcePaths.command';
124132
export const LIST_SOURCEPATHS = 'java.project.listSourcePaths';
125133
/**
126134
* Import new projects
135+
* client-side & server-side commands
127136
*/
137+
export const IMPORT_PROJECTS_CMD = 'java.project.import.command';
128138
export const IMPORT_PROJECTS = 'java.project.import';
129139
/**
130140
* Override or implements the methods from the supertypes.

src/fileEventHandler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ async function handleNewJavaFiles(e: FileCreateEvent) {
5050

5151
let sourcePaths: string[] = [];
5252
if (serverReady) {
53-
const result: ListCommandResult = await commands.executeCommand<ListCommandResult>(Commands.EXECUTE_WORKSPACE_COMMAND, Commands.LIST_SOURCEPATHS);
53+
const result: ListCommandResult = await commands.executeCommand<ListCommandResult>(Commands.EXECUTE_WORKSPACE_COMMAND, Commands.LIST_SOURCEPATHS_CMD);
5454
if (result && result.data && result.data.length) {
5555
sourcePaths = result.data.map((sourcePath) => sourcePath.path).sort((a, b) => b.length - a.length);
5656
}

src/standardLanguageClient.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ export class StandardLanguageClient {
260260
} else if (choice.startsWith(USE_JAVA)) {
261261
await workspace.getConfiguration().update(GRADLE_IMPORT_JVM, newJavaHome, ConfigurationTarget.Global);
262262
commands.executeCommand("workbench.action.openSettings", GRADLE_IMPORT_JVM);
263-
commands.executeCommand(Commands.IMPORT_PROJECTS);
263+
commands.executeCommand(Commands.IMPORT_PROJECTS_CMD);
264264
} else if (choice.startsWith(UPGRADE_GRADLE)) {
265265
const useWrapper = workspace.getConfiguration().get<boolean>("java.import.gradle.wrapper.enabled");
266266
if (!useWrapper) {
@@ -285,14 +285,14 @@ export class StandardLanguageClient {
285285
window.showTextDocument(document, {selection: new Range(distributionUrlRange.start, new Position(distributionUrlRange.start.line + 1, 0))});
286286
}
287287
}
288-
commands.executeCommand(Commands.IMPORT_PROJECTS);
288+
commands.executeCommand(Commands.IMPORT_PROJECTS_CMD);
289289
}
290290
}
291291
});
292292
}
293293

294294
private registerCommandsForStandardServer(context: ExtensionContext, jdtEventEmitter: EventEmitter<Uri>): void {
295-
context.subscriptions.push(commands.registerCommand(Commands.IMPORT_PROJECTS, async () => {
295+
context.subscriptions.push(commands.registerCommand(Commands.IMPORT_PROJECTS_CMD, async () => {
296296
return await commands.executeCommand<void>(Commands.EXECUTE_WORKSPACE_COMMAND, Commands.IMPORT_PROJECTS);
297297
}));
298298

@@ -432,7 +432,7 @@ export class StandardLanguageClient {
432432
});
433433
}));
434434

435-
context.subscriptions.push(commands.registerCommand(Commands.UPDATE_SOURCE_ATTACHMENT, async (classFileUri: Uri): Promise<boolean> => {
435+
context.subscriptions.push(commands.registerCommand(Commands.UPDATE_SOURCE_ATTACHMENT_CMD, async (classFileUri: Uri): Promise<boolean> => {
436436
const resolveRequest: SourceAttachmentRequest = {
437437
classFileUri: classFileUri.toString(),
438438
};

test/standard-mode-suite/extension.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ suite('Java Language Extension - Standard', () => {
3030
return vscode.commands.getCommands(true).then((commands) =>
3131
{
3232
const JAVA_COMMANDS = [
33-
Commands.ADD_TO_SOURCEPATH,
33+
Commands.ADD_TO_SOURCEPATH_CMD,
3434
Commands.APPLY_REFACTORING_COMMAND,
3535
Commands.APPLY_WORKSPACE_EDIT,
3636
Commands.CHOOSE_IMPORTS,
@@ -46,8 +46,8 @@ suite('Java Language Extension - Standard', () => {
4646
Commands.HASHCODE_EQUALS_PROMPT,
4747
Commands.IGNORE_INCOMPLETE_CLASSPATH,
4848
Commands.IGNORE_INCOMPLETE_CLASSPATH_HELP,
49-
Commands.IMPORT_PROJECTS,
50-
Commands.LIST_SOURCEPATHS,
49+
Commands.IMPORT_PROJECTS_CMD,
50+
Commands.LIST_SOURCEPATHS_CMD,
5151
Commands.NAVIGATE_TO_SUPER_IMPLEMENTATION_COMMAND,
5252
Commands.OPEN_CLIENT_LOG,
5353
Commands.OPEN_FORMATTER,
@@ -58,13 +58,13 @@ suite('Java Language Extension - Standard', () => {
5858
Commands.ORGANIZE_IMPORTS,
5959
Commands.OVERRIDE_METHODS_PROMPT,
6060
Commands.PROJECT_CONFIGURATION_STATUS,
61-
Commands.REMOVE_FROM_SOURCEPATH,
61+
Commands.REMOVE_FROM_SOURCEPATH_CMD,
6262
Commands.RENAME_COMMAND,
6363
Commands.SHOW_JAVA_IMPLEMENTATIONS,
6464
Commands.SHOW_JAVA_REFERENCES,
6565
Commands.SHOW_SERVER_TASK_STATUS,
6666
Commands.SWITCH_SERVER_MODE,
67-
Commands.UPDATE_SOURCE_ATTACHMENT,
67+
Commands.UPDATE_SOURCE_ATTACHMENT_CMD,
6868
Commands.RUNTIME_VALIDATION_OPEN,
6969
Commands.CHANGE_BASE_TYPE,
7070
Commands.SHOW_TYPE_HIERARCHY,

test/standard-mode-suite/publicApi.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ suite('Public APIs - Standard', () => {
159159
api.onDidProjectsImport(() => {
160160
return resolve();
161161
});
162-
await commands.executeCommand(Commands.IMPORT_PROJECTS);
162+
await commands.executeCommand(Commands.IMPORT_PROJECTS_CMD);
163163
});
164164
});
165165

0 commit comments

Comments
 (0)