Skip to content

feat(autocomplete): match completions against their filterText - #6002

Open
boogie wants to merge 1 commit into
ajaxorg:masterfrom
boogie:feat/completion-filter-text
Open

feat(autocomplete): match completions against their filterText#6002
boogie wants to merge 1 commit into
ajaxorg:masterfrom
boogie:feat/completion-filter-text

Conversation

@boogie

@boogie boogie commented Aug 14, 2026

Copy link
Copy Markdown

Problem

FilteredList matches every completion against the text it displays — its caption, or the value or snippet when there is no caption. A completion whose caption differs from what the user types to reach it is therefore filtered out entirely.

That is the normal shape of a language server completion. The protocol has a field for exactly this, CompletionItem.filterText, because the label and the text being matched are not the same thing:

If the text edit is a replace edit then the range denotes the word used for filtering. If the replace changes the text it most likely makes sense to specify a filter text to be used.

A concrete case: a server offers iframe as the label while the user has typed <ifra. Ace drops the completion, because iframe does not contain <.

The existing escape hatch, skipFilter, is all or nothing — it bypasses scoring and match highlighting along with the filtering, so the completion can no longer be ranked or narrowed at all.

This has forced workarounds downstream. In mkslanc/ace-linters#196 the conclusion was that a proper fix requires changing Ace itself:

this code is put there only as work-around for ace completer's FilteredList (…) So the patch should include re-writing some ace's prototypes.

Change

Completions accept an optional filterText. When present, that is what the completion is matched and scored against, in place of the text it displays.

Compatibility:

  • Completions without the property are matched exactly as before — the expression collapses to the previous one.
  • An empty string is ignored rather than meaning "match nothing".
  • Completions carrying no displayable text at all are still dropped up front, as before.
  • It takes precedence over the ignoreCaption option, being set per completion rather than per provider.

The popup's highlight rendering needs no change. $tokenizeRow derives highlight offsets from the caption on its own and skips any part it cannot locate there, so a completion reached through text that does not occur in its caption renders without a highlight rather than breaking. That limitation is documented on the property.

types/ace-modules.d.ts is regenerated for the new property.

Tests

  • test: completions are matched against filterText when it is provided — with < part of the identifier, typing <ifra keeps the completion declaring filterText: "<iframe" and drops the one relying on its caption, and inserting it replaces the typed text. Without the change the popup does not open at all.
  • test: should filter using filterText even if ignoreCaption true — pins the precedence, alongside the existing ignoreCaption tests.

Open kitchen-sink @ 502966a74c7767caca99eddd292d17aba092ba89

The completion list matches every item against the text it displays, so a
completion whose caption differs from what the user types to reach it is
filtered out entirely. This is the common case for language server
completions, where `CompletionItem.filterText` exists precisely to decouple
the two: an `iframe` caption reached by typing `<ifra`, for example. The
existing escape hatch, `skipFilter`, is all or nothing and drops the scoring
along with the filtering.

Add an optional `filterText` property to completions. When present it is what
the item is matched and scored against, in place of the text it displays, and
it takes precedence over the `ignoreCaption` option, being set per item rather
than per provider. Items without the property are matched exactly as before,
and completions carrying no displayable text are still dropped up front.

The popup derives its highlight positions from the caption on its own and
skips the parts it cannot find there, so an item reached through text that
does not occur in its caption renders without a highlight rather than
breaking. That limitation is noted on the property.
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