Repository navigation
fix: run LspPlugin command handlers on the async thread - #3055
Merged
Merged
Conversation
`Session.execute_command` called `@command_handler` methods on the calling thread. Commands run through `lsp_execute` (code lenses, completion item commands, inlay hints, command links) execute on the main thread, while code actions run on the async thread, so handlers ran on an unpredictable thread and could call `*_async` APIs from the UI thread. Always dispatch command handlers to the async thread, matching `@uri_handler`, and resolve with an Error if the handler raises.
rchl
commented
Oct 7, 2026
| self.request_id = 0 # Our request IDs are always integers. | ||
| self._logger = logger | ||
| self._response_handlers: dict[str | int, tuple[Request[Any, Any], Callable[[Any], None], Callable[[ResponseError], None]]] = {} # noqa: E501 | ||
| self._response_handlers: dict[str | int, tuple[Request[Any, Any], Callable[[Any], None], Callable[[ResponseError], None]]] = {} # ruff: ignore[line-too-long] |
Member
Author
There was a problem hiding this comment.
My ruff is making those changes on auto-fixing. I guess I'm using later version of ruff than LSP itself.
We should update but I don't want to cause unnecessary conflicts for asyncio branch so will revert for now.
rwols
approved these changes
Oct 10, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Session.execute_commandcalled@command_handlermethods on the calling thread. Commands run throughlsp_execute(code lenses, completion item commands, inlay hints, command links) execute on the main thread, while code actions run on the async thread, so handlers ran on an unpredictable thread and could call*_asyncAPIs from the UI thread.Always dispatch command handlers to the async thread, matching
@uri_handler, and resolve with an Error if the handler raises.