Conversation
|
I have signed the CLA! |
soutaro
left a comment
There was a problem hiding this comment.
Thanks for working on this! There’s a multi-root workspace case we need to handle. Ruby LSP runs a separate server for each workspace folder, so two folders loading the same add-on will register the same command names, which results in a registration error in VS Code.
Could we make the command names unique per server instance? One option is a UUID suffix, with a helper that add-ons can use when building Code Lenses and other command references. Ruby LSP could map those names back to the original commands when dispatching to the add-on. I tested this approach in VS Code and confirmed that commands reached the correct server, including after restarting one of them.
|
@soutaro |
soutaro
left a comment
There was a problem hiding this comment.
Thanks! There are a few minor things, but the PR looks good overall.
| # typed: strict | ||
| # frozen_string_literal: true | ||
|
|
||
| require "securerandom" |
There was a problem hiding this comment.
I think this require can be deleted, since we usually load ruby_lsp library to use addon.
There was a problem hiding this comment.
Removed the explicit require "securerandom" in c0bf20a.
| addon = @addon_class.new | ||
| Addon.addons << addon | ||
|
|
||
| server = Server.new(test_mode: true) |
There was a problem hiding this comment.
Is there any reason not to use with_server(load_addons: false) here?
There was a problem hiding this comment.
Thank you for the suggestion.
I updated the test in bc946d4 to use with_server(load_addons: false).
The existing capability setup and stubs remain in place, while the shared helper now handles server cleanup, so the manual ensure and run_shutdown are no longer necessary.
|
@soutaro All done with the handling work. |
Motivation
Ruby LSP add-ons can contribute Code Lenses and other editor features, but there is currently no generic way for an add-on to register and handle the commands referenced by those features. This forces add-ons that need server-side command handling to provide additional editor integration.
Implementation
Addon#commandsandAddon#execute_commandhooks.Addon#command_id, which appends a UUID generated for each add-on instance to logical command identifiers.client/registerCapabilityrequest after add-ons are loaded.workspace/executeCommandrequest by resolving scoped IDs back to logical commands and routing them to the owning add-on.workspace.executeCommand.dynamicRegistrationcapability reported by the client and ignore errored add-ons.Add-ons are loaded after the initialize response, so dynamic registration keeps the existing add-on lifecycle unchanged. The VS Code extension does not require changes because its existing
vscode-languageclientdependency handles standard dynamic execute-command registration.Automated Tests
test/requests/execute_command_test.rb(registration, command ID uniqueness, and routing)test/global_state_test.rbManual Tests
Not run in a full VS Code session. The new server tests verify the dynamic registration payload and command dispatch. An end-to-end test can be performed with an add-on that returns a command from
commands, implementsexecute_command, and exposes a Code Lens usingcommand_id.