Skip to content

fix(editor): send the pending text before asking for completions - #805

Merged
LeMyst merged 1 commit into
cooklang:mainfrom
LeMyst:fix/lsp-completion-race
Oct 28, 2026
Merged

LeMyst merged 1 commit into
cooklang:mainfrom
LeMyst:fix/lsp-completion-race

Conversation

@LeMyst

@LeMyst LeMyst commented Oct 28, 2026

Copy link
Copy Markdown
Collaborator

Closes #804

The editor's completion request now sends the text still waiting for the 150 ms didChange debounce first, so the language server completes the text as it is.

  • The debounced send moves into flushLspChange(). The debounce timer calls it as before, and the completion resolver calls it right before textDocument/completion. It sends nothing when no change is pending. The WebSocket keeps message order, so didChange arrives first.
  • It sends the editor's current content (CooklangEditor.getContent), which is what the timer would have sent at the end of the debounce anyway.
  • The debounce stays for ordinary typing, so the server still isn't sent a full document per keystroke.

Tests

  • editor-completion-typing.spec.ts types @sal without a pause in a recipe that uses @salt{} and expects salt to be offered. Run 5 times (--repeat-each=5): 5/5 pass with the fix, 5/5 fail without the flushLspChange() call.
  • The recipe name in the spec is a single word, so it doesn't depend on fix: recipe and ingredient names in any script #803 (the document URI fix). The two branches touch different parts of edit.html and merge cleanly.
  • cargo test --workspace: 1865 passed. Full chromium Playwright run green, apart from the specs that spawn target/debug/cook, which doesn't exist in my local setup. The pantry and shopping-list specs were rerun with --workers=1, as on CI.

🤖 Generated with Claude Code

https://claude.ai/code/session_01MmrM91dHzvQoaerCcR9wra

The editor sends its text to the language server 150 ms after the last
keystroke, but CodeMirror asks for completions as soon as typing pauses
for 100 ms. Typed without a pause, `@sal` was completed against the text
from before the `@`, and the list stayed empty; only typing slower than
the debounce got suggestions.

The completion request now sends the waiting change first. The socket
keeps the order, so the server reads the current text.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MmrM91dHzvQoaerCcR9wra
@LeMyst
LeMyst marked this pull request as ready for review October 28, 2026 18:57
@LeMyst
LeMyst merged commit 7a2cd0e into cooklang:main Oct 28, 2026
6 checks passed
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.

Editor completion lists nothing when typing fast: the request reaches the language server before the text

1 participant