diff --git a/src/main/java/com/redhat/devtools/lsp4ij/features/highlight/LSPHighlightUsagesHandlerFactory.java b/src/main/java/com/redhat/devtools/lsp4ij/features/highlight/LSPHighlightUsagesHandlerFactory.java index 34b0682d0..5310eb729 100644 --- a/src/main/java/com/redhat/devtools/lsp4ij/features/highlight/LSPHighlightUsagesHandlerFactory.java +++ b/src/main/java/com/redhat/devtools/lsp4ij/features/highlight/LSPHighlightUsagesHandlerFactory.java @@ -25,6 +25,7 @@ import com.redhat.devtools.lsp4ij.LSPIJUtils; import com.redhat.devtools.lsp4ij.LanguageServersRegistry; import com.redhat.devtools.lsp4ij.client.indexing.ProjectIndexingManager; +import com.redhat.devtools.lsp4ij.internal.SimpleLanguageUtils; import org.eclipse.lsp4j.DocumentHighlight; import org.eclipse.lsp4j.DocumentHighlightKind; import org.eclipse.lsp4j.TextDocumentIdentifier; @@ -58,7 +59,13 @@ public class LSPHighlightUsagesHandlerFactory implements HighlightUsagesHandlerF return null; } List targets = getTargets(editor, file); - return targets.isEmpty() ? null : new LSPHighlightUsagesHandler(editor, file, targets); + if (targets.isEmpty()) { + // For a TEXT or textmate file, returning null here would make the IDE cache the empty result + // for the whole file, and it would stop sending 'textDocument/documentHighlight' until the document changes. + // See https://github.com/redhat-developer/lsp4ij/issues/1300 + return SimpleLanguageUtils.isSupported(file.getLanguage()) ? new LSPHighlightUsagesHandler(editor, file, targets) : null; + } + return new LSPHighlightUsagesHandler(editor, file, targets); } private List getTargets(Editor editor, PsiFile psiFile) {