void (@NotNull Project project, @NotNull Document document) { refresh(null); MarkupModelEx model = (MarkupModelEx)DocumentMarkupModel.forDocument(document, project, true); model.addMarkupModelListener(this, new MarkupModelListener() { @Override public void afterAdded(@NotNull RangeHighlighterEx highlighter) { incErrorCount(highlighter, 1); } @Override public void afterRemoved(@NotNull RangeHighlighterEx highlighter) { incErrorCount(highlighter, -1); } }); UIUtil.invokeLaterIfNeeded(() -> { for (RangeHighlighter rangeHighlighter : model.getAllHighlighters()) { incErrorCount(rangeHighlighter, 1); } }); }