com.intellij.codeHighlighting.TextEditorHighlightingPass Java Examples

The following examples show how to use com.intellij.codeHighlighting.TextEditorHighlightingPass. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PassExecutorService.java    From consulo with Apache License 2.0 6 votes vote down vote up
static void log(ProgressIndicator progressIndicator, TextEditorHighlightingPass pass, @NonNls @Nonnull Object... info) {
  if (LOG.isDebugEnabled()) {
    CharSequence docText = pass == null || pass.getDocument() == null ? "" : ": '" + StringUtil.first(pass.getDocument().getCharsSequence(), 10, true) + "'";
    synchronized (PassExecutorService.class) {
      String infos = StringUtil.join(info, Functions.TO_STRING(), " ");
      String message = StringUtil.repeatSymbol(' ', getThreadNum() * 4) +
                       " " +
                       pass +
                       " " +
                       infos +
                       "; progress=" +
                       (progressIndicator == null ? null : progressIndicator.hashCode()) +
                       " " +
                       (progressIndicator == null ? "?" : progressIndicator.isCanceled() ? "X" : "V") +
                       docText;
      LOG.debug(message);
      //System.out.println(message);
    }
  }
}
 
Example #2
Source File: PassExecutorService.java    From consulo with Apache License 2.0 6 votes vote down vote up
private ScheduledPass findOrCreatePredecessorPass(@Nonnull FileEditor fileEditor,
                                                  @Nonnull Map<Pair<FileEditor, Integer>, ScheduledPass> toBeSubmitted,
                                                  @Nonnull List<TextEditorHighlightingPass> textEditorHighlightingPasses,
                                                  @Nonnull List<ScheduledPass> freePasses,
                                                  @Nonnull List<ScheduledPass> dependentPasses,
                                                  @Nonnull DaemonProgressIndicator updateProgress,
                                                  @Nonnull AtomicInteger myThreadsToStartCountdown,
                                                  final int predecessorId) {
  Pair<FileEditor, Integer> predKey = Pair.create(fileEditor, predecessorId);
  ScheduledPass predecessor = toBeSubmitted.get(predKey);
  if (predecessor == null) {
    TextEditorHighlightingPass textEditorPass = findPassById(predecessorId, textEditorHighlightingPasses);
    predecessor = textEditorPass == null
                  ? null
                  : createScheduledPass(fileEditor, textEditorPass, toBeSubmitted, textEditorHighlightingPasses, freePasses, dependentPasses, updateProgress, myThreadsToStartCountdown);
  }
  return predecessor;
}
 
Example #3
Source File: TextEditorBackgroundHighlighter.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
List<TextEditorHighlightingPass> getPasses(@Nonnull int[] passesToIgnore) {
  if (myProject.isDisposed()) return Collections.emptyList();
  LOG.assertTrue(PsiDocumentManager.getInstance(myProject).isCommitted(myDocument));
  renewFile();
  if (myFile == null) return Collections.emptyList();
  if (myCompiled) {
    passesToIgnore = EXCEPT_OVERRIDDEN;
  }
  else if (!DaemonCodeAnalyzer.getInstance(myProject).isHighlightingAvailable(myFile)) {
    return Collections.emptyList();
  }

  TextEditorHighlightingPassManager passRegistrar = TextEditorHighlightingPassManager.getInstance(myProject);

  return passRegistrar.instantiatePasses(myFile, myEditor, passesToIgnore);
}
 
Example #4
Source File: WidgetIndentsHighlightingPassFactory.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
@NotNull
public TextEditorHighlightingPass createHighlightingPass(@NotNull PsiFile file, @NotNull final Editor e) {
  if (!FlutterSettings.getInstance().isShowBuildMethodGuides()) {
    if (e instanceof EditorEx) {
      // Cleanup highlighters from the widget indents pass if it was
      // previously enabled.
      ApplicationManager.getApplication().invokeLater(() -> WidgetIndentsHighlightingPass.cleanupHighlighters(e));
    }

    // Return a placeholder editor highlighting pass. The user will get the
    // regular IntelliJ platform provided FilteredIndentsHighlightingPass in this case.
    // This is the special case where the user disabled the
    // WidgetIndentsGuides after previously having them setup.
    return new PlaceholderHighlightingPass(
      project,
      e.getDocument(),
      false
    );
  }
  final FilteredIndentsHighlightingPass filteredIndentsHighlightingPass = new FilteredIndentsHighlightingPass(project, e, file);
  if (!(e instanceof EditorEx)) return filteredIndentsHighlightingPass;
  final EditorEx editor = (EditorEx)e;

  final VirtualFile virtualFile = editor.getVirtualFile();
  if (!FlutterUtils.couldContainWidgets(virtualFile)) {
    return filteredIndentsHighlightingPass;
  }
  final FlutterOutline outline = editorOutlineService.getOutline(virtualFile.getCanonicalPath());

  if (outline != null) {
    updateEditorSettings(editor);
    ApplicationManager.getApplication().invokeLater(() -> runWidgetIndentsPass(editor, outline));
  }
  // Return the indent pass rendering regular indent guides with guides that
  // intersect with the widget guides filtered out.
  return filteredIndentsHighlightingPass;
}
 
Example #5
Source File: IdentifierHighlighterPassFactory.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public TextEditorHighlightingPass createHighlightingPass(@Nonnull final PsiFile file, @Nonnull final Editor editor) {
  if (editor.isOneLineMode()) return null;

  if (CodeInsightSettings.getInstance().HIGHLIGHT_IDENTIFIER_UNDER_CARET && (!ApplicationManager.getApplication().isHeadlessEnvironment() || ourTestingIdentifierHighlighting)) {
    return new IdentifierHighlighterPass(file.getProject(), file, editor);
  }
  return null;
}
 
Example #6
Source File: LineMarkersPassFactory.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
@Nullable
public TextEditorHighlightingPass createHighlightingPass(@Nonnull PsiFile file, @Nonnull final Editor editor) {
  TextRange restrictRange = FileStatusMap.getDirtyTextRange(editor, Pass.LINE_MARKERS);
  Document document = editor.getDocument();
  if (restrictRange == null) return new ProgressableTextEditorHighlightingPass.EmptyPass(file.getProject(), document);
  ProperTextRange visibleRange = VisibleHighlightingPassFactory.calculateVisibleRange(editor);
  return new LineMarkersPass(file.getProject(), file, document, expandRangeToCoverWholeLines(document, visibleRange), expandRangeToCoverWholeLines(document, restrictRange));
}
 
Example #7
Source File: PassExecutorService.java    From consulo with Apache License 2.0 5 votes vote down vote up
private ScheduledPass(@Nonnull FileEditor fileEditor,
                      @Nonnull TextEditorHighlightingPass pass,
                      @Nonnull DaemonProgressIndicator progressIndicator,
                      @Nonnull AtomicInteger threadsToStartCountdown) {
  myFileEditor = fileEditor;
  myPass = pass;
  myThreadsToStartCountdown = threadsToStartCountdown;
  myUpdateProgress = progressIndicator;
}
 
Example #8
Source File: ExternalToolPassFactory.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
@Nullable
public TextEditorHighlightingPass createHighlightingPass(@Nonnull PsiFile file, @Nonnull final Editor editor) {
  TextRange textRange = FileStatusMap.getDirtyTextRange(editor, Pass.EXTERNAL_TOOLS) == null ? null : file.getTextRange();
  if (textRange == null || !externalAnnotatorsDefined(file)) {
    return null;
  }
  return new ExternalToolPass(this, file, editor, textRange.getStartOffset(), textRange.getEndOffset());
}
 
Example #9
Source File: WidgetIndentsHighlightingPassFactory.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
@NotNull
public TextEditorHighlightingPass createHighlightingPass(@NotNull PsiFile file, @NotNull final Editor e) {
  if (!FlutterSettings.getInstance().isShowBuildMethodGuides()) {
    if (e instanceof EditorEx) {
      // Cleanup highlighters from the widget indents pass if it was
      // previously enabled.
      ApplicationManager.getApplication().invokeLater(() -> WidgetIndentsHighlightingPass.cleanupHighlighters(e));
    }

    // Return a placeholder editor highlighting pass. The user will get the
    // regular IntelliJ platform provided FilteredIndentsHighlightingPass in this case.
    // This is the special case where the user disabled the
    // WidgetIndentsGuides after previously having them setup.
    return new PlaceholderHighlightingPass(
      project,
      e.getDocument(),
      false
    );
  }
  final FilteredIndentsHighlightingPass filteredIndentsHighlightingPass = new FilteredIndentsHighlightingPass(project, e, file);
  if (!(e instanceof EditorEx)) return filteredIndentsHighlightingPass;
  final EditorEx editor = (EditorEx)e;

  final VirtualFile virtualFile = editor.getVirtualFile();
  if (!FlutterUtils.couldContainWidgets(virtualFile)) {
    return filteredIndentsHighlightingPass;
  }
  final FlutterOutline outline = editorOutlineService.getOutline(virtualFile.getCanonicalPath());

  if (outline != null) {
    updateEditorSettings(editor);
    ApplicationManager.getApplication().invokeLater(() -> runWidgetIndentsPass(editor, outline));
  }
  // Return the indent pass rendering regular indent guides with guides that
  // intersect with the widget guides filtered out.
  return filteredIndentsHighlightingPass;
}
 
Example #10
Source File: GeneralHighlightingPassFactory.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
@Nullable
public TextEditorHighlightingPass createHighlightingPass(@Nonnull PsiFile file, @Nonnull final Editor editor) {
  TextRange textRange = FileStatusMap.getDirtyTextRange(editor, Pass.UPDATE_ALL);
  if (textRange == null) return new EmptyPass(file.getProject(), editor.getDocument());
  ProperTextRange visibleRange = VisibleHighlightingPassFactory.calculateVisibleRange(editor);
  return new GeneralHighlightingPass(file.getProject(), file, editor.getDocument(), textRange.getStartOffset(), textRange.getEndOffset(), true, visibleRange, editor, new DefaultHighlightInfoProcessor());
}
 
Example #11
Source File: DefaultHighlightInfoProcessor.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void highlightsInsideVisiblePartAreProduced(@Nonnull final HighlightingSession session,
                                                   @Nullable Editor editor,
                                                   @Nonnull final List<? extends HighlightInfo> infos,
                                                   @Nonnull TextRange priorityRange,
                                                   @Nonnull TextRange restrictRange,
                                                   final int groupId) {
  final PsiFile psiFile = session.getPsiFile();
  final Project project = psiFile.getProject();
  final Document document = PsiDocumentManager.getInstance(project).getDocument(psiFile);
  if (document == null) return;
  final long modificationStamp = document.getModificationStamp();
  final TextRange priorityIntersection = priorityRange.intersection(restrictRange);
  List<? extends HighlightInfo> infoCopy = new ArrayList<>(infos);
  ((HighlightingSessionImpl)session).applyInEDT(() -> {
    if (modificationStamp != document.getModificationStamp()) return;
    if (priorityIntersection != null) {
      MarkupModel markupModel = DocumentMarkupModel.forDocument(document, project, true);

      EditorColorsScheme scheme = session.getColorsScheme();
      UpdateHighlightersUtil.setHighlightersInRange(project, document, priorityIntersection, scheme, infoCopy, (MarkupModelEx)markupModel, groupId);
    }
    if (editor != null && !editor.isDisposed()) {
      // usability: show auto import popup as soon as possible
      if (!DumbService.isDumb(project)) {
        ShowAutoImportPassFactory siFactory = TextEditorHighlightingPassFactory.EP_NAME.findExtensionOrFail(project, ShowAutoImportPassFactory.class);
        TextEditorHighlightingPass highlightingPass = siFactory.createHighlightingPass(psiFile, editor);
        if (highlightingPass != null) {
          highlightingPass.doApplyInformationToEditor();
        }
      }

      repaintErrorStripeAndIcon(editor, project);
    }
  });
}
 
Example #12
Source File: ChangeSignaturePassFactory.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public TextEditorHighlightingPass createHighlightingPass(@Nonnull final PsiFile file, @Nonnull final Editor editor) {
  LanguageChangeSignatureDetector<ChangeInfo> detector =
          LanguageChangeSignatureDetectors.INSTANCE.forLanguage(file.getLanguage());
  if (detector == null) return null;

  return new ChangeSignaturePass(file.getProject(), file, editor);
}
 
Example #13
Source File: WolfPassFactory.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
@Nullable
public TextEditorHighlightingPass createHighlightingPass(@Nonnull PsiFile file, @Nonnull final Editor editor) {
  final long psiModificationCount = PsiManager.getInstance(file.getProject()).getModificationTracker().getModificationCount();
  if (psiModificationCount == myPsiModificationCount) {
    return null; //optimization
  }
  return new WolfHighlightingPass(file.getProject(), editor.getDocument(), file){
    @Override
    protected void applyInformationWithProgress() {
      super.applyInformationWithProgress();
      myPsiModificationCount = psiModificationCount;
    }
  };
}
 
Example #14
Source File: LocalInspectionsPassFactory.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public TextEditorHighlightingPass createMainHighlightingPass(@Nonnull PsiFile file,
                                                             @Nonnull Document document,
                                                             @Nonnull HighlightInfoProcessor highlightInfoProcessor) {
  final TextRange textRange = file.getTextRange();
  LOG.assertTrue(textRange != null, "textRange is null for " + file + " (" + PsiUtilCore.getVirtualFile(file) + ")");
  return new MyLocalInspectionsPass(file, document, textRange, LocalInspectionsPass.EMPTY_PRIORITY_RANGE, highlightInfoProcessor);
}
 
Example #15
Source File: LocalInspectionsPassFactory.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
@Nullable
public TextEditorHighlightingPass createHighlightingPass(@Nonnull PsiFile file, @Nonnull final Editor editor) {
  TextRange textRange = calculateRangeToProcess(editor);
  if (textRange == null || !InspectionProjectProfileManager.getInstance(file.getProject()).isProfileLoaded()){
    return new ProgressableTextEditorHighlightingPass.EmptyPass(file.getProject(), editor.getDocument());
  }
  TextRange visibleRange = VisibleHighlightingPassFactory.calculateVisibleRange(editor);
  return new MyLocalInspectionsPass(file, editor.getDocument(), textRange, visibleRange, new DefaultHighlightInfoProcessor());
}
 
Example #16
Source File: InjectedGeneralHighlightingPassFactory.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public TextEditorHighlightingPass createMainHighlightingPass(@Nonnull PsiFile file,
                                                             @Nonnull Document document,
                                                             @Nonnull HighlightInfoProcessor highlightInfoProcessor) {
  Project project = file.getProject();
  return new InjectedGeneralHighlightingPass(project, file, document, 0, document.getTextLength(), true, new ProperTextRange(0,document.getTextLength()), null,
                                             highlightInfoProcessor);
}
 
Example #17
Source File: InjectedGeneralHighlightingPassFactory.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
@Nullable
public TextEditorHighlightingPass createHighlightingPass(@Nonnull PsiFile file, @Nonnull final Editor editor) {
  Project project = file.getProject();
  TextRange textRange = FileStatusMap.getDirtyTextRange(editor, Pass.UPDATE_ALL);
  if (textRange == null) return new ProgressableTextEditorHighlightingPass.EmptyPass(project, editor.getDocument());
  ProperTextRange visibleRange = VisibleHighlightingPassFactory.calculateVisibleRange(editor);
  return new InjectedGeneralHighlightingPass(project, file, editor.getDocument(), textRange.getStartOffset(), textRange.getEndOffset(), true, visibleRange, editor,
                                             new DefaultHighlightInfoProcessor());
}
 
Example #18
Source File: CppHighlightingPassFactoryBase.java    From CppTools with Apache License 2.0 5 votes vote down vote up
@Nullable
public TextEditorHighlightingPass createHighlightingPass(@Nullable PsiFile file, @NotNull final Editor editor) {
  final PsiFile psiFile = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument());
  if (psiFile == null || psiFile.getFileType() != CppSupportLoader.CPP_FILETYPE) return null;

  if (HighlightUtils.debug) {
    HighlightUtils.trace(psiFile, editor, "About to highlight:");
  }

  return doCreatePass(editor, psiFile, HighlightUtils.getUpToDateHighlightCommand(psiFile, project));
}
 
Example #19
Source File: InjectedCodeFoldingPassFactory.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
@Nonnull
public TextEditorHighlightingPass createHighlightingPass(@Nonnull PsiFile file, @Nonnull final Editor editor) {
  return new InjectedCodeFoldingPass(file.getProject(), editor, file);
}
 
Example #20
Source File: IndentsPassFactory.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
@Nonnull
public TextEditorHighlightingPass createHighlightingPass(@Nonnull PsiFile file, @Nonnull final Editor editor) {
  return new IndentsPass(file.getProject(), editor, file);
}
 
Example #21
Source File: GeneralHighlightingPassFactory.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public TextEditorHighlightingPass createMainHighlightingPass(@Nonnull PsiFile file, @Nonnull Document document, @Nonnull HighlightInfoProcessor highlightInfoProcessor) {
  // no applying to the editor - for read-only analysis only
  return new GeneralHighlightingPass(file.getProject(), file, document, 0, file.getTextLength(), true, new ProperTextRange(0, document.getTextLength()), null, highlightInfoProcessor);
}
 
Example #22
Source File: CppSimpleEditorHighlightingPassFactory.java    From CppTools with Apache License 2.0 4 votes vote down vote up
protected TextEditorHighlightingPass doCreatePass(Editor editor, PsiFile psiFile, HighlightCommand command) {
  return new SimpleHighlightingPass(editor, psiFile, command);
}
 
Example #23
Source File: CppOverridenHighlightingPassFactory.java    From CppTools with Apache License 2.0 4 votes vote down vote up
protected TextEditorHighlightingPass doCreatePass(Editor editor, PsiFile psiFile, HighlightCommand command) {
  return new OverridenHighlightingPass(editor, psiFile,command);
}
 
Example #24
Source File: TextEditorBackgroundHighlighter.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
@Nonnull
public TextEditorHighlightingPass[] createPassesForEditor() {
  List<TextEditorHighlightingPass> passes = getPasses(ArrayUtil.EMPTY_INT_ARRAY);
  return passes.isEmpty() ? TextEditorHighlightingPass.EMPTY_ARRAY : passes.toArray(new TextEditorHighlightingPass[passes.size()]);
}
 
Example #25
Source File: PassExecutorService.java    From consulo with Apache License 2.0 4 votes vote down vote up
private static void sortById(@Nonnull List<? extends TextEditorHighlightingPass> result) {
  ContainerUtil.quickSort(result, Comparator.comparingInt(TextEditorHighlightingPass::getId));
}
 
Example #26
Source File: PassExecutorService.java    From consulo with Apache License 2.0 4 votes vote down vote up
private static TextEditorHighlightingPass findPassById(final int id, @Nonnull List<? extends TextEditorHighlightingPass> textEditorHighlightingPasses) {
  return ContainerUtil.find(textEditorHighlightingPasses, pass -> pass.getId() == id);
}
 
Example #27
Source File: TextEditorBackgroundHighlighter.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
@Nonnull
public TextEditorHighlightingPass[] createPassesForVisibleArea() {
  return createPassesForEditor();
}
 
Example #28
Source File: ShowAutoImportPassFactory.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
@Nullable
public TextEditorHighlightingPass createHighlightingPass(@Nonnull PsiFile file, @Nonnull final Editor editor) {
  return ApplicationManager.getApplication().isUnitTestMode() || DaemonListeners.canChangeFileSilently(file) ? new ShowAutoImportPass(file.getProject(), file, editor) : null;
}
 
Example #29
Source File: CodeFoldingPassFactory.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
@Nonnull
public TextEditorHighlightingPass createHighlightingPass(@Nonnull PsiFile file, @Nonnull final Editor editor) {
  return new CodeFoldingPass(editor, file);
}
 
Example #30
Source File: WholeFileLocalInspectionsPassFactory.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
@Nullable
public TextEditorHighlightingPass createHighlightingPass(@Nonnull final PsiFile file, @Nonnull final Editor editor) {
  final long psiModificationCount = PsiManager.getInstance(myProject).getModificationTracker().getModificationCount();
  if (psiModificationCount == myPsiModificationCount) {
    return null; //optimization
  }

  if (myFileToolsCache.containsKey(file) && !myFileToolsCache.get(file)) {
    return null;
  }
  ProperTextRange visibleRange = VisibleHighlightingPassFactory.calculateVisibleRange(editor);
  return new LocalInspectionsPass(file, editor.getDocument(), 0, file.getTextLength(), visibleRange, true, new DefaultHighlightInfoProcessor()) {
    @Nonnull
    @Override
    List<LocalInspectionToolWrapper> getInspectionTools(@Nonnull InspectionProfileWrapper profile) {
      List<LocalInspectionToolWrapper> tools = super.getInspectionTools(profile);
      List<LocalInspectionToolWrapper> result = tools.stream().filter(LocalInspectionToolWrapper::runForWholeFile).collect(Collectors.toList());
      myFileToolsCache.put(file, !result.isEmpty());
      return result;
    }

    @Override
    protected String getPresentableName() {
      return DaemonBundle.message("pass.whole.inspections");
    }

    @Override
    void inspectInjectedPsi(@Nonnull List<PsiElement> elements,
                            boolean onTheFly,
                            @Nonnull ProgressIndicator indicator,
                            @Nonnull InspectionManager iManager,
                            boolean inVisibleRange,
                            @Nonnull List<LocalInspectionToolWrapper> wrappers) {
      // already inspected in LIP
    }

    @Override
    protected void applyInformationWithProgress() {
      super.applyInformationWithProgress();
      myPsiModificationCount = PsiManager.getInstance(myProject).getModificationTracker().getModificationCount();
    }
  };
}