void (@NotNull ProgressIndicator progress) { if (!Registry.is("editor.injected.highlighting.enabled")) return; List<Divider.DividedElements> allDivided = new ArrayList<>(); Divider.divideInsideAndOutsideAllRoots(myFile, myRestrictRange, myPriorityRange, SHOULD_HIGHLIGHT_FILTER, new CommonProcessors.CollectProcessor<>(allDivided)); List<PsiElement> allInsideElements = ContainerUtil.concat(ContainerUtil.map(allDivided, d -> d.inside())); List<PsiElement> allOutsideElements = ContainerUtil.concat(ContainerUtil.map(allDivided, d -> d.outside())); List<HighlightInfo> resultInside = new ArrayList<>(100); List<HighlightInfo> resultOutside = new ArrayList<>(100); InjectedLanguageManager injectedLanguageManager = InjectedLanguageManager.getInstance(myProject); TextAttributesKey fragmentKey = createInjectedLanguageFragmentKey(myFile.getLanguage()); processInjectedPsiFiles(allInsideElements, allOutsideElements, progress, (injectedPsi, places) -> addInjectedPsiHighlights(injectedLanguageManager, injectedPsi, places, fragmentKey, patchedInfo -> { queueInfoToUpdateIncrementally(patchedInfo, getId()); synchronized (myHighlights) { if (myRestrictRange.contains(patchedInfo)) { resultInside.add(patchedInfo); } else { // non-conditionally apply injected results regardless whether they are in myRestrictRange resultOutside.add(patchedInfo); } } })); synchronized (myHighlights) { // all infos for the "injected fragment for the host which is inside" are indeed inside // but some infos for the "injected fragment for the host which is outside" can be still inside if (resultOutside.isEmpty()) { // apply only result (by default apply command) and only within inside myHighlights.addAll(resultInside); myHighlightInfoProcessor.highlightsInsideVisiblePartAreProduced(myHighlightingSession, getEditor(), myHighlights, myRestrictRange, myRestrictRange, getId()); } else { boolean priorityIntersectionHasElements = myPriorityRange.intersectsStrict(myRestrictRange); if ((!allInsideElements.isEmpty() || !resultInside.isEmpty()) && priorityIntersectionHasElements) { // do not apply when there were no elements to highlight // clear infos found in visible area to avoid applying them twice myHighlights.addAll(resultInside); myHighlightInfoProcessor.highlightsInsideVisiblePartAreProduced(myHighlightingSession, getEditor(), resultInside, myPriorityRange, myRestrictRange, getId()); } else { for (HighlightInfo info : resultInside) { if (myRestrictRange.contains(info) && !myPriorityRange.contains(info)) { resultOutside.add(info); } } } myHighlightInfoProcessor.highlightsOutsideVisiblePartAreProduced(myHighlightingSession, getEditor(), resultOutside, myRestrictRange, new ProperTextRange(0, myDocument.getTextLength()), getId()); } } }