Skip to content

Commit

Permalink
Let general HighlightingPasses (i.e. not TextEditorHighlightingPass-d…
Browse files Browse the repository at this point in the history
…erived) run in parallel to other passes since they are not dependent on anything. Make document notnull as by-product

GitOrigin-RevId: 7f478ae9a7cf1396276888991a5c3d29d8a9c755
  • Loading branch information
cdracm authored and intellij-monorepo-bot committed Apr 27, 2020
1 parent b79801a commit e7f246b
Show file tree
Hide file tree
Showing 25 changed files with 133 additions and 227 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ private class JavaSoftKeywordHighlightingPass(private val file: PsiJavaFile, doc
}

override fun doApplyInformationToEditor() {
UpdateHighlightersUtil.setHighlightersToEditor(myProject, myDocument!!, 0, file.textLength, results, colorsScheme, id)
UpdateHighlightersUtil.setHighlightersToEditor(myProject, myDocument, 0, file.textLength, results, colorsScheme, id)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ abstract class ElementProcessingHintPass(
private val hints = TIntObjectHashMap<SmartList<String>>()

override fun doCollectInformation(progress: ProgressIndicator) {
assert(myDocument != null)
hints.clear()

val virtualFile = rootElement.containingFile?.originalFile?.virtualFile ?: return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1589,7 +1589,7 @@ public void beforeRemoved(@NotNull RangeHighlighterEx highlighter) {
if (errorDescription.equals(description)) {
errorRemoved[0] = true;

List<TextEditorHighlightingPass> passes = myDaemonCodeAnalyzer.getPassesToShowProgressFor(document);
List<ProgressableTextEditorHighlightingPass> passes = myDaemonCodeAnalyzer.getPassesToShowProgressFor(document);
GeneralHighlightingPass ghp = null;
for (TextEditorHighlightingPass pass : passes) {
if (pass instanceof GeneralHighlightingPass && pass.getId() == Pass.UPDATE_ALL) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@

public abstract class TextEditorHighlightingPass implements HighlightingPass {
public static final TextEditorHighlightingPass[] EMPTY_ARRAY = new TextEditorHighlightingPass[0];
@Nullable protected final Document myDocument;
@NotNull protected final Project myProject;
@NotNull
protected final Document myDocument;
@NotNull
protected final Project myProject;
private final boolean myRunIntentionPassAfter;
private final long myInitialDocStamp;
private final long myInitialPsiStamp;
Expand All @@ -33,14 +35,14 @@ public abstract class TextEditorHighlightingPass implements HighlightingPass {
private volatile boolean myDumb;
private EditorColorsScheme myColorsScheme;

protected TextEditorHighlightingPass(@NotNull final Project project, @Nullable final Document document, boolean runIntentionPassAfter) {
protected TextEditorHighlightingPass(@NotNull final Project project, @NotNull final Document document, boolean runIntentionPassAfter) {
myDocument = document;
myProject = project;
myRunIntentionPassAfter = runIntentionPassAfter;
myInitialDocStamp = document == null ? 0 : document.getModificationStamp();
myInitialDocStamp = document.getModificationStamp();
myInitialPsiStamp = PsiModificationTracker.SERVICE.getInstance(myProject).getModificationCount();
}
protected TextEditorHighlightingPass(@NotNull final Project project, @Nullable final Document document) {
protected TextEditorHighlightingPass(@NotNull final Project project, @NotNull Document document) {
this(project, document, true);
}

Expand Down Expand Up @@ -74,21 +76,17 @@ protected boolean isValid() {
return false;
}

if (myDocument != null) {
if (myDocument.getModificationStamp() != myInitialDocStamp) return false;
PsiFile file = PsiDocumentManager.getInstance(myProject).getPsiFile(myDocument);
return file != null && file.isValid();
}

return true;
if (myDocument.getModificationStamp() != myInitialDocStamp) return false;
PsiFile file = PsiDocumentManager.getInstance(myProject).getPsiFile(myDocument);
return file != null && file.isValid();
}

@Override
public final void applyInformationToEditor() {
if (!isValid()) return; // Document has changed.
if (DumbService.getInstance(myProject).isDumb() && !DumbService.isDumbAware(this)) {
Document document = getDocument();
PsiFile file = document == null ? null : PsiDocumentManager.getInstance(myProject).getPsiFile(document);
PsiFile file = PsiDocumentManager.getInstance(myProject).getPsiFile(document);
if (file != null) {
DaemonCodeAnalyzerEx.getInstanceEx(myProject).getFileStatusMap().markFileUpToDate(getDocument(), getId());
}
Expand Down Expand Up @@ -121,7 +119,7 @@ public final void setCompletionPredecessorIds(int @NotNull [] completionPredeces
myCompletionPredecessorIds = completionPredecessorIds;
}

@Nullable
@NotNull
public Document getDocument() {
return myDocument;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,6 @@ public GeneralHighlightingPass(@NotNull Project project,
return myFile;
}

@Override
public @NotNull Document getDocument() {
// this pass always get not-null document
//noinspection ConstantConditions
return super.getDocument();
}

private static final Key<AtomicInteger> HIGHLIGHT_VISITOR_INSTANCE_COUNT = new Key<>("HIGHLIGHT_VISITOR_INSTANCE_COUNT");
private HighlightVisitor @NotNull [] cloneHighlightVisitors() {
int oldCount = incVisitorUsageCount(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public abstract class ProgressableTextEditorHighlightingPass extends TextEditorH
HighlightingSession myHighlightingSession;

protected ProgressableTextEditorHighlightingPass(@NotNull Project project,
@Nullable final Document document,
@NotNull final Document document,
@NotNull String presentableName,
@Nullable PsiFile file,
@Nullable Editor editor,
Expand Down Expand Up @@ -77,8 +77,8 @@ public final void doCollectInformation(@NotNull final ProgressIndicator progress
GlobalInspectionContextBase.assertUnderDaemonProgress();
myFinished = false;
if (myFile != null) {
myHighlightingSession =
HighlightingSessionImpl.getOrCreateHighlightingSession(myFile, (DaemonProgressIndicator)ProgressWrapper.unwrapAll(progress), getColorsScheme());
DaemonProgressIndicator daemonProgressIndicator = (DaemonProgressIndicator)ProgressWrapper.unwrapAll(progress);
myHighlightingSession = HighlightingSessionImpl.getOrCreateHighlightingSession(myFile, daemonProgressIndicator, getColorsScheme());
}
try {
collectInformationWithProgress(progress);
Expand Down Expand Up @@ -161,7 +161,7 @@ void waitForHighlightInfosApplied() {
}

static class EmptyPass extends TextEditorHighlightingPass {
EmptyPass(final Project project, @Nullable final Document document) {
EmptyPass(@NotNull Project project, @NotNull Document document) {
super(project, document, false);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@
import com.intellij.openapi.vfs.VirtualFileManager;
import com.intellij.openapi.vfs.newvfs.RefreshQueueImpl;
import com.intellij.packageDependencies.DependencyValidationManager;
import com.intellij.psi.*;
import com.intellij.psi.FileViewProvider;
import com.intellij.psi.PsiCompiledElement;
import com.intellij.psi.PsiDocumentManager;
import com.intellij.psi.PsiFile;
import com.intellij.psi.util.PsiModificationTracker;
import com.intellij.psi.util.PsiUtilCore;
import com.intellij.util.*;
Expand Down Expand Up @@ -546,15 +549,13 @@ public void restart(@NotNull PsiFile file) {
}

@NotNull
public List<TextEditorHighlightingPass> getPassesToShowProgressFor(Document document) {
List<TextEditorHighlightingPass> allPasses = myPassExecutorService.getAllSubmittedPasses();
List<TextEditorHighlightingPass> result = new ArrayList<>(allPasses.size());
for (TextEditorHighlightingPass pass : allPasses) {
if (pass.getDocument() == document || pass.getDocument() == null) {
result.add(pass);
}
}
return result;
public List<ProgressableTextEditorHighlightingPass> getPassesToShowProgressFor(@NotNull Document document) {
List<HighlightingPass> allPasses = myPassExecutorService.getAllSubmittedPasses();
return allPasses.stream()
.map(p->p instanceof ProgressableTextEditorHighlightingPass ? (ProgressableTextEditorHighlightingPass)p : null)
.filter(p-> p != null && p.getDocument() == document)
.sorted(Comparator.comparingInt(p->p.getId()))
.collect(Collectors.toList());
}

boolean isAllAnalysisFinished(@NotNull PsiFile file) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,9 +328,7 @@ private boolean isCaretOverCollapsedFoldRegion() {
* In brace matching case this is done from {@link BraceHighlightingHandler#highlightBraces(com.intellij.openapi.util.TextRange, com.intellij.openapi.util.TextRange, boolean, boolean, com.intellij.openapi.fileTypes.FileType)}
*/
private void doAdditionalCodeBlockHighlighting() {
if (myCodeBlockMarkerRanges.size() < 2 ||
myDocument == null ||
!(myEditor instanceof EditorEx)) {
if (myCodeBlockMarkerRanges.size() < 2 || !(myEditor instanceof EditorEx)) {
return;
}
ArrayList<TextRange> markers = new ArrayList<>(myCodeBlockMarkerRanges);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,6 @@ public IndentsPass(@NotNull Project project, @NotNull Editor editor, @NotNull Ps

@Override
public void doCollectInformation(@NotNull ProgressIndicator progress) {
assert myDocument != null;
final Long stamp = myEditor.getUserData(LAST_TIME_INDENTS_BUILT);
if (stamp != null && stamp.longValue() == nowStamp()) return;

Expand All @@ -203,7 +202,6 @@ public void doCollectInformation(@NotNull ProgressIndicator progress) {

private long nowStamp() {
if (!myEditor.getSettings().isIndentGuidesShown()) return -1;
assert myDocument != null;
// include tab size into stamp to make sure indent guides are recalculated on tab size change
return myDocument.getModificationStamp() ^ (((long)getTabSize()) << 24);
}
Expand Down Expand Up @@ -257,7 +255,6 @@ else if (cmp > 0) {
}

final int startRangeIndex = curRange;
assert myDocument != null;
DocumentUtil.executeInBulk(myDocument, myRanges.size() > 10000, () -> {
for (int i = startRangeIndex; i < myRanges.size(); i++) {
newHighlighters.add(createHighlighter(mm, myRanges.get(i)));
Expand All @@ -282,7 +279,6 @@ private List<IndentGuideDescriptor> buildDescriptors() {

lines.push(0);
indents.push(0);
assert myDocument != null;
List<IndentGuideDescriptor> descriptors = new ArrayList<>();
for (int line = 1; line < lineIndents.length; line++) {
ProgressManager.checkCanceled();
Expand Down Expand Up @@ -371,7 +367,6 @@ private class IndentsCalculator {
@NotNull final CharSequence myChars;

IndentsCalculator() {
assert myDocument != null;
lineIndents = new int[myDocument.getLineCount()];
myChars = myDocument.getCharsSequence();
}
Expand All @@ -380,7 +375,6 @@ private class IndentsCalculator {
* Calculates line indents for the {@link #myDocument target document}.
*/
void calculate() {
assert myDocument != null;
final FileType fileType = myFile.getFileType();
int tabSize = getTabSize();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,6 @@ public class LineMarkersPass extends TextEditorHighlightingPass {
myRestrictRange = restrictRange;
}

@NotNull
@Override
public Document getDocument() {
//noinspection ConstantConditions
return super.getDocument();
}

@Override
public void doApplyInformationToEditor() {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public class LocalInspectionsPass extends ProgressableTextEditorHighlightingPass
private final boolean myInspectInjectedPsi;

public LocalInspectionsPass(@NotNull PsiFile file,
@Nullable Document document,
@NotNull Document document,
int startOffset,
int endOffset,
@NotNull TextRange priorityRange,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public TextEditorHighlightingPass createMainHighlightingPass(@NotNull PsiFile fi

private static class MyLocalInspectionsPass extends LocalInspectionsPass {
private MyLocalInspectionsPass(@NotNull PsiFile file,
Document document,
@NotNull Document document,
@NotNull TextRange textRange,
@NotNull TextRange visibleRange,
@NotNull HighlightInfoProcessor highlightInfoProcessor) {
Expand Down
Loading

0 comments on commit e7f246b

Please sign in to comment.