Repository navigation
fix: a completion item without a textEdit is matched against the word at the caret, not the whole PSI token, so completion works after a ':' in a comment - #2214
Conversation
… at the caret, not the whole PSI token, so completion works after a ':' in a comment LSP4IJ matched a completion item without a text edit against the prefix that IntelliJ computes from the PSI element at the caret, and inserted it from the start of that element. A custom PSI that keeps a whole comment as one token, as the EmmyLua plugin does for "---@diagnostic disable-next-line : u", gave the prefix "disable-next-line : u", which matches no item: the completion showed nothing, and an item inserted after the space replaced the whole text of the token. A prefix that spans whitespace is no word: such an item is now matched against the word that ends at the caret, "u", the identifier characters before it, as IntelliJ completes in a comment or in plain text and as VS Code completes an item without a text edit, and inserting it replaces that word. A prefix without whitespace, as a dotted property key that liberty-ls completes, is kept, and so are the prefixes in TextMate and plain-text files, which already are the word at the caret. Fixes redhat-developer#447
|
Warning Review limit reachedThis review ran on the open-source allowance, not this organization's plan, because the pull request author doesn't have an assigned seat. Waiting won't change this — ask an organization admin to assign them a seat, or add seats in Billing if every seat is already assigned, then retry. Next included review available in 17 minutes. View limit details
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2214 +/- ##
==========================================
+ Coverage 54.59% 54.65% +0.05%
==========================================
Files 834 834
Lines 35385 35403 +18
Branches 7300 5549 -1751
==========================================
+ Hits 19320 19348 +28
+ Misses 13223 13208 -15
- Partials 2842 2847 +5 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Combined, unchanged, with the other small fixes into #2219, one commit each, so that they take one review instead of six. |
Fixes #447
What
For a completion item without a
textEdit, LSP4IJ took the prefix to match and to replace from the PSI element at the caret. A plugin whose PSI makes a whole comment one token, as EmmyLua's does for---@diagnostic disable-next-line : u, gave the prefixdisable-next-line : u. That prefix matched no item. After a space, the item replaced the whole token.Change
When the PSI prefix, or the PSI element up to the caret, contains whitespace, the prefix is the word at the caret: the identifier characters before it, as IntelliJ uses in comments and plain text. That applies to both matching (
CompletionPrefix.getWordPrefix) and insertion (CompletionUtils.computePrefixStartFromInsertText).Without whitespace in the token, nothing changes. Using the document word always would break dotted or hyphenated tokens:
BootstrapPropertiesCompletionTestcompletescom.ibm.ws.logwith whole keys and notextEdit. TextMate and plain-text files, and DAP, behave as before.Not in this PR:
disable-next-line:u, without a space, still gets the PSI prefix. That would need a fallback per item.Tests
New
CompletionWithoutTextEditInMultiWordTokenTest(2 tests). A.propertiesvalue stands in for a one-token comment:key=disable-next-line : ushowsunusedandundefined-global, notneed-import;unusedgiveskey=disable-next-line : unused.Red-green: without the change, the first test has no completion, and inserting after a space gives
key=need-import. With the change, both pass.The new class passes headless on IC 2024.2, 2025.3 and IU 2026.3.
features.completion.*andLSPIJUtils_getWordRangeAtTestpass on all three platforms: 169 tests each, 0 failures, 0 skipped.Behaviour change
disable-next-line : ushows no items, and after a space an item replaces the whole tokenu, and the chosen one replaces onlyu