Skip to content

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

Closed
lagergren wants to merge 1 commit into
redhat-developer:mainfrom
lagergren:fix/completion-prefix-without-text-edit

Conversation

@lagergren

Copy link
Copy Markdown
Collaborator

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 prefix disable-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: BootstrapPropertiesCompletionTest completes com.ibm.ws.log with whole keys and no textEdit. 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 .properties value stands in for a one-token comment:

  • key=disable-next-line : u shows unused and undefined-global, not need-import;
  • inserting unused gives key=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.* and LSPIJUtils_getWordRangeAtTest pass on all three platforms: 169 tests each, 0 failures, 0 skipped.

Behaviour change

Before After
Inside a one-token comment, disable-next-line : u shows no items, and after a space an item replaces the whole token The items are filtered by u, and the chosen one replaces only u

… 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
@lagergren lagergren added this to the 0.30.2 milestone Nov 24, 2026
@lagergren lagergren added the bug Something isn't working label Nov 24, 2026
@coderabbitai

coderabbitai Bot commented Nov 24, 2026

Copy link
Copy Markdown

Warning

Review limit reached

This 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.

Check out review usage here.

View limit details

Limit details: You’ve used all 2 included reviews currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: c2622fe0-5810-4ff9-990f-c7b10957aecf
Commits

Reviewing files that changed from the base of the PR and between d592c89 and b819aef.

Files selected for processing: 4

  • src/main/java/com/redhat/devtools/lsp4ij/client/features/LSPCompletionFeature.java
  • src/main/java/com/redhat/devtools/lsp4ij/features/completion/CompletionPrefix.java
  • src/main/java/com/redhat/devtools/lsp4ij/internal/CompletionUtils.java
  • src/test/java/com/redhat/devtools/lsp4ij/features/completion/CompletionWithoutTextEditInMultiWordTokenTest.java

@codecov

codecov Bot commented Nov 24, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 94.73684% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 54.65%. Comparing base (1b0b053) to head (b819aef).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...dhat/devtools/lsp4ij/internal/CompletionUtils.java 90.00% 0 Missing and 1 partial ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@lagergren

Copy link
Copy Markdown
Collaborator Author

Combined, unchanged, with the other small fixes into #2219, one commit each, so that they take one review instead of six.

@lagergren lagergren closed this Nov 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unable to see code completion after the colon in comments.

1 participant