do not recycle inspection highlights in annotator runner because they should be recycled in inspection pass (part of IDEA-321013)

GitOrigin-RevId: 122c8eb0b3459698b27e2cee4fc0491ed261c5ee
This commit is contained in:
Alexey Kudravtsev
2024-02-20 18:07:59 +01:00
committed by intellij-monorepo-bot
parent 45d1228fa8
commit c705e3d84f
3 changed files with 8 additions and 5 deletions

View File

@@ -68,7 +68,7 @@ final class AnnotatorRunner {
List<PsiElement> insideThenOutside = ContainerUtil.concat(inside, outside);
Map<Annotator, Set<Language>> supportedLanguages = calcSupportedLanguages(insideThenOutside);
HighlightInfoUpdater highlightInfoUpdater = HighlightInfoUpdater.getInstance(myProject);
HighlightersRecycler invalidElementsRecycler = highlightInfoUpdater.removeOrRecycleInvalidPsiElements(myPsiFile);
HighlightersRecycler invalidElementsRecycler = highlightInfoUpdater.removeOrRecycleInvalidPsiElements(myPsiFile, "AnnotationRunner", false, true);
try {
PairProcessor<Annotator, JobLauncher.QueueController<? super Annotator>> processor = (annotator, __) ->
ApplicationManagerEx.getApplicationEx().tryRunReadAction(() -> runAnnotator(annotator, insideThenOutside, supportedLanguages,

View File

@@ -106,7 +106,7 @@ final class HighlightInfoUpdater implements Disposable {
}
@NotNull
HighlightersRecycler removeOrRecycleInvalidPsiElements(@NotNull PsiFile psiFile) {
HighlightersRecycler removeOrRecycleInvalidPsiElements(@NotNull PsiFile psiFile, @NotNull Object origin, boolean removeInspectionHighlights, boolean removeAnnotatorHighlights) {
PsiFile hostFile = InjectedLanguageManager.getInstance(psiFile.getProject()).getTopLevelFile(psiFile);
Document hostDocument = hostFile.getFileDocument();
Map<PsiFile, Map<Object, ToolHighlights>> hostMap = getOrCreateHostMap(hostDocument);
@@ -129,7 +129,7 @@ final class HighlightInfoUpdater implements Disposable {
}
}
if (LOG.isDebugEnabled()) {
LOG.debug("removeOrRecycleInvalidPsiElements: removed invalid file: "+psi+" ("+removed+" highlighters removed)");
LOG.debug("removeOrRecycleInvalidPsiElements: removed invalid file: "+psi+" ("+removed+" highlighters removed); from "+origin);
}
return true;
});
@@ -139,6 +139,7 @@ final class HighlightInfoUpdater implements Disposable {
return toReuse;
}
for (Map.Entry<Object, ToolHighlights> toolEntry: map.entrySet()) {
Object toolId = toolEntry.getKey();
ToolHighlights toolHighlights = toolEntry.getValue();
toolHighlights.elementHighlights.entrySet().removeIf(entry -> {
PsiElement psiElement = entry.getKey();
@@ -148,8 +149,10 @@ final class HighlightInfoUpdater implements Disposable {
for (HighlightInfo info : entry.getValue()) {
RangeHighlighterEx highlighter = info.getHighlighter();
if (highlighter != null) {
if (info.isFromAnnotator() && !removeAnnotatorHighlights) continue;
if (isInspectionToolId(toolId) && !removeInspectionHighlights) continue;
if (LOG.isDebugEnabled()) {
LOG.debug("removeOrRecycleInvalidPsiElements: recycle " + info + " for " + psiElement);
LOG.debug("removeOrRecycleInvalidPsiElements: recycle " + info + " for invalid " + psiElement+" from "+origin);
}
toReuse.recycleHighlighter(highlighter);
}

View File

@@ -91,7 +91,7 @@ public final class LocalInspectionsPass extends ProgressableTextEditorHighlighti
@Override
protected void collectInformationWithProgress(@NotNull ProgressIndicator progress) {
HighlightInfoUpdater highlightInfoUpdater = HighlightInfoUpdater.getInstance(getFile().getProject());
HighlightersRecycler invalidElementsRecycler = highlightInfoUpdater.removeOrRecycleInvalidPsiElements(getFile());
HighlightersRecycler invalidElementsRecycler = highlightInfoUpdater.removeOrRecycleInvalidPsiElements(getFile(), this, true, false);
try {
List<HighlightInfo> fileInfos = Collections.synchronizedList(new ArrayList<>());
List<? extends LocalInspectionToolWrapper> toolWrappers = getInspectionTools(myProfileWrapper);