fix(vscode-companion): don't override cursorPosition=0 to text.length#2971
Open
chinesepowered wants to merge 1 commit intoQwenLM:mainfrom
Open
fix(vscode-companion): don't override cursorPosition=0 to text.length#2971chinesepowered wants to merge 1 commit intoQwenLM:mainfrom
chinesepowered wants to merge 1 commit intoQwenLM:mainfrom
Conversation
Completion trigger detection overrode a legitimate cursorPosition=0 to text.length when the text was non-empty. The walker on the text-node path already sets cursorPosition to text.length when the node is not found (line 292), so by the time we reach the override, position 0 means the cursor is genuinely at the start. Overriding it caused substring(0, text.length) to search the ENTIRE text for @ and /, pulling trigger matches from content AFTER the cursor.
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.
Fix VS Code companion autocomplete misfiring when cursor is at position 0.
TLDR
useCompletionTrigger.tsrewrote a legitimatecursorPosition === 0intotext.lengthwhenever the text was non-empty, causing trigger detection to search the entire text (including content after the cursor) for@and/characters. Users who placed the cursor at the start of existing text would see stale, incorrect autocomplete suggestions based on content that came after their cursor. The fix removes the override.Screenshots / Video Demo
N/A — behavior change; the concrete repro is described below.
Dive Deeper
The relevant section of
useCompletionTrigger.ts(line 295-300 before the fix):The walker above (line 292) already handles the "cursor not found" case by setting
cursorPosition = text.length:So by the time we reach the override,
cursorPosition === 0is unambiguous — it means the walker did find the cursor's text node and resolved its offset to 0 (cursor genuinely at the start of non-empty text). Rewriting 0 →text.lengthcausedtextBeforeCursor = text.substring(0, text.length)to span the entire text, so any@or/anywhere in the text would falsely register as a trigger match.Repro: In the VS Code companion webview, type
hello @someoneinto the input, then press Home to put the cursor at position 0. Before the fix, autocomplete would incorrectly trigger on the@someonefurther right in the text. After the fix, no trigger fires (correctly — there's nothing before position 0).The fix is a one-liner: trust
cursorPositionas the walker computed it.Note: the element-node path on line 270 uses its own
offset || text.lengthfallback, so the element-node case is unchanged. This PR only touches the text-node path's downstream override.Modified file:
packages/vscode-ide-companion/src/webview/hooks/useCompletionTrigger.ts— removed thecursorPosition === 0overrideReviewer Test Plan
hello @someoneinto the input@autocomplete appears (before the fix, it would)@at position 0 — cursor moves to position 1,@autocomplete should appear correctly@//completions elsewhere in the text continue to workTesting Matrix