Skip to content

Add provideCompletionItem middleware to rewrite MP snippet filterText - #610

Open
sharma1208 wants to merge 1 commit into
redhat-developer:masterfrom
sharma1208:mp-snippet-filtertext-fix
Open

Add provideCompletionItem middleware to rewrite MP snippet filterText#610
sharma1208 wants to merge 1 commit into
redhat-developer:masterfrom
sharma1208:mp-snippet-filtertext-fix

Conversation

@sharma1208

Copy link
Copy Markdown

Problem

MicroProfile snippet completion items (mpliveness, mpreadiness, mpnrc) only surface in VS Code when the user types the exact prefix mp. Typing a meaningful word fragment like live, health, or readi returns nothing.

The MP language server sets both label and filterText to the same short lowercase token (e.g. "mpliveness"). VS Code's fuzzyScore requires matched characters to start at a word boundary like an uppercase letter, space, or start of string. A string like "mpliveness" has no boundaries, so only a prefix matches.

This works fine in IntelliJ (LSP4IJ registers both filterText and label as lookup strings) and Eclipse (LSP4E uses ordered subsequence matching), but VS Code has no equivalent layer.

Fix

Add a provideCompletionItem middleware hook that rewrites filterText from the opaque token to item.detail (e.g. "mpliveness""MicroProfile Health liveness check") before items are returned to VS Code. This gives the fuzzy engine real word boundaries to match against.

The rewrite is guarded so it only applies when filterText and detail exist and differ, so regular Java completions are unaffected.

What works after this fix

Query Result
mp works (unchanged)
live now works
readi now works
health now works
check now works

Known limitation

Pure mid-word subsequences like ven (no word boundary before v in liveness) are not achievable with VS Code's boundary-anchored fuzzyScore regardless of the filterText value. This is a fundamental engine difference from LSP4E's subsequence matching.

Testing

Tested locally via Extension Development Host against a MicroProfile Gradle project.
Confirmed via provideCompletionItem middleware logging that item.detail carries the human-readable string and that rewriting filterText to it produces correct fuzzy matches.

Fixes OpenLiberty/liberty-tools-vscode#341
and Fixes #609

VS Code's fuzzyScore requires matched characters to start at a word
boundary (uppercase letter, space, start of string). The MP language
server sets both label and filterText to lowercase tokens like
'mpliveness' with no boundaries, so partial word matches like 'live'
or 'health' score 0 and the item never surfaces.

Rewrite filterText to the item's human-readable detail string
('MicroProfile Health liveness check') before items are returned to
VS Code. This gives the fuzzy engine real word boundaries to match
against, so queries like 'live', 'health', 'readi', 'check' all work.

Note: pure mid-word subsequences like 'ven' (no boundary before 'v'
in 'liveness') are not achievable with VS Code's boundary-anchored
fuzzyScore regardless of filterText value — this is a known engine
limitation compared to LSP4E's ordered subsequence matching and
LSP4IJ's dual lookup string registration.

This mirrors:
- LSP4IJ: getAllLookupStrings() registers both filterText and label
- LSP4E: CompletionProposalTools ordered subsequence matching

Fixes: OpenLiberty/liberty-tools-vscode#341
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant