Skip to content

fix: Prevent whole-file PSI caching in highlight handler - #1659

Merged
angelozerr merged 2 commits into
redhat-developer:mainfrom
ethanhann:bug/inconsistent_highlighting
Sep 1, 2026
Merged

fix: Prevent whole-file PSI caching in highlight handler#1659
angelozerr merged 2 commits into
redhat-developer:mainfrom
ethanhann:bug/inconsistent_highlighting

Conversation

@ethanhann

Copy link
Copy Markdown
Contributor

Relates to #1300
Plugin version: 0.21.0
I verified this fix on RustRover 2026.1.4.

When a language server returns an empty highlight list for a file whose only PSI element spans the whole file, such as plain text, the empty result is cached for the whole file. It stops sending documentHighlight requests until the file is reopened which breaks highlighting. This PR returns an empty handler instead of null in that case. The empty result is cached for the caret offset only which allows highlighting to keep working.

@ethanhann ethanhann changed the title Fix: Prevent whole-file PSI caching in highlight handler fix: Prevent whole-file PSI caching in highlight handler Aug 31, 2026
// Returning null here would make the IDE cache the empty result for the whole plain-text file,
// and it would stop sending 'textDocument/documentHighlight' until the document changes.
// See https://github.com/redhat-developer/lsp4ij/issues/1300
return isWholeFileElementAtCaret(editor, file) ? new LSPHighlightUsagesHandler(editor, file, targets) : null;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It means that you will call findElementAt every time when targets are empty.

I think this issue is only for TEXT and textmate language. Generally PsiFile findElementAt doesnt return the full text range file.

So my suggestion is to replace isWholeFileElementAtCaret call with SimpleLanguageUtils.isSUpported(file.getLanguage())

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the feedback. I wasn't aware of the SimpleLanguageUtils.isSupported() method. I retested with this change and it works perfectly.

@angelozerr angelozerr added this to the 0.21.1 milestone Sep 1, 2026
@angelozerr angelozerr moved this to In Progress in Java Tooling Sep 1, 2026
@angelozerr
angelozerr merged commit 6d6c1aa into redhat-developer:main Sep 1, 2026
5 of 6 checks passed
@github-project-automation github-project-automation Bot moved this from In Progress to Done in Java Tooling Sep 1, 2026
@angelozerr

Copy link
Copy Markdown
Contributor

Thanks @ethanhann !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants