Skip to content

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

Description

@randyzwitch

(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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions