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;
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
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;
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
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));
}
}
+ @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();
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;
/**
* @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) {
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);
+ }
}