add external pass to main passes (WEB-19179) appcode/144.1612 clion/144.1609
authorSergey Simonchik <sergey.simonchik@jetbrains.com>
Mon, 30 Nov 2015 11:23:08 +0000 (14:23 +0300)
committerSergey Simonchik <sergey.simonchik@jetbrains.com>
Mon, 30 Nov 2015 11:23:08 +0000 (14:23 +0300)
platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/ExternalToolPass.java
platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/ExternalToolPassFactory.java

index dc8bda912c02eb5a12f4f2e8076758ac880896b7..c2e9d8fea749278d3c20eb904f5b3f78c85afb62 100644 (file)
@@ -25,6 +25,7 @@ import com.intellij.lang.annotation.ExternalAnnotator;
 import com.intellij.openapi.application.ApplicationManager;
 import com.intellij.openapi.application.ModalityState;
 import com.intellij.openapi.application.ex.ApplicationManagerEx;
+import com.intellij.openapi.editor.Document;
 import com.intellij.openapi.editor.Editor;
 import com.intellij.openapi.progress.ProgressIndicator;
 import com.intellij.openapi.project.DumbService;
@@ -35,10 +36,7 @@ import com.intellij.util.containers.HashMap;
 import com.intellij.util.ui.update.Update;
 import org.jetbrains.annotations.NotNull;
 
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
+import java.util.*;
 
 /**
  * @author ven
@@ -49,6 +47,7 @@ public class ExternalToolPass extends ProgressableTextEditorHighlightingPass {
   private final Map<ExternalAnnotator, MyData> myAnnotator2DataMap = new HashMap<ExternalAnnotator, MyData>();
 
   private final ExternalToolPassFactory myExternalToolPassFactory;
+  private final boolean myMainHighlightingPass;
 
   private static class MyData {
     private final PsiFile myPsiRoot;
@@ -68,8 +67,21 @@ public class ExternalToolPass extends ProgressableTextEditorHighlightingPass {
                           int endOffset) {
     super(file.getProject(), editor.getDocument(), "External annotators", file, editor, new TextRange(startOffset, endOffset), false, new DefaultHighlightInfoProcessor());
     myAnnotationHolder = new AnnotationHolderImpl(new AnnotationSession(file));
+    myExternalToolPassFactory = externalToolPassFactory;
+    myMainHighlightingPass = false;
+  }
 
+  ExternalToolPass(@NotNull ExternalToolPassFactory externalToolPassFactory,
+                          @NotNull PsiFile file,
+                          @NotNull Document document,
+                          int startOffset,
+                          int endOffset,
+                          @NotNull HighlightInfoProcessor highlightInfoProcessor,
+                          boolean mainHighlightingPass) {
+    super(file.getProject(), document, "External annotators", file, null, new TextRange(startOffset, endOffset), false, highlightInfoProcessor);
+    myAnnotationHolder = new AnnotationHolderImpl(new AnnotationSession(file));
     myExternalToolPassFactory = externalToolPassFactory;
+    myMainHighlightingPass = mainHighlightingPass;
   }
 
   @Override
@@ -97,7 +109,15 @@ public class ExternalToolPass extends ProgressableTextEditorHighlightingPass {
         boolean errorFound = daemonCodeAnalyzer.getFileStatusMap().wasErrorFound(myDocument);
 
         for(ExternalAnnotator externalAnnotator: externalAnnotators) {
-          final Object collectedInfo = externalAnnotator.collectInformation(psiRoot, getEditor(), errorFound);
+          final Object collectedInfo;
+          Editor editor = getEditor();
+          if (editor != null) {
+            collectedInfo = externalAnnotator.collectInformation(psiRoot, editor, errorFound);
+          }
+          else {
+            collectedInfo = externalAnnotator.collectInformation(psiRoot);
+          }
+
           advanceProgress(1);
           if (collectedInfo != null) {
             myAnnotator2DataMap.put(externalAnnotator, new MyData(psiRoot, collectedInfo));
@@ -107,6 +127,20 @@ public class ExternalToolPass extends ProgressableTextEditorHighlightingPass {
     }
   }
 
+  @NotNull
+  @Override
+  public List<HighlightInfo> getInfos() {
+    if (myProject.isDisposed()) {
+      return Collections.emptyList();
+    }
+    if (myMainHighlightingPass) {
+      doAnnotate();
+      applyRelevant();
+      return getHighlights();
+    }
+    return super.getInfos();
+  }
+
   @Override
   protected void applyInformationWithProgress() {
     final long modificationStampBefore = myDocument.getModificationStamp();
index 9d51c8c1283e8181b6780c72de0ffc018b83f4d0..d2fc3dda03337d3ca2280873c5260461d10f663f 100644 (file)
 
 package com.intellij.codeInsight.daemon.impl;
 
-import com.intellij.codeHighlighting.Pass;
-import com.intellij.codeHighlighting.TextEditorHighlightingPass;
-import com.intellij.codeHighlighting.TextEditorHighlightingPassFactory;
-import com.intellij.codeHighlighting.TextEditorHighlightingPassRegistrar;
+import com.intellij.codeHighlighting.*;
 import com.intellij.lang.ExternalLanguageAnnotators;
 import com.intellij.lang.Language;
 import com.intellij.lang.annotation.ExternalAnnotator;
 import com.intellij.openapi.application.ApplicationManager;
 import com.intellij.openapi.components.AbstractProjectComponent;
+import com.intellij.openapi.editor.Document;
 import com.intellij.openapi.editor.Editor;
 import com.intellij.openapi.project.Project;
 import com.intellij.openapi.util.TextRange;
@@ -40,7 +38,8 @@ import java.util.List;
 /**
  * @author cdr
 */
-public class ExternalToolPassFactory extends AbstractProjectComponent implements TextEditorHighlightingPassFactory {
+public class ExternalToolPassFactory extends AbstractProjectComponent implements TextEditorHighlightingPassFactory,
+                                                                                 MainHighlightingPassFactory {
   private final MergingUpdateQueue myExternalActivitiesQueue;
 
   public ExternalToolPassFactory(Project project, TextEditorHighlightingPassRegistrar highlightingPassRegistrar) {
@@ -83,4 +82,18 @@ public class ExternalToolPassFactory extends AbstractProjectComponent implements
   void scheduleExternalActivity(@NotNull Update update) {
     myExternalActivitiesQueue.queue(update);
   }
+
+  @Nullable
+  @Override
+  public TextEditorHighlightingPass createMainHighlightingPass(@NotNull PsiFile file,
+                                                               @NotNull Document document,
+                                                               @NotNull HighlightInfoProcessor highlightInfoProcessor) {
+    TextRange range = file.getTextRange();
+    if (range == null || !externalAnnotatorsDefined(file)) {
+      return null;
+    }
+    return new ExternalToolPass(this, file, document,
+                                range.getStartOffset(), range.getEndOffset(),
+                                highlightInfoProcessor, true);
+  }
 }