mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-16 14:23:28 +07:00
remove highlighters which were associated with garbage-collected psi elements
GitOrigin-RevId: 19ebe6e841e06e206f1d6a56803212a85f54376d
This commit is contained in:
committed by
intellij-monorepo-bot
parent
473c6b0714
commit
723b441b94
@@ -50,7 +50,8 @@ final class HighlightInfoUpdater implements Disposable {
|
||||
private static final Key<Map<PsiFile, Map<Object, ToolHighlights>>> VISITED_PSI_ELEMENTS = Key.create("VISITED_PSI_ELEMENTS");
|
||||
|
||||
static class ToolHighlights {
|
||||
final Map<PsiElement, List<? extends HighlightInfo>> elementHighlights = CollectionFactory.createConcurrentSoftMap(); //new ConcurrentHashMap<>();
|
||||
final Map<PsiElement, List<? extends HighlightInfo>> elementHighlights = CollectionFactory.createConcurrentSoftMap(evicted -> removeEvicted(evicted));
|
||||
|
||||
@NotNull ToolLatencies latencies = new ToolLatencies(0,0,0);
|
||||
}
|
||||
record ToolLatencies(
|
||||
@@ -81,6 +82,16 @@ final class HighlightInfoUpdater implements Disposable {
|
||||
public void dispose() {
|
||||
}
|
||||
|
||||
private static void removeEvicted(@NotNull List<? extends HighlightInfo> evicted) {
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("Disposing evicted " + evicted);
|
||||
}
|
||||
for (HighlightInfo info : evicted) {
|
||||
RangeHighlighterEx highlighter = info.getHighlighter();
|
||||
if (highlighter != null) highlighter.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private Map<Object, ToolHighlights> getData(@NotNull PsiFile psiFile) {
|
||||
PsiFile hostFile = InjectedLanguageManager.getInstance(psiFile.getProject()).getTopLevelFile(psiFile);
|
||||
@@ -141,23 +152,22 @@ final class HighlightInfoUpdater implements Disposable {
|
||||
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();
|
||||
toolHighlights.elementHighlights.replaceAll((psiElement, infos) -> {
|
||||
if (psiElement == FAKE_ELEMENT || psiElement.isValid()) {
|
||||
return false;
|
||||
return infos;
|
||||
}
|
||||
for (HighlightInfo info : entry.getValue()) {
|
||||
return List.copyOf(ContainerUtil.filter(infos, info -> {
|
||||
RangeHighlighterEx highlighter = info.getHighlighter();
|
||||
if (highlighter != null) {
|
||||
if (info.isFromAnnotator() && !removeAnnotatorHighlights) continue;
|
||||
if (isInspectionToolId(toolId) && !removeInspectionHighlights) continue;
|
||||
if (highlighter != null && (info.isFromAnnotator() && removeAnnotatorHighlights ||
|
||||
isInspectionToolId(toolId) && removeInspectionHighlights)) {
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("removeOrRecycleInvalidPsiElements: recycle " + info + " for invalid " + psiElement+" from "+origin);
|
||||
LOG.debug("removeOrRecycleInvalidPsiElements: recycle " + info + " for invalid " + psiElement + " from " + origin);
|
||||
}
|
||||
toReuse.recycleHighlighter(highlighter);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
return true;
|
||||
}));
|
||||
});
|
||||
}
|
||||
return toReuse;
|
||||
|
||||
Reference in New Issue
Block a user