From 4e00a8b5429f6832f8e7acc9cb9d60de8e01b713 Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Fri, 30 Jun 2017 15:31:31 +0300 Subject: [PATCH] CopyPasteTest failed occasionally because HighlightSession was (concurrently) created without editor so ShowAutoImportPass wasn't run in DefaultHighlightInfoProcessor --- .../daemon/impl/GeneralHighlightingPass.java | 8 +++++--- .../daemon/impl/HighlightInfoProcessor.java | 7 ++++++- .../daemon/impl/HighlightingSession.java | 8 +++++++- .../daemon/impl/HighlightingSessionImpl.java | 13 +------------ .../ProgressableTextEditorHighlightingPass.java | 6 +++--- .../impl/ChameleonSyntaxHighlightingPass.java | 4 ++-- .../daemon/impl/DaemonCodeAnalyzerImpl.java | 3 +-- .../daemon/impl/DefaultHighlightInfoProcessor.java | 11 ++++++----- .../impl/InjectedGeneralHighlightingPass.java | 9 ++++----- 9 files changed, 35 insertions(+), 34 deletions(-) diff --git a/platform/analysis-impl/src/com/intellij/codeInsight/daemon/impl/GeneralHighlightingPass.java b/platform/analysis-impl/src/com/intellij/codeInsight/daemon/impl/GeneralHighlightingPass.java index 07702ab74936..961b5bff1fce 100644 --- a/platform/analysis-impl/src/com/intellij/codeInsight/daemon/impl/GeneralHighlightingPass.java +++ b/platform/analysis-impl/src/com/intellij/codeInsight/daemon/impl/GeneralHighlightingPass.java @@ -238,7 +238,8 @@ public class GeneralHighlightingPass extends ProgressableTextEditorHighlightingP boolean success = collectHighlights(allInsideElements, allInsideRanges, allOutsideElements, allOutsideRanges, progress, filteredVisitors, insideResult, outsideResult, forceHighlightParents); if (success) { - myHighlightInfoProcessor.highlightsOutsideVisiblePartAreProduced(myHighlightingSession, outsideResult, myPriorityRange, + myHighlightInfoProcessor.highlightsOutsideVisiblePartAreProduced(myHighlightingSession, getEditor(), + outsideResult, myPriorityRange, myRestrictRange, getId()); if (myUpdateAll) { @@ -302,7 +303,7 @@ public class GeneralHighlightingPass extends ProgressableTextEditorHighlightingP nestedRange, nestedInfos); final TextRange priorityIntersection = myPriorityRange.intersection(myRestrictRange); if ((!elements1.isEmpty() || !insideResult.isEmpty()) && priorityIntersection != null) { // do not apply when there were no elements to highlight - myHighlightInfoProcessor.highlightsInsideVisiblePartAreProduced(myHighlightingSession, insideResult, myPriorityRange, myRestrictRange, getId()); + myHighlightInfoProcessor.highlightsInsideVisiblePartAreProduced(myHighlightingSession, getEditor(), insideResult, myPriorityRange, myRestrictRange, getId()); } runVisitors(elements2, ranges2, chunkSize, progress, skipParentsSet, holder, insideResult, outsideResult, forceHighlightParents, visitors, nestedRange, nestedInfos); @@ -314,7 +315,8 @@ public class GeneralHighlightingPass extends ProgressableTextEditorHighlightingP assert info != null; postInfos.add(info); } - myHighlightInfoProcessor.highlightsInsideVisiblePartAreProduced(myHighlightingSession, postInfos, getFile().getTextRange(), getFile().getTextRange(), POST_UPDATE_ALL); + myHighlightInfoProcessor.highlightsInsideVisiblePartAreProduced(myHighlightingSession, getEditor(), + postInfos, getFile().getTextRange(), getFile().getTextRange(), POST_UPDATE_ALL); return success; } diff --git a/platform/analysis-impl/src/com/intellij/codeInsight/daemon/impl/HighlightInfoProcessor.java b/platform/analysis-impl/src/com/intellij/codeInsight/daemon/impl/HighlightInfoProcessor.java index 94638614d37f..b149b5bb187f 100644 --- a/platform/analysis-impl/src/com/intellij/codeInsight/daemon/impl/HighlightInfoProcessor.java +++ b/platform/analysis-impl/src/com/intellij/codeInsight/daemon/impl/HighlightInfoProcessor.java @@ -15,6 +15,7 @@ */ package com.intellij.codeInsight.daemon.impl; +import com.intellij.openapi.editor.Editor; import com.intellij.openapi.util.TextRange; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -27,10 +28,12 @@ public abstract class HighlightInfoProcessor { // HInfos for visible part of file/block are produced. // Will remove all range-highlighters from there and replace them with passed infos public void highlightsInsideVisiblePartAreProduced(@NotNull HighlightingSession session, + @Nullable Editor editor, @NotNull List infos, @NotNull TextRange priorityRange, @NotNull TextRange restrictRange, int groupId) {} public void highlightsOutsideVisiblePartAreProduced(@NotNull HighlightingSession session, + @Nullable Editor editor, @NotNull List infos, @NotNull TextRange priorityRange, @NotNull TextRange restrictedRange, int groupId) {} @@ -49,7 +52,9 @@ public abstract class HighlightInfoProcessor { @NotNull TextRange elementRange, @Nullable List infos){} - public void progressIsAdvanced(@NotNull HighlightingSession highlightingSession, double progress){} + public void progressIsAdvanced(@NotNull HighlightingSession highlightingSession, + @Nullable Editor editor, + double progress){} private static final HighlightInfoProcessor EMPTY = new HighlightInfoProcessor() { }; diff --git a/platform/analysis-impl/src/com/intellij/codeInsight/daemon/impl/HighlightingSession.java b/platform/analysis-impl/src/com/intellij/codeInsight/daemon/impl/HighlightingSession.java index 0013a2cace2a..4605df7f3207 100644 --- a/platform/analysis-impl/src/com/intellij/codeInsight/daemon/impl/HighlightingSession.java +++ b/platform/analysis-impl/src/com/intellij/codeInsight/daemon/impl/HighlightingSession.java @@ -30,7 +30,13 @@ public interface HighlightingSession { @NotNull PsiFile getPsiFile(); - Editor getEditor(); + /** + * TODO to remove in IDEA 2018 + */ + @Deprecated + default Editor getEditor() { + return null; + } @NotNull Document getDocument(); diff --git a/platform/analysis-impl/src/com/intellij/codeInsight/daemon/impl/HighlightingSessionImpl.java b/platform/analysis-impl/src/com/intellij/codeInsight/daemon/impl/HighlightingSessionImpl.java index 23494deecabf..a2da669634b2 100644 --- a/platform/analysis-impl/src/com/intellij/codeInsight/daemon/impl/HighlightingSessionImpl.java +++ b/platform/analysis-impl/src/com/intellij/codeInsight/daemon/impl/HighlightingSessionImpl.java @@ -17,7 +17,6 @@ package com.intellij.codeInsight.daemon.impl; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.editor.Document; -import com.intellij.openapi.editor.Editor; import com.intellij.openapi.editor.RangeMarker; import com.intellij.openapi.editor.colors.EditorColorsScheme; import com.intellij.openapi.editor.ex.RangeHighlighterEx; @@ -39,7 +38,6 @@ import java.util.concurrent.ConcurrentMap; public class HighlightingSessionImpl implements HighlightingSession { @NotNull private final PsiFile myPsiFile; - @Nullable private final Editor myEditor; @NotNull private final ProgressIndicator myProgressIndicator; private final EditorColorsScheme myEditorColorsScheme; @NotNull private final Project myProject; @@ -48,11 +46,9 @@ public class HighlightingSessionImpl implements HighlightingSession { private final TransferToEDTQueue myEDTQueue; private HighlightingSessionImpl(@NotNull PsiFile psiFile, - @Nullable Editor editor, @NotNull DaemonProgressIndicator progressIndicator, EditorColorsScheme editorColorsScheme) { myPsiFile = psiFile; - myEditor = editor; myProgressIndicator = progressIndicator; myEditorColorsScheme = editorColorsScheme; myProject = psiFile.getProject(); @@ -76,7 +72,6 @@ public class HighlightingSessionImpl implements HighlightingSession { @NotNull static HighlightingSession getOrCreateHighlightingSession(@NotNull PsiFile psiFile, - @Nullable Editor editor, @NotNull DaemonProgressIndicator progressIndicator, @Nullable EditorColorsScheme editorColorsScheme) { HighlightingSession session = getHighlightingSession(psiFile, progressIndicator); @@ -86,7 +81,7 @@ public class HighlightingSessionImpl implements HighlightingSession { map = progressIndicator.putUserDataIfAbsent(HIGHLIGHTING_SESSION, ContainerUtil.newConcurrentMap()); } session = ConcurrencyUtil.cacheOrGet(map, psiFile, - new HighlightingSessionImpl(psiFile, editor, progressIndicator, editorColorsScheme)); + new HighlightingSessionImpl(psiFile, progressIndicator, editorColorsScheme)); } return session; } @@ -107,12 +102,6 @@ public class HighlightingSessionImpl implements HighlightingSession { return myPsiFile; } - @Nullable - @Override - public Editor getEditor() { - return myEditor; - } - @NotNull @Override public Document getDocument() { diff --git a/platform/analysis-impl/src/com/intellij/codeInsight/daemon/impl/ProgressableTextEditorHighlightingPass.java b/platform/analysis-impl/src/com/intellij/codeInsight/daemon/impl/ProgressableTextEditorHighlightingPass.java index 564dac79f821..05071e01deb0 100644 --- a/platform/analysis-impl/src/com/intellij/codeInsight/daemon/impl/ProgressableTextEditorHighlightingPass.java +++ b/platform/analysis-impl/src/com/intellij/codeInsight/daemon/impl/ProgressableTextEditorHighlightingPass.java @@ -77,7 +77,7 @@ public abstract class ProgressableTextEditorHighlightingPass extends TextEditorH } myFinished = false; if (myFile != null) { - myHighlightingSession = HighlightingSessionImpl.getOrCreateHighlightingSession(myFile, myEditor, (DaemonProgressIndicator)progress, getColorsScheme()); + myHighlightingSession = HighlightingSessionImpl.getOrCreateHighlightingSession(myFile, (DaemonProgressIndicator)progress, getColorsScheme()); } try { collectInformationWithProgress(progress); @@ -98,7 +98,7 @@ public abstract class ProgressableTextEditorHighlightingPass extends TextEditorH DaemonCodeAnalyzerEx daemonCodeAnalyzer = DaemonCodeAnalyzerEx.getInstanceEx(myProject); daemonCodeAnalyzer.getFileStatusMap().markFileUpToDate(myDocument, getId()); if (myHighlightingSession != null) { - myHighlightInfoProcessor.progressIsAdvanced(myHighlightingSession, 1); //causes traffic light repaint + myHighlightInfoProcessor.progressIsAdvanced(myHighlightingSession, getEditor(), 1); //causes traffic light repaint } } @@ -147,7 +147,7 @@ public abstract class ProgressableTextEditorHighlightingPass extends TextEditorH if (current >= myNextChunkThreshold) { double progress = getProgress(); myNextChunkThreshold += Math.max(1, myProgressLimit / 100); - myHighlightInfoProcessor.progressIsAdvanced(myHighlightingSession, progress); + myHighlightInfoProcessor.progressIsAdvanced(myHighlightingSession, getEditor(), progress); } } } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/ChameleonSyntaxHighlightingPass.java b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/ChameleonSyntaxHighlightingPass.java index 131788d38e7a..3e84a89095ca 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/ChameleonSyntaxHighlightingPass.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/ChameleonSyntaxHighlightingPass.java @@ -111,11 +111,11 @@ class ChameleonSyntaxHighlightingPass extends GeneralHighlightingPass { for (PsiElement e : lazyInside) { collectHighlights(e, inside, outside, myPriorityRange); } - myHighlightInfoProcessor.highlightsInsideVisiblePartAreProduced(myHighlightingSession, inside, myPriorityRange, myRestrictRange, getId()); + myHighlightInfoProcessor.highlightsInsideVisiblePartAreProduced(myHighlightingSession, getEditor(), inside, myPriorityRange, myRestrictRange, getId()); for (PsiElement e : lazyOutside) { collectHighlights(e, inside, outside, myPriorityRange); } - myHighlightInfoProcessor.highlightsOutsideVisiblePartAreProduced(myHighlightingSession, outside, myPriorityRange, myRestrictRange, getId()); + myHighlightInfoProcessor.highlightsOutsideVisiblePartAreProduced(myHighlightingSession, getEditor(), outside, myPriorityRange, myRestrictRange, getId()); myHighlights.addAll(inside); myHighlights.addAll(outside); } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/DaemonCodeAnalyzerImpl.java b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/DaemonCodeAnalyzerImpl.java index b71300378740..edf55007b5bd 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/DaemonCodeAnalyzerImpl.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/DaemonCodeAnalyzerImpl.java @@ -391,8 +391,7 @@ public class DaemonCodeAnalyzerImpl extends DaemonCodeAnalyzerEx implements Pers throw new RuntimeException("Highlighting still running after "+(System.currentTimeMillis()-start)/1000+" seconds.\n"+ ThreadDumper.dumpThreadsToString()); } - final HighlightingSessionImpl session = - (HighlightingSessionImpl)HighlightingSessionImpl.getOrCreateHighlightingSession(file, textEditors.get(0).getEditor(), progress, null); + HighlightingSessionImpl session = (HighlightingSessionImpl)HighlightingSessionImpl.getOrCreateHighlightingSession(file, progress, null); wrap(() -> { if (!waitInOtherThread(60000, canChangeDocument)) { throw new TimeoutException("Unable to complete in 60s"); diff --git a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/DefaultHighlightInfoProcessor.java b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/DefaultHighlightInfoProcessor.java index b4c0e5149c48..5b994828fe4b 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/DefaultHighlightInfoProcessor.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/DefaultHighlightInfoProcessor.java @@ -40,6 +40,7 @@ import java.util.List; public class DefaultHighlightInfoProcessor extends HighlightInfoProcessor { @Override public void highlightsInsideVisiblePartAreProduced(@NotNull final HighlightingSession session, + @Nullable Editor editor, @NotNull final List infos, @NotNull TextRange priorityRange, @NotNull TextRange restrictRange, @@ -51,7 +52,6 @@ public class DefaultHighlightInfoProcessor extends HighlightInfoProcessor { final long modificationStamp = document.getModificationStamp(); final TextRange priorityIntersection = priorityRange.intersection(restrictRange); - final Editor editor = session.getEditor(); ((HighlightingSessionImpl)session).applyInEDT(() -> { if (modificationStamp != document.getModificationStamp()) return; if (priorityIntersection != null) { @@ -74,6 +74,7 @@ public class DefaultHighlightInfoProcessor extends HighlightInfoProcessor { @Override public void highlightsOutsideVisiblePartAreProduced(@NotNull final HighlightingSession session, + @Nullable Editor editor, @NotNull final List infos, @NotNull final TextRange priorityRange, @NotNull final TextRange restrictedRange, final int groupId) { @@ -91,7 +92,6 @@ public class DefaultHighlightInfoProcessor extends HighlightInfoProcessor { restrictedRange.getStartOffset(), restrictedRange.getEndOffset(), ProperTextRange.create(priorityRange), groupId); - Editor editor = session.getEditor(); if (editor != null) { DaemonListeners.repaintErrorStripeRenderer(editor, project); } @@ -142,14 +142,15 @@ public class DefaultHighlightInfoProcessor extends HighlightInfoProcessor { } @Override - public void progressIsAdvanced(@NotNull HighlightingSession highlightingSession, double progress) { + public void progressIsAdvanced(@NotNull HighlightingSession highlightingSession, + @Nullable Editor editor, + double progress) { PsiFile file = highlightingSession.getPsiFile(); - Editor editor = highlightingSession.getEditor(); repaintTrafficIcon(file, editor, progress); } private final Alarm repaintIconAlarm = new Alarm(Alarm.ThreadToUse.SWING_THREAD); - private void repaintTrafficIcon(@NotNull final PsiFile file, final Editor editor, double progress) { + private void repaintTrafficIcon(@NotNull final PsiFile file, @Nullable Editor editor, double progress) { if (ApplicationManager.getApplication().isCommandLine()) return; if (repaintIconAlarm.isEmpty() || progress >= 1) { diff --git a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/InjectedGeneralHighlightingPass.java b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/InjectedGeneralHighlightingPass.java index 691795f3843d..a1fa10bc9464 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/InjectedGeneralHighlightingPass.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/InjectedGeneralHighlightingPass.java @@ -76,8 +76,6 @@ public class InjectedGeneralHighlightingPass extends GeneralHighlightingPass imp protected void collectInformationWithProgress(@NotNull final ProgressIndicator progress) { if (!Registry.is("editor.injected.highlighting.enabled")) return; - final Set gotHighlights = new THashSet<>(100); - List allDivided = new ArrayList<>(); Divider.divideInsideAndOutsideAllRoots(myFile, myRestrictRange, myPriorityRange, SHOULD_HIGHLIGHT_FILTER, new CommonProcessors.CollectProcessor<>(allDivided)); @@ -99,6 +97,7 @@ public class InjectedGeneralHighlightingPass extends GeneralHighlightingPass imp // sync here because all writes happened in another thread result = injectedResult; } + final Set gotHighlights = new THashSet<>(100); final List injectionsOutside = new ArrayList<>(gotHighlights.size()); for (HighlightInfo info : result) { if (myRestrictRange.contains(info)) { @@ -119,7 +118,7 @@ public class InjectedGeneralHighlightingPass extends GeneralHighlightingPass imp myHighlights.addAll(toApplyInside); gotHighlights.clear(); - myHighlightInfoProcessor.highlightsInsideVisiblePartAreProduced(myHighlightingSession, toApplyInside, myPriorityRange, myRestrictRange, + myHighlightInfoProcessor.highlightsInsideVisiblePartAreProduced(myHighlightingSession, getEditor(), toApplyInside, myPriorityRange, myRestrictRange, getId()); } @@ -132,13 +131,13 @@ public class InjectedGeneralHighlightingPass extends GeneralHighlightingPass imp } toApply.addAll(injectionsOutside); - myHighlightInfoProcessor.highlightsOutsideVisiblePartAreProduced(myHighlightingSession, toApply, myRestrictRange, new ProperTextRange(0, myDocument.getTextLength()), + myHighlightInfoProcessor.highlightsOutsideVisiblePartAreProduced(myHighlightingSession, getEditor(), toApply, myRestrictRange, new ProperTextRange(0, myDocument.getTextLength()), getId()); } else { // else apply only result (by default apply command) and only within inside myHighlights.addAll(gotHighlights); - myHighlightInfoProcessor.highlightsInsideVisiblePartAreProduced(myHighlightingSession, myHighlights, myRestrictRange, myRestrictRange, + myHighlightInfoProcessor.highlightsInsideVisiblePartAreProduced(myHighlightingSession, getEditor(), myHighlights, myRestrictRange, myRestrictRange, getId()); } }