mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
CopyPasteTest failed occasionally because HighlightSession was (concurrently) created without editor so ShowAutoImportPass wasn't run in DefaultHighlightInfoProcessor
This commit is contained in:
+5
-3
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
+6
-1
@@ -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<HighlightInfo> infos,
|
||||
@NotNull TextRange priorityRange,
|
||||
@NotNull TextRange restrictRange, int groupId) {}
|
||||
public void highlightsOutsideVisiblePartAreProduced(@NotNull HighlightingSession session,
|
||||
@Nullable Editor editor,
|
||||
@NotNull List<HighlightInfo> infos,
|
||||
@NotNull TextRange priorityRange,
|
||||
@NotNull TextRange restrictedRange, int groupId) {}
|
||||
@@ -49,7 +52,9 @@ public abstract class HighlightInfoProcessor {
|
||||
@NotNull TextRange elementRange,
|
||||
@Nullable List<HighlightInfo> 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() { };
|
||||
|
||||
+7
-1
@@ -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();
|
||||
|
||||
+1
-12
@@ -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<Runnable> 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() {
|
||||
|
||||
+3
-3
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -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);
|
||||
}
|
||||
|
||||
+1
-2
@@ -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");
|
||||
|
||||
+6
-5
@@ -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<HighlightInfo> 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<HighlightInfo> 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) {
|
||||
|
||||
+4
-5
@@ -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<HighlightInfo> gotHighlights = new THashSet<>(100);
|
||||
|
||||
List<Divider.DividedElements> 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<HighlightInfo> gotHighlights = new THashSet<>(100);
|
||||
final List<HighlightInfo> 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());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user