Skip to content

fix(completion): suppress completions inside comments - #59

Merged
AlexanderBrevig merged 2 commits into
mainfrom
fix/no-completion-in-comments
Aug 31, 2026
Merged

fix(completion): suppress completions inside comments#59
AlexanderBrevig merged 2 commits into
mainfrom
fix/no-completion-in-comments

Conversation

@AlexanderBrevig

@AlexanderBrevig AlexanderBrevig commented Aug 31, 2026

Copy link
Copy Markdown
Owner

Refs #41.

Problem

forth-lsp offered word/colon completions even when the cursor was inside a comment. Typing a : inside a \ … line comment or ( … ) comment popped up : / :NONAME suggestions, as if starting a colon definition. That's wrong on its own, and it's very likely why #41 looks server-driven — the suggestion popup appears in the comment, and a client-side auto-closing pair (:;) from a Forth grammar extension then inserts the semicolon.

To be clear about scope: this does not insert or remove any ; — the server never did that (verified separately: completion returns bare labels, formatting never synthesizes a ;, and there's no on-type-formatting provider). This fixes the misleading completions that made the behavior look like forth-lsp.

Change

handle_completion now lexes the document and, if the cursor's byte offset falls inside a Comment or StackComment token, returns no completions and bails early. The comment's end offset is treated inclusively, so completions are suppressed even when the cursor is appended to the very end of a comment (the exact #41 keystroke).

Completion in real code is unaffected — a word being typed right after a stack comment on the same line (: foo ( a -- b ) du|) still completes, because the cursor is past the comment token.

Tests

  • Unit tests for position_in_comment: line comments, paren/stack comments, appending at the end of a comment, and negative cases in plain code.
  • tests/repro_issue_41.rs — an end-to-end regression test that spawns the real binary over stdio, opens a doc with : inside line and paren comments, and asserts (a) completion is empty inside the comment and (b) formatting introduces no extra semicolons.

256 unit tests + integration test pass; cargo clippy --all-targets clean.

AlexanderBrevig and others added 2 commits August 31, 2026 11:18
Typing inside a \ line comment or ( ... ) comment no longer triggers
word/colon completions. A ':' typed in a comment is prose, not the start
of a colon definition, so offering ':' / ':NONAME' there was misleading
(and made the popup in #41 look server-driven).

handle_completion now lexes the document and returns no completions when
the cursor's byte offset falls within a Comment or StackComment token.
The end offset is inclusive so completions are also suppressed while
appending to the end of a comment.

Adds unit tests for position_in_comment and an end-to-end regression test
(tests/repro_issue_41.rs) that drives the real binary over stdio and
asserts completion is empty inside a comment and formatting never injects
a stray semicolon.

Refs #41

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Fixes a formatting deviation merged in #58 that left `cargo fmt --all
--check` (and therefore main's CI) red.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@AlexanderBrevig
AlexanderBrevig merged commit 8ef23cb into main Aug 31, 2026
1 check passed
@AlexanderBrevig
AlexanderBrevig deleted the fix/no-completion-in-comments branch August 31, 2026 10:55
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