Skip to content

LSP: select the completion item that the server preselects (preselect) #2241

Done

Description

@lagergren

What

CompletionItem.preselect (completion item) asks the client to select that item when the list shows. The spec: "Only one completion item can be selected and that the client decides which item that is. The rule is that the first item of those that match best is selected."

The client announces it with textDocument.completion.completionItem.preselectSupport. The item is selected; the list is not reordered.

Why

  • typescript-language-server: preselect: entry.isRecommended (src/completion.ts). One case is the matching enum or class after new or in a typed position.
  • rust-analyzer: res.preselect = Some(true) for its most relevant items (crates/rust-analyzer/src/lsp/to_proto.rs).

What users miss: the item the server knows fits best, such as the expected type or the recommended member, is not the selected one. So Enter accepts something else.

Today

How it could be done

  • IntelliJ's extension point com.intellij.completion.skip (CompletionPreselectSkipper.skipElement(LookupElement, CompletionLocation), both versions) decides which items the lookup must not preselect. The first item that isn't skipped is selected.
  • When a completion result holds a preselected item, skip the LSP items of that result that aren't preselected. The preselected one then gets the selection, and the order stays as it is. That is what the spec asks: select, don't reorder.
  • Only the items of the same server and request are skipped, never those of other contributors. Amended on 2026-11-27, see feat: select the completion item that the language server preselects #2289: while a language server preselects an item of the completion, the items of the other contributors are skipped too. Skipping only decides which item is selected: no item is hidden or moved. IntelliJ asks the skippers once per item, when it is added, and selects the first item that isn't skipped, or the first item when it skips them all. If the other contributors' items were never skipped, typing text that filters out the preselected item would select another contributor's item below the LSP items, instead of the first LSP item.
  • Announce preselectSupport: true.
  • Optional: a client feature method (LSPCompletionFeature.isPreselect(item)), so that an adopter can turn it off.

Test

A completion fixture test with three items where the third has preselect: true. The third is selected, and the order is unchanged.

Activity

  1. added
    enhancement
    on Nov 25, 2026
  2. cordeirops commented on Nov 26, 2026

    @cordeirops
    Contributor

    Hi! I'd like to work on this issue, and I already have a solution in the PR #2289.

    /assign

    Thanks!

  3. modified the milestones: 0.30.3, 0.30.2 on Nov 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    completionenhancement

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions