Skip to content

LSP: support completion commit characters (commitCharacters, allCommitCharacters) #2235

Todo

Description

@lagergren

What

Completion commit characters are characters that accept the selected completion item and are then typed as usual. For example, . or ( after a function name. There are three sources:

  • CompletionItem.commitCharacters, per item. The client announces it with textDocument.completion.completionItem.commitCharactersSupport.
  • CompletionOptions.allCommitCharacters (3.2), for all items of the server.
  • CompletionList.itemDefaults.commitCharacters (3.17), announced in completionList.itemDefaults.

The spec: "If present, this will override allCommitCharacters." Since 3.18, CompletionList.applyKind can merge the two instead.

Why

  • typescript-language-server: sends per-item commitCharacters when the client sets commitCharactersSupport (src/lsp-server.ts, src/completion.ts). It moves them to itemDefaults when the client supports that.
  • Pyright and basedpyright: read commitCharactersSupport (languageServerBase.ts).
  • Dart: behind dart.previewCommitCharacters, which is in LSP4IJ's own dart-lsp template (templates/lsp/dart-lsp/settings.schema.json).

What users miss: typing foo. or foo( with the lookup open keeps the typed prefix and closes or refilters the lookup, instead of accepting fooBar and going on.

Today

How it could be done

  • Add a CharFilter (extension point com.intellij.lookup.charFilter, both versions). In acceptChar(c, prefixLength, lookup), when the current item is an LSPCompletionProposal and c is one of its commit characters, return Result.SELECT_ITEM_AND_FINISH_LOOKUP. The item's own list wins over itemDefaults and allCommitCharacters, as the spec says. Otherwise return null so that the other filters decide.
  • Commit only when the lookup is focused (Lookup.isFocused()). VS Code also commits only a suggestion that the user has selected. This avoids committing an item that the auto-popup merely shows while the user types.
  • handleInsert can see the character with context.getCompletionChar(). Check that the typed character is inserted once, after the item, and that a snippet template still starts.
  • Announce commitCharactersSupport: true, and add commitCharacters to completionList.itemDefaults.
  • Possibly a client setting to turn it off per server, as Dart offers on its side.

Test

Fixture tests:

  • . with a focused LSP item that has commitCharacters: ["."];
  • the same with the lookup unfocused;
  • allCommitCharacters only;
  • itemDefaults.commitCharacters overridden by an item's own list.

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. Please /assign

    Before I start, I checked the servers listed in the issue:

    • typescript-language-server sends commitCharacters [".", ",", ";"] on every item.
    • Dart sends ['('] only with dart.previewCommitCharacters.
    • Pyright/basedpyright read commitCharactersSupport, but the base class sends none
      (addExtraCommitChar is a no-op, only Pylance overrides it).

    IntelliJ's DefaultCharFilter already accepts the selected item for . , ; = space : ( when
    the lookup is focused, so I can't see a difference from this change with any of them.

    Do you have a server and a character (not in that list) where the current behavior is wrong,
    and should characters that the server doesn't list stop committing?

    Thanks!

  3. added this to the Backlog milestone on Nov 30, 2026
  4. lagergren commented on Dec 1, 2026

    @lagergren
    CollaboratorAuthor

    @cordeirops Thanks for checking. You're right: with a focused lookup, IntelliJ's own DefaultCharFilter already accepts the selected item on . , ; = space : (. So with typescript-language-server and Dart there is no visible difference, and I don't know of a server today that lists a character outside that set.

    What would still be worth doing:

    • The capability: announce commitCharactersSupport and itemDefaults.commitCharacters, so that servers which wait for them send them.
    • Characters IntelliJ doesn't commit on: a character that a server lists and IntelliJ doesn't, such as [, <, { or ", would then accept the selected item. As in the issue, only with a focused lookup.

    To your second question: no, characters that the server doesn't list should keep committing. IntelliJ users expect its own commit characters in every language, so LSP4IJ would only add the server's characters, never remove IntelliJ's.

    If that scope works for you, please take it, it's yours.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

completionenhancement

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions