@NotNull
  private TextEditorHighlightingPass convertToTextHighlightingPass(
      @NotNull final HighlightingPass pass,
      final Document document,
      @NotNull AtomicInteger id,
      int previousPassId) {
    TextEditorHighlightingPass textEditorHighlightingPass;
    if (pass instanceof TextEditorHighlightingPass) {
      textEditorHighlightingPass = (TextEditorHighlightingPass) pass;
    } else {
      // run all passes in sequence
      textEditorHighlightingPass =
          new TextEditorHighlightingPass(myProject, document, true) {
            @Override
            public void doCollectInformation(@NotNull ProgressIndicator progress) {
              pass.collectInformation(progress);
            }

            @Override
            public void doApplyInformationToEditor() {
              pass.applyInformationToEditor();
            }
          };
      textEditorHighlightingPass.setId(id.incrementAndGet());
      if (previousPassId != 0) {
        textEditorHighlightingPass.setCompletionPredecessorIds(new int[] {previousPassId});
      }
    }
    return textEditorHighlightingPass;
  }