fix(completion): suppress completions inside comments - #59
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:/:NONAMEsuggestions, 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_completionnow lexes the document and, if the cursor's byte offset falls inside aCommentorStackCommenttoken, 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
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-targetsclean.