void (@NotNull ProgressIndicator progress) { ApplicationManager.getApplication().assertIsNonDispatchThread(); List<HighlightInfo> outsideResult = new ArrayList<>(100); List<HighlightInfo> insideResult = new ArrayList<>(100); DaemonCodeAnalyzerEx daemonCodeAnalyzer = DaemonCodeAnalyzerEx.getInstanceEx(myProject); HighlightVisitor[] filteredVisitors = getHighlightVisitors(getFile()); try { List<Divider.DividedElements> dividedElements = new ArrayList<>(); Divider.divideInsideAndOutsideAllRoots(getFile(), myRestrictRange, myPriorityRange, SHOULD_HIGHLIGHT_FILTER, new CommonProcessors.CollectProcessor<>(dividedElements)); List<PsiElement> allInsideElements = ContainerUtil.concat(ContainerUtil.map(dividedElements, dividedForRoot -> { List<? extends PsiElement> inside = dividedForRoot.inside(); PsiElement lastInside = ContainerUtil.getLastItem(inside); return lastInside instanceof PsiFile && !(lastInside instanceof PsiCodeFragment) ? inside .subList(0, inside.size() - 1) : inside; })); List<LongList> map = ContainerUtil.map(dividedElements, dividedForRoot -> { LongList insideRanges = dividedForRoot.insideRanges(); PsiElement lastInside = ContainerUtil.getLastItem(dividedForRoot.inside()); return lastInside instanceof PsiFile && !(lastInside instanceof PsiCodeFragment) ? insideRanges.subList(0, insideRanges.size() - 1) : insideRanges; }); LongList allInsideRanges = ContainerUtil.reduce(map, new LongArrayList(map.isEmpty() ? 1 : map.get(0).size()), (l1, l2)->{ l1.addAll(l2); return l1;}); List<PsiElement> allOutsideElements = ContainerUtil.concat(ContainerUtil.map(dividedElements, dividedForRoot -> { List<? extends PsiElement> outside = dividedForRoot.outside(); PsiElement lastInside = ContainerUtil.getLastItem(dividedForRoot.inside()); return lastInside instanceof PsiFile && !(lastInside instanceof PsiCodeFragment) ? ContainerUtil.append(outside, lastInside) : outside; })); List<LongList> map1 = ContainerUtil.map(dividedElements, dividedForRoot -> { LongList outsideRanges = dividedForRoot.outsideRanges(); PsiElement lastInside = ContainerUtil.getLastItem(dividedForRoot.inside()); long lastInsideRange = dividedForRoot.insideRanges().isEmpty() ? -1 : dividedForRoot.insideRanges().getLong(dividedForRoot.insideRanges().size()-1); if (lastInside instanceof PsiFile && !(lastInside instanceof PsiCodeFragment) && lastInsideRange != -1) { LongArrayList r = new LongArrayList(outsideRanges); r.add(lastInsideRange); return r; } return outsideRanges; }); LongList allOutsideRanges = ContainerUtil.reduce(map1, new LongArrayList(map1.isEmpty() ? 1 : map1.get(0).size()), (l1, l2)->{ l1.addAll(l2); return l1;}); setProgressLimit(allInsideElements.size() + allOutsideElements.size()); boolean forceHighlightParents = forceHighlightParents(); if (!isDumbMode() && getEditor() != null) { highlightTodos(getFile(), getDocument().getCharsSequence(), myRestrictRange.getStartOffset(), myRestrictRange.getEndOffset(), myPriorityRange, insideResult, outsideResult); } boolean success = collectHighlights(allInsideElements, allInsideRanges, allOutsideElements, allOutsideRanges, filteredVisitors, insideResult, outsideResult, forceHighlightParents); myHighlights.addAll(insideResult); myHighlights.addAll(outsideResult); if (success) { myHighlightInfoProcessor.highlightsOutsideVisiblePartAreProduced(myHighlightingSession, getEditor(), outsideResult, myPriorityRange, myRestrictRange, getId()); if (myUpdateAll) { daemonCodeAnalyzer.getFileStatusMap().setErrorFoundFlag(myProject, getDocument(), myErrorFound); reportErrorsToWolf(myHasErrorSeverity); } } else { cancelAndRestartDaemonLater(progress, myProject); } } finally { incVisitorUsageCount(-1); } }