From e228f691bbf6c5077aed2a253d62eaef3dc1655d Mon Sep 17 00:00:00 2001 From: Vladimir Goncharov Date: Thu, 25 Sep 2025 15:24:42 +0000 Subject: [PATCH] [lsp] IJPL-189555 Introduce LSP-backed highlight usages (document highlights) feature Merge-request: IJ-MR-176039 Merged-by: Vladimir Goncharov GitOrigin-RevId: 118f6df4d2dd490fc60af2afe6547dc71865a0e5 --- .../daemon/impl/IdentifierHighlightingComputer.kt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/IdentifierHighlightingComputer.kt b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/IdentifierHighlightingComputer.kt index 85e11255c053..b567e50a8d47 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/IdentifierHighlightingComputer.kt +++ b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/IdentifierHighlightingComputer.kt @@ -250,7 +250,10 @@ class IdentifierHighlightingComputer( private fun findTarget(editor: Editor, file: PsiFile, myCaretOffset: Int): PsiElement? { val offset = TargetElementUtil.adjustOffset(file, editor.getDocument(), myCaretOffset) - return file.findElementAt(offset) + val psiElement = file.findElementAt(offset) + // LSP has an edge case when it tries to highlight a file with no (finegrained) PSI, where the only PSI element is the whole file. + // In this situation we wouldn't want to cache the whole file as an underlying identifier + return if (psiElement != null && psiElement.textRange == file.textRange) null else psiElement } /**