Skip to content

fix: run LspPlugin command handlers on the async thread - #3055

Merged
rwols merged 3 commits into
mainfrom
fix/command-handler-async-thread
Oct 10, 2026
Merged

rwols merged 3 commits into
mainfrom
fix/command-handler-async-thread

Conversation

@rchl

@rchl rchl commented Oct 7, 2026

Copy link
Copy Markdown
Member

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.

`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.
Comment thread plugin/core/sessions.py Outdated
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]

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
rwols merged commit 5c4a06a into main Oct 10, 2026
9 checks passed
@rwols
rwols deleted the fix/command-handler-async-thread branch October 10, 2026 13:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants