Skip to content

Fix trigger-character completion race in LSP proxy#122

Open
bro4all wants to merge 2 commits intomodular:mainfrom
bro4all:codex/fix-completion-race
Open

Fix trigger-character completion race in LSP proxy#122
bro4all wants to merge 2 commits intomodular:mainfrom
bro4all:codex/fix-completion-race

Conversation

@bro4all
Copy link
Copy Markdown

@bro4all bro4all commented Mar 31, 2026

Problem

Typing . in a Mojo file could trigger textDocument/completion at the same time as the preceding textDocument/didChange notification. The proxy wrote those packets independently, so the completion request could overtake the change and the server replied with -32600: invalid request.

Fix

Serialize all outgoing proxy packets through a single write queue in MojoLSPServer, and register pending requests before writing the request packet. That keeps didChange and later requests in order and closes the fast-response race.

Tests

  • Added a proxy regression test that proves a completion request does not start writing until the earlier notification write callback completes.
  • Added an extension-host completion test that exercises trigger-character completion after typing . in a Mojo file.
  • Verified with npm run ci, npm run typecheck, npm run build, npm run format, and the default VS Code test suite.

BEGIN_PUBLIC
[Mojo] Serialize LSP proxy packet writes

Auto-triggered completion could race with didChange because the proxy wrote outgoing LSP packets independently. Serialize proxy writes through a single queue and register pending requests before sending request packets so completion requests no longer overtake earlier document-change notifications.

Add regression coverage for the proxy write ordering and a completion test that exercises trigger-character completion after typing '.' in a Mojo file.
END_PUBLIC
@bro4all bro4all marked this pull request as ready for review March 31, 2026 01:16
BEGIN_PUBLIC
[Mojo] Fix lint for proxy regression tests

Address the GitHub lint failures in the new proxy regression tests by documenting the compiled proxy require in the TypeScript test and declaring the Node globals used by the fake LSP server helper.
END_PUBLIC

Signed-off-by: Omar Habra <omarbro4all@gmail.com>
@DuncanMcBain DuncanMcBain self-requested a review April 8, 2026 16:44
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.

1 participant