List<HighlightInfo> (@NotNull PsiFile psiFile, @NotNull Editor editor, int @NotNull [] toIgnore, boolean canChangeDocument, boolean readEditorMarkupModel) { Project project = psiFile.getProject(); ensureIndexesUpToDate(project); VirtualFile virtualFile = psiFile.getVirtualFile(); if (!ReadAction.compute(() -> ProblemHighlightFilter.shouldHighlightFile(psiFile))) { boolean inSource = ReadAction.compute(() -> ProjectRootManager.getInstance(project).getFileIndex().isInSource(virtualFile)); throw new IllegalStateException("ProblemHighlightFilter.shouldHighlightFile('" + psiFile + "') == false, so can't highlight it." + (inSource ? "" : " Maybe it's because " + virtualFile+ " is outside source folders? (source folders: " + ReadAction.compute(() -> Arrays.toString(ProjectRootManager.getInstance(project).getContentSourceRoots()))+")")); } DaemonCodeAnalyzerImpl codeAnalyzer = (DaemonCodeAnalyzerImpl)DaemonCodeAnalyzer.getInstance(project); TextEditor textEditor = TextEditorProvider.getInstance().getTextEditor(editor); DaemonCodeAnalyzerSettings settings = DaemonCodeAnalyzerSettings.getInstance(); ProjectInspectionProfileManager.getInstance(project); // avoid "severities changed, restart" event ProcessCanceledException exception = null; int retries = 1000; for (int i = 0; i < retries; i++) { int oldDelay = settings.getAutoReparseDelay(); try { settings.setAutoReparseDelay(0); List<HighlightInfo> infos = new ArrayList<>(); EdtTestUtil.runInEdtAndWait(() -> { codeAnalyzer.runPasses(psiFile, editor.getDocument(), textEditor, toIgnore, canChangeDocument, null); IdeaTestExecutionPolicy policy = IdeaTestExecutionPolicy.current(); if (policy != null) { policy.waitForHighlighting(project, editor); } IdentifierHighlighterPassFactory.waitForIdentifierHighlighting(); UIUtil.dispatchAllInvocationEvents(); infos.addAll(DaemonCodeAnalyzerImpl.getHighlights(editor.getDocument(), null, project)); if (readEditorMarkupModel) { MarkupModelEx markupModel = (MarkupModelEx)editor.getMarkupModel(); DaemonCodeAnalyzerEx.processHighlights(markupModel, project, null, 0, editor.getDocument().getTextLength(), Processors.cancelableCollectProcessor(infos)); } }); return infos; } catch (ProcessCanceledException e) { Throwable cause = e.getCause(); if (cause != null && cause.getClass() != Throwable.class) { // canceled because of an exception, no need to repeat the same throw e; } EdtTestUtil.runInEdtAndWait(() -> { PsiDocumentManager.getInstance(project).commitAllDocuments(); UIUtil.dispatchAllInvocationEvents(); }); exception = e; } finally { settings.setAutoReparseDelay(oldDelay); } } throw new AssertionError("Unable to highlight after " + retries + " retries", exception); }