Skip to content

fix(completion): select top result after lsp updates - #314

Merged
fcoury-oai merged 1 commit into
mainfrom
fcoury/completion-first-selection
Aug 22, 2026
Merged

fix(completion): select top result after lsp updates#314
fcoury-oai merged 1 commit into
mainfrom
fcoury/completion-first-selection

Conversation

@fcoury-oai

Copy link
Copy Markdown
Collaborator

Why

Autocomplete opens immediately with matching buffer words while the language server is still responding. When LSP candidates arrive, the popup currently preserves that automatically selected buffer word, even when a better-ranked or explicitly preselected server result appears above it. Pressing Tab can therefore accept the wrong suggestion.

What changed

  • Track whether the completion selection was changed intentionally through keyboard navigation.
  • Let delayed LSP results select their highest-ranked or server-preselected candidate until the user chooses an item; preserve deliberate selections across asynchronous updates.
  • Reset explicit-selection tracking when the filter changes or the popup closes.
  • Add popup-level regressions for ranking, server preselection, manual navigation, and filter changes, plus an editor-level delayed-response and Tab-acceptance regression.

How to Test

  1. Open a file with an active language server and an existing buffer word that matches a prefix, then type that prefix. Wait for the LSP results and verify the best server suggestion becomes highlighted; press Tab and verify that suggestion is inserted.
  2. Trigger completion again, move to a different item with the arrow keys or Ctrl-N/Ctrl-P before the LSP response arrives, and verify the same manually selected item remains highlighted when the results refresh.
  3. After selecting an item manually, type another character or press Backspace. Verify a subsequent LSP refresh again selects the best result for the updated prefix.
  4. Run the focused automated coverage:
cargo test -p red --lib ui::completion::tests
cargo test -p red --lib delayed_lsp_completion_selects_its_best_match_over_buffer_words
cargo test -p red --test completion

@fcoury-oai
fcoury-oai merged commit 61107d5 into main Aug 22, 2026
10 checks passed
@fcoury-oai
fcoury-oai deleted the fcoury/completion-first-selection branch August 22, 2026 22:20
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