feat(autocomplete): match completions against their filterText - #6002
Open
boogie wants to merge 1 commit into
Open
feat(autocomplete): match completions against their filterText#6002boogie wants to merge 1 commit into
boogie wants to merge 1 commit into
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
FilteredListmatches 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:A concrete case: a server offers
iframeas the label while the user has typed<ifra. Ace drops the completion, becauseiframedoes 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:
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:
ignoreCaptionoption, being set per completion rather than per provider.The popup's highlight rendering needs no change.
$tokenizeRowderives 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.tsis regenerated for the new property.Tests
test: completions are matched against filterText when it is provided— with<part of the identifier, typing<ifrakeeps the completion declaringfilterText: "<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 existingignoreCaptiontests.Open kitchen-sink @ 502966a74c7767caca99eddd292d17aba092ba89