[BUG] textDocument/completion returns -32600 "invalid request" when auto-triggered, racing with textDocument/didChange

Open
#119 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
45/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Quiet
Tech stack
typescript, vscode
Domain
tooling

Research direction

Start by reproducing the auto-triggered request with verbose LSP tracing, then trace the textDocument/completion and textDocument/didChange handling in the extension or server. Done means typing a trigger character produces completion results without an -32600 invalid request, while explicit Ctrl+Space continues to work.

Written by the indexing model from the issue text.

Description

(Note: this bug report was generated when I tried to get Claude Code to help me set up autocompletion, but I am a real person :) )

Describe the bug

Auto-triggered completions (via the . trigger character) always fail with -32600: invalid request from the LSP server. Completions only succeed when explicitly invoked with Ctrl+Space after a pause in typing.

This means member access completions (e.g., math.) never appear automatically in VSCode despite . being registered as a trigger character in the server's completionProvider capabilities.

To Reproduce

Open a .mojo file in VSCode with the Mojo extension installed
Add import math at the top
Inside a function, type math.
Observe: no completion popup appears

For comparison, place the cursor after math. and press Ctrl+Space — completions appear correctly.

Expected behavior

Typing . should trigger the completion popup automatically, as . is registered in the server's completionProvider.triggerCharacters.

LSP Trace Evidence

With mojo.trace.server: verbose enabled, the auto-triggered completion requests consistently fail:

I[10:57:50.352] --> textDocument/didChange (version=6)
I[10:57:50.352] --> textDocument/completion(18)
I[10:57:50.352] --> reply:textDocument/completion(18): -32600: invalid request
The explicit Ctrl+Space invocation (after a pause, no concurrent didChange) succeeds:


I[10:58:53.922] --> textDocument/completion(77)
I[10:58:54.800] --> reply:textDocument/completion(77)
{"id":77,"jsonrpc":"2.0","result":{"isIncomplete":false,"items":[...]}}

The root cause appears to be a race condition: the LSP rejects textDocument/completion requests that arrive concurrently with textDocument/didChange notifications. The auto-trigger fires at the same instant as the document change, causing the rejection. Ctrl+Space works because the user pauses before pressing it, allowing the document change to finish processing.

Environment

Mojo version: 0.26.2 (via pixi)
OS: Linux (Ubuntu)
VSCode extension: modular-mojotools.vscode-mojo 26.2.0

Dominant language
TypeScript
Stars
38
Forks
17
Avg merge
4d 13h
Merged PRs (30d)
13

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from modular/vscode-mojo

All issues in modular/vscode-mojo

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.