From b4c3e873585b1863615efca2bd38de3fa46a8352 Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Wed, 24 Sep 2025 13:51:53 +0200 Subject: [PATCH] xml: port more passes to background apply, part of IJPL-207812 port UpdateHighlightersUtil usages to BackgroundUpdateHighlightersUtil for better responsiveness GitOrigin-RevId: 286c5fa9a295c5ebad280202f2cb187d36a719e7 --- .../xml/XmlCustomTagHighlightingPass.kt | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/xml/xml-analysis-impl/src/com/intellij/xml/XmlCustomTagHighlightingPass.kt b/xml/xml-analysis-impl/src/com/intellij/xml/XmlCustomTagHighlightingPass.kt index 2b618a3d77ff..a1100b83dbae 100644 --- a/xml/xml-analysis-impl/src/com/intellij/xml/XmlCustomTagHighlightingPass.kt +++ b/xml/xml-analysis-impl/src/com/intellij/xml/XmlCustomTagHighlightingPass.kt @@ -2,10 +2,10 @@ package com.intellij.xml import com.intellij.codeHighlighting.TextEditorHighlightingPass +import com.intellij.codeInsight.daemon.impl.BackgroundUpdateHighlightersUtil import com.intellij.codeInsight.daemon.impl.HighlightInfo import com.intellij.codeInsight.daemon.impl.HighlightInfoType.INFORMATION import com.intellij.codeInsight.daemon.impl.HighlightInfoType.SYMBOL_TYPE_SEVERITY -import com.intellij.codeInsight.daemon.impl.UpdateHighlightersUtil import com.intellij.codeInsight.daemon.impl.analysis.HighlightInfoHolder import com.intellij.codeInspection.htmlInspections.XmlEntitiesInspection import com.intellij.lang.ASTNode @@ -38,10 +38,10 @@ private val attributeKeyMapping: Map = map ) internal class XmlCustomTagHighlightingPass(val file: PsiFile, editor: Editor) : TextEditorHighlightingPass(file.project, editor.document, true) { - private val myHolder: HighlightInfoHolder = HighlightInfoHolder(file) private val myHighlighter = SyntaxHighlighterFactory.getSyntaxHighlighter(file.language, file.project, file.virtualFile) override fun doCollectInformation(progress: ProgressIndicator) { + val myHolder = HighlightInfoHolder(file) file.acceptChildren(object : XmlRecursiveElementWalkingVisitor() { override fun visitXmlTag(tag: XmlTag) { super.visitXmlTag(tag) @@ -55,12 +55,17 @@ internal class XmlCustomTagHighlightingPass(val file: PsiFile, editor: Editor) : if (isCustomTag(file, tag)) { tag.node?.let { for (child in it.getChildren(null)) { - applyHighlighting(tag, child, child.elementType) + applyHighlighting(tag, child, child.elementType, myHolder) } } } } }) + val highlights: MutableList = mutableListOf() + for (i in 0 until myHolder.size()) { + highlights.add(myHolder[i]) + } + BackgroundUpdateHighlightersUtil.setHighlightersToEditor(myProject, file, myDocument, 0, file.textLength, highlights, id) } private fun getCustomNames() = @@ -69,14 +74,14 @@ internal class XmlCustomTagHighlightingPass(val file: PsiFile, editor: Editor) : ?.mapTo(HashSet()) { StringUtil.toLowerCase(it) } ?: emptySet() - private fun applyHighlighting(originalXmlTag: XmlTag, node: ASTNode, elementType: IElementType) { + private fun applyHighlighting(originalXmlTag: XmlTag, node: ASTNode, elementType: IElementType, holder: HighlightInfoHolder) { if (node !is LeafElement) return val effectiveElementType = if (elementType == XmlTokenType.XML_NAME) XmlTokenType.XML_TAG_NAME else elementType val attributesKeys = myHighlighter.getTokenHighlights(effectiveElementType) val newAttributesKeys = replaceTextAttributeKeys(originalXmlTag, attributesKeys) if (!newAttributesKeys.contentEquals(attributesKeys)) { - myHolder.add(highlight(originalXmlTag, node, newAttributesKeys)) + holder.add(highlight(originalXmlTag, node, newAttributesKeys)) } } @@ -115,11 +120,6 @@ internal class XmlCustomTagHighlightingPass(val file: PsiFile, editor: Editor) : .firstNotNullOfOrNull { it.highlightCustomTag(file, originalXmlTag) } override fun doApplyInformationToEditor() { - val highlights: MutableList = mutableListOf() - for (i in 0 until myHolder.size()) { - highlights.add(myHolder[i]) - } - UpdateHighlightersUtil.setHighlightersToEditor(myProject, myDocument, 0, file.textLength, highlights, colorsScheme, id) } }