Repository navigation
Closed
Labels
Milestone
Description
When developing my own extension and running it under the Extension Development Host in the debugger (I have it set to pause on uncaught exceptions), on opening a Java project (with this extension installed), I am getting the following stack trace:
Exception has occurred: Error: command 'java.project.listSourcePaths' already exists
t u.registerCommand ([/Users/inonit/Applications/Visual]() Studio Code.app[/Contents/Resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:93:28683]())
at Object.registerCommand ([/Users/inonit/Applications/Visual]() Studio Code.app[/Contents/Resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:107:30423]())
at X.register ([/Users/inonit/.vscode/extensions/redhat.java-1.3.0/dist/extension.js:2:945419]())
at [/Users/inonit/.vscode/extensions/redhat.java-1.3.0/dist/extension.js:2:966900]()
at new Promise (<anonymous>)
at w.handleRegistrationRequest ([/Users/inonit/.vscode/extensions/redhat.java-1.3.0/dist/extension.js:2:966543]())
at [/Users/inonit/.vscode/extensions/redhat.java-1.3.0/dist/extension.js:2:957330]()
at [/Users/inonit/.vscode/extensions/redhat.java-1.3.0/dist/extension.js:2:1106102]()
at [/Users/inonit/.vscode/extensions/redhat.java-1.3.0/dist/extension.js:2:1107161]()
at Immediate._onImmediate ([/Users/inonit/.vscode/extensions/redhat.java-1.3.0/dist/extension.js:2:1109867]())
at processImmediate (internal[/timers.js:461:21]())
at process.callbackTrampoline (internal[/async_hooks.js:131:14]())```
##### Environment
- Operating System: macOS (10.15.7 and 12.2.1)
- JDK version: Oracle JDK 1.8.0_212 and AdoptOpenJDK 11.0.8
- Visual Studio Code version: 1.64.2
- Java extension version: 1.3.0
##### Steps To Reproduce
1. Open Extension Development Host with my (unpublished) extension and with a window containing Java projects
2. Wait. I don't know the API well enough to know whether this is on a timer (the stack trace may suggest this) or whether it's more complicated than that (`processImmediate` is maybe just something to do with the event loop)?
##### Current Result
See stack trace of uncaught exception above.
##### Expected Result
No uncaught exception.
##### Additional Informations

Activity
rgrunber commentedon Feb 24, 2022
I see it as well
It seemed the stacktrace was associated with the language server registering commands to the client side, so I recalled we have https://github.com/eclipse/eclipse.jdt.ls/blob/master/org.eclipse.jdt.ls.core/plugin.xml#L54-L106 in JDT-LS. Any command there that's also registered on the client side (eg. https://github.com/redhat-developer/vscode-java/blob/master/src/buildpath.ts#L48) would run into this.
@fbricon @snjeza , is there a reason we register in both places ?
Looks to me like we have a command on the client side that is just meant to call the same command on the server side. Maybe just using a slightly different name would avoid the clash.
rgrunber commentedon Feb 28, 2022
I don't think the exception results in any unwanted behaviour, though I have a simple patch to fix it. I think the issue happens as follows :
We register a command on the client-side (eg. https://github.com/redhat-developer/vscode-java/blob/master/src/buildpath.ts#L48-L49) that simply calls
java.execute.workspaceCommandon the server side with the same named command id. That command id is also registered by the server to the client. See https://github.com/eclipse/eclipse.jdt.ls/blob/master/org.eclipse.jdt.ls.core/src/org/eclipse/jdt/ls/core/internal/handlers/JDTLanguageServer.java#L350-L351 & https://github.com/eclipse/eclipse.jdt.ls/blob/master/org.eclipse.jdt.ls.core/plugin.xml#L74 .The client side is registered first and the server side fails to register its command (already exists). However, I don't think this is an issue because we call the server side commands through `java.execute.workspaceCommand , and not directly.
Update : Yup, https://github.com/microsoft/vscode-languageserver-node/blob/main/client/src/common/client.ts#L2887-L2891 handles the registration of the commands passed to
workspace/executeCommandcoming from the server. It registers a command with the same ID. So one could dovscode.commands.executeCommand(ID)orvscode.commands.executeCommand("java.workspace.executeCommand", ID)and both should work.Ensure that client-side commands do not clash with server-side.
Ensure that client-side commands do not clash with server-side.
Ensure that client-side commands do not clash with server-side.