Skip to content

fix(lsp): preserve auto-imports after continued typing - #329

Merged
fcoury-oai merged 1 commit into
mainfrom
fcoury/completion-auto-import
Aug 23, 2026
Merged

fix(lsp): preserve auto-imports after continued typing#329
fcoury-oai merged 1 commit into
mainfrom
fcoury/completion-auto-import

Conversation

@fcoury-oai

Copy link
Copy Markdown
Collaborator

Why

Rust auto-import candidates defer their import edits until completionItem/resolve. When the user continued typing while the completion menu stayed open, the selected item still carried opaque server data and ranges from the earlier request. rust-analyzer could no longer match that stale item, so Red inserted the completion text without its import.

What Changed

  • Refresh a selected deferred completion at the current cursor position when the completion snapshot changed.
  • Match the refreshed candidate using its stable visible identity, then resolve the fresh server item for import edits.
  • Route refresh responses and failures separately from normal completion requests while preserving stale-response checks.
  • Add regression coverage for applying refreshed server ranges after passthrough typing.

How to Test

  1. In a Rust file, define module::Something outside the current scope and type Som at a use site.
  2. Open completion, type e while the menu remains open, then select Something (auto import module::Something).
  3. Verify Red inserts both Something and the corresponding use statement.
  4. Undo once and verify the accepted completion and import are removed together while the character typed before acceptance remains.
  5. As a regression check, accept a normal TypeScript auto-import completion and verify its eager import edit still applies.

Automated coverage:

  • cargo test completion_resolve -- --nocapture
  • cargo test --test completion -- --nocapture
  • cargo clippy --all-targets --all-features -- -D warnings

@fcoury
fcoury force-pushed the fcoury/completion-auto-import branch from 8200e0e to 8f8966b Compare August 23, 2026 16:49
@fcoury-oai
fcoury-oai merged commit d1442f5 into main Aug 23, 2026
10 checks passed
@fcoury-oai
fcoury-oai deleted the fcoury/completion-auto-import branch August 23, 2026 17:01
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