private void runAnnotator(@NotNull Annotator annotator,
                            @NotNull List<? extends PsiElement> insideThenOutside,
                            @NotNull Map<Annotator, Set<Language>> supportedLanguages,
                            @NotNull TriConsumer<Object, ? super PsiElement, ? super List<? extends HighlightInfo>> result) {
    Set<Language> supported = supportedLanguages.get(annotator);
    if (supported.isEmpty()) {
      return;
    }
    // create AnnotationHolderImpl for each Annotator to make it immutable thread-safe converter to the corresponding HighlightInfo
    AnnotationSessionImpl.computeWithSession(myBatchMode, annotator, myAnnotationSession, annotationHolder -> {
      for (PsiElement psiElement : insideThenOutside) {
        if (!supported.contains(psiElement.getLanguage())) {
          continue;
        }
        if (!myDumbService.isUsableInCurrentContext(annotator)) {
          continue;
        }
        ProgressManager.checkCanceled();
        int sizeBefore = annotationHolder.size();
        annotationHolder.runAnnotatorWithContext(psiElement);
        int sizeAfter = annotationHolder.size();

        List<HighlightInfo> newInfos;
        if (sizeBefore == sizeAfter) {
          newInfos = List.of();
        }
        else {
          newInfos = new ArrayList<>(sizeAfter - sizeBefore);
          for (int i = sizeBefore; i < sizeAfter; i++) {
            Annotation annotation = annotationHolder.get(i);
            HighlightInfo info = HighlightInfo.fromAnnotation(annotator.getClass(), annotation, myBatchMode);
            info.setGroup(-1); // prevent DefaultHighlightProcessor from removing this info, we want to control it ourselves via `psiElementVisited` below
            if (myPsiFile.getViewProvider() instanceof InjectedFileViewProvider) {
              info.markFromInjection();
            }
            addConvertedToHostInfo(info, newInfos);
            if (LOG.isDebugEnabled()) {
              LOG.debug("runAnnotator "+annotator+"; annotation="+annotation+" -> "+newInfos);
            }
            myAnnotatorStatisticsCollector.reportAnnotationProduced(annotator, annotation);
          }
          results.addAll(newInfos);
        }
        result.accept(annotator.getClass(), psiElement, newInfos);
      }
      return null;
    });
  }
private void runAnnotator(@NotNull Annotator annotator,
                            @NotNull List<? extends PsiElement> insideThenOutside,
                            @NotNull Map<Annotator, Set<Language>> supportedLanguages,
                            @NotNull TriConsumer<Object, ? super PsiElement, ? super List<? extends HighlightInfo>> result)