From 69029cd4c499a62318821da447801e1c5201cad0 Mon Sep 17 00:00:00 2001 From: Andrey Starovoyt Date: Thu, 2 Dec 2021 18:36:25 +0300 Subject: [PATCH] html/xml: remove "tag" support, keep only tag name for simplicity WEB-21035 GitOrigin-RevId: 02fd163c3bd385450d0d6d17e2d688b7c667ef50 --- .../src/META-INF/XmlPlugin.xml | 2 +- .../XmlTagTreeHighlightingPass.java | 3 +- .../options/colors/pages/HTMLColorsPage.java | 6 +- .../options/colors/pages/XMLColorsPage.java | 6 +- .../resources/messages/XmlBundle.properties | 1 - .../xml/XmlHighlightsExtractorTest.java | 3 +- .../html/HtmlCustomTagHighlightingPass.kt | 183 ------------------ .../xml/XmlCustomTagHighlightingPass.kt | 121 ++++++++++++ .../XmlCustomTagHighlightingPassFactory.kt} | 17 +- .../openapi/editor/XmlHighlighterColors.java | 4 - .../xml/XmlCustomElementDescriptor.java | 15 ++ .../intellij/xml/XmlElementDescriptor.java | 8 - .../ide/highlighter/HtmlFileHighlighter.java | 4 +- 13 files changed, 152 insertions(+), 221 deletions(-) delete mode 100644 xml/xml-analysis-impl/src/com/intellij/html/HtmlCustomTagHighlightingPass.kt create mode 100644 xml/xml-analysis-impl/src/com/intellij/xml/XmlCustomTagHighlightingPass.kt rename xml/xml-analysis-impl/src/com/intellij/{html/HtmlCustomTagHighlightingPassFactory.kt => xml/XmlCustomTagHighlightingPassFactory.kt} (56%) create mode 100644 xml/xml-psi-api/src/com/intellij/xml/XmlCustomElementDescriptor.java diff --git a/platform/platform-resources/src/META-INF/XmlPlugin.xml b/platform/platform-resources/src/META-INF/XmlPlugin.xml index fc9984bfb82a..9bf27b081ad6 100644 --- a/platform/platform-resources/src/META-INF/XmlPlugin.xml +++ b/platform/platform-resources/src/META-INF/XmlPlugin.xml @@ -106,8 +106,8 @@ + - diff --git a/xml/impl/src/com/intellij/codeInsight/daemon/impl/tagTreeHighlighting/XmlTagTreeHighlightingPass.java b/xml/impl/src/com/intellij/codeInsight/daemon/impl/tagTreeHighlighting/XmlTagTreeHighlightingPass.java index 830725e28920..bd4c7fd91371 100644 --- a/xml/impl/src/com/intellij/codeInsight/daemon/impl/tagTreeHighlighting/XmlTagTreeHighlightingPass.java +++ b/xml/impl/src/com/intellij/codeInsight/daemon/impl/tagTreeHighlighting/XmlTagTreeHighlightingPass.java @@ -238,7 +238,8 @@ public class XmlTagTreeHighlightingPass extends TextEditorHighlightingPass { @NotNull private static HighlightInfo createHighlightInfo(Color color, @NotNull TextRange range) { TextAttributes attributes = new TextAttributes(null, color, null, null, Font.PLAIN); - return HighlightInfo.newHighlightInfo(TYPE).range(range).textAttributes(attributes).severity(HighlightSeverity.INFORMATION).createUnconditionally(); + return HighlightInfo.newHighlightInfo(TYPE).range(range).textAttributes(attributes) + .severity(HighlightInfoType.ELEMENT_UNDER_CARET_SEVERITY).createUnconditionally(); } @NotNull diff --git a/xml/impl/src/com/intellij/openapi/options/colors/pages/HTMLColorsPage.java b/xml/impl/src/com/intellij/openapi/options/colors/pages/HTMLColorsPage.java index 9fe2be29f7f2..5cb1e260f711 100644 --- a/xml/impl/src/com/intellij/openapi/options/colors/pages/HTMLColorsPage.java +++ b/xml/impl/src/com/intellij/openapi/options/colors/pages/HTMLColorsPage.java @@ -39,7 +39,6 @@ public class HTMLColorsPage implements ColorSettingsPage { new AttributesDescriptor(XmlBundle.message("options.html.attribute.descriptor.code"), XmlHighlighterColors.HTML_CODE), new AttributesDescriptor(XmlBundle.message("options.html.attribute.descriptor.comment"), XmlHighlighterColors.HTML_COMMENT), new AttributesDescriptor(XmlBundle.message("options.html.attribute.descriptor.tag"), XmlHighlighterColors.HTML_TAG), - new AttributesDescriptor(XmlBundle.message("options.xml.attribute.descriptor.tag.custom"), XmlHighlighterColors.HTML_CUSTOM_TAG), new AttributesDescriptor(XmlBundle.message("options.xml.attribute.descriptor.tag.name.custom"), XmlHighlighterColors.HTML_CUSTOM_TAG_NAME), new AttributesDescriptor(XmlBundle.message("options.html.attribute.descriptor.tag.name"), XmlHighlighterColors.HTML_TAG_NAME), new AttributesDescriptor(XmlBundle.message("options.html.attribute.descriptor.attribute.name"), XmlHighlighterColors.HTML_ATTRIBUTE_NAME), @@ -101,9 +100,9 @@ public class HTMLColorsPage implements ColorSettingsPage { "

" + FULL_PRODUCT_NAME + "

\n" + "


\n" + "What is " + FULL_PRODUCT_NAME.replaceAll(" ", " ") + "? · Α

\n" + - "<custom-tag>" + + "<custom-tag>" + "hello" + - "custom_tag>\n" + + "custom_tag>\n" + "\n" + ""; } @@ -111,7 +110,6 @@ public class HTMLColorsPage implements ColorSettingsPage { @Override public Map getAdditionalHighlightingTagToDescriptorMap() { return new ContainerUtil.ImmutableMapBuilder() - .put("custom_tag", XmlHighlighterColors.HTML_CUSTOM_TAG) .put("custom_tag_name", XmlHighlighterColors.HTML_CUSTOM_TAG_NAME) .build(); } diff --git a/xml/impl/src/com/intellij/openapi/options/colors/pages/XMLColorsPage.java b/xml/impl/src/com/intellij/openapi/options/colors/pages/XMLColorsPage.java index 046df943f3a3..ae597df69e37 100644 --- a/xml/impl/src/com/intellij/openapi/options/colors/pages/XMLColorsPage.java +++ b/xml/impl/src/com/intellij/openapi/options/colors/pages/XMLColorsPage.java @@ -37,7 +37,6 @@ public class XMLColorsPage implements ColorSettingsPage { new AttributesDescriptor(XmlBundle.message("options.xml.attribute.descriptor.comment"), XmlHighlighterColors.XML_COMMENT), new AttributesDescriptor(XmlBundle.message("options.xml.attribute.descriptor.tag"), XmlHighlighterColors.XML_TAG), new AttributesDescriptor(XmlBundle.message("options.xml.attribute.descriptor.tag.name"), XmlHighlighterColors.XML_TAG_NAME), - new AttributesDescriptor(XmlBundle.message("options.xml.attribute.descriptor.tag.custom"), XmlHighlighterColors.XML_CUSTOM_TAG), new AttributesDescriptor(XmlBundle.message("options.xml.attribute.descriptor.tag.name.custom"), XmlHighlighterColors.XML_CUSTOM_TAG_NAME), new AttributesDescriptor(XmlBundle.message("options.xml.attribute.descriptor.matched.tag.name"), XmlHighlighterColors.MATCHED_TAG_NAME), new AttributesDescriptor(XmlBundle.message("options.xml.attribute.descriptor.namespace.prefix"), XmlHighlighterColors.XML_NS_PREFIX), @@ -95,9 +94,9 @@ public class XMLColorsPage implements ColorSettingsPage { " ]]>\n" + " \n" + " \n" + - " <custom-tag>" + + " <custom-tag>" + "hello" + - "custom_tag>\n" + + "custom_tag>\n" + " <pf:foo pf:bar=\"bar\"/>\n" + ""; } @@ -105,7 +104,6 @@ public class XMLColorsPage implements ColorSettingsPage { @Override public Map getAdditionalHighlightingTagToDescriptorMap() { return new ContainerUtil.ImmutableMapBuilder() - .put("custom_tag", XmlHighlighterColors.XML_CUSTOM_TAG) .put("custom_tag_name", XmlHighlighterColors.XML_CUSTOM_TAG_NAME) .put("np", XmlHighlighterColors.XML_NS_PREFIX) .put("bg", XmlHighlighterColors.XML_TAG) diff --git a/xml/openapi/resources/messages/XmlBundle.properties b/xml/openapi/resources/messages/XmlBundle.properties index 97e788ddc1fd..d942e8e5b23a 100644 --- a/xml/openapi/resources/messages/XmlBundle.properties +++ b/xml/openapi/resources/messages/XmlBundle.properties @@ -296,7 +296,6 @@ options.xml.attribute.descriptor.tag=Tag options.xml.attribute.descriptor.tag.data=Tag Data action.name.show.history.for.text=Text options.html.attribute.descriptor.tag=Tag -options.xml.attribute.descriptor.tag.custom=Custom Tag options.xml.attribute.descriptor.tag.name.custom=Custom Tag Name inspection.javadoc.html.not.required.label.text=Additional not required html attributes: inspection.javadoc.html.not.required.dialog.title=Edit Additional Not Required Html Attributes diff --git a/xml/tests/src/com/intellij/xml/XmlHighlightsExtractorTest.java b/xml/tests/src/com/intellij/xml/XmlHighlightsExtractorTest.java index 5bb926577390..5ea8b46a06dc 100644 --- a/xml/tests/src/com/intellij/xml/XmlHighlightsExtractorTest.java +++ b/xml/tests/src/com/intellij/xml/XmlHighlightsExtractorTest.java @@ -34,7 +34,7 @@ public class XmlHighlightsExtractorTest extends LightPlatformTestCase { List highlights = new ArrayList<>(); String s = new HighlightsExtractor(map, INLINE_ELEMENT_DESCRIPTORS, COLOR_KEY_MAPPING).extractHighlights(page.getDemoText(), highlights); - assertEquals(8, highlights.size()); + assertEquals(10, highlights.size()); assertEquals("\n" + "\n" + "\n" + @@ -52,6 +52,7 @@ public class XmlHighlightsExtractorTest extends LightPlatformTestCase { " ]]>\n" + " \n" + " \n" + + " hello\n" + " \n" + "", s); } diff --git a/xml/xml-analysis-impl/src/com/intellij/html/HtmlCustomTagHighlightingPass.kt b/xml/xml-analysis-impl/src/com/intellij/html/HtmlCustomTagHighlightingPass.kt deleted file mode 100644 index 63ea847d4263..000000000000 --- a/xml/xml-analysis-impl/src/com/intellij/html/HtmlCustomTagHighlightingPass.kt +++ /dev/null @@ -1,183 +0,0 @@ -// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. -package com.intellij.html - -import com.intellij.codeHighlighting.TextEditorHighlightingPass -import com.intellij.codeInsight.daemon.impl.HighlightInfo -import com.intellij.codeInsight.daemon.impl.HighlightInfoType -import com.intellij.codeInsight.daemon.impl.UpdateHighlightersUtil -import com.intellij.codeInsight.daemon.impl.analysis.HighlightInfoHolder -import com.intellij.lang.ASTNode -import com.intellij.openapi.editor.Editor -import com.intellij.openapi.editor.XmlHighlighterColors -import com.intellij.openapi.editor.colors.EditorColorsUtil -import com.intellij.openapi.editor.colors.TextAttributesKey -import com.intellij.openapi.editor.ex.util.LayeredTextAttributes -import com.intellij.openapi.fileTypes.SyntaxHighlighterFactory -import com.intellij.openapi.progress.ProgressIndicator -import com.intellij.openapi.util.TextRange -import com.intellij.psi.PsiFile -import com.intellij.psi.XmlRecursiveElementWalkingVisitor -import com.intellij.psi.impl.source.html.dtd.HtmlElementDescriptorImpl -import com.intellij.psi.impl.source.html.dtd.HtmlNSDescriptorImpl -import com.intellij.psi.impl.source.tree.LeafElement -import com.intellij.psi.tree.IElementType -import com.intellij.psi.tree.xml.IXmlLeafElementType -import com.intellij.psi.xml.XmlAttribute -import com.intellij.psi.xml.XmlAttributeValue -import com.intellij.psi.xml.XmlTag -import com.intellij.psi.xml.XmlTokenType -import com.intellij.xml.XmlElementDescriptor - -val attributeKeyMapping = mapOf( - XmlHighlighterColors.HTML_TAG_NAME to XmlHighlighterColors.HTML_CUSTOM_TAG_NAME, - XmlHighlighterColors.XML_TAG_NAME to XmlHighlighterColors.XML_CUSTOM_TAG_NAME, - XmlHighlighterColors.HTML_TAG to XmlHighlighterColors.HTML_CUSTOM_TAG, - XmlHighlighterColors.XML_TAG to XmlHighlighterColors.XML_CUSTOM_TAG -) - -class HtmlCustomTagHighlightingPass(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) { - file.acceptChildren(object : XmlRecursiveElementWalkingVisitor() { - override fun visitXmlTag(tag: XmlTag) { - super.visitXmlTag(tag) - val descriptor = tag.descriptor ?: return - - if (descriptor.isCustomElement || !isHtmlTagName(descriptor, tag)) { - tag.node?.let { addLexerBasedHighlighting(it) } - } - } - }) - } - - private fun isHtmlTagName(descriptor: XmlElementDescriptor, tag: XmlTag): Boolean { - if (descriptor is HtmlElementDescriptorImpl) return true - val nsDescriptor = tag.getNSDescriptor(tag.namespace, true) - if (nsDescriptor is HtmlNSDescriptorImpl) { - val htmlDescriptor = nsDescriptor.getElementDescriptorByName(tag.name) - if (htmlDescriptor != null) return true - } - return false - } - - /** - * We have to use highlighting lexer for the mappings current token text attributes -> custom token text attributes - * because XML/HTML highlighting lexer produces in some cases different tokens, and we have to map these tokens, and not real one - */ - fun addLexerBasedHighlighting(node: ASTNode) { - val (ranges, excludedRanges) = collectRanges(node) - if (ranges.isEmpty()) return - val highlightingLexer = myHighlighter.highlightingLexer - val chars = node.chars - val text = ranges.joinToString("") { it.subSequence(chars) } - - highlightingLexer.start(text) - - val startOffset = node.startOffset - var indexOfCurrentRange = 0 - var currentRange = ranges[0] - var offsetOfCurrentRange = 0 - while (highlightingLexer.tokenType != null) { - if (highlightingLexer.tokenStart >= currentRange.length + offsetOfCurrentRange) { - offsetOfCurrentRange += currentRange.length - currentRange = ranges[++indexOfCurrentRange] - } - - val relativeOffsetStart = (highlightingLexer.tokenStart - offsetOfCurrentRange) + currentRange.startOffset - val relativeOffsetEnd = (highlightingLexer.tokenEnd - offsetOfCurrentRange) + currentRange.startOffset - - if (excludedRanges.none { it.containsRange(relativeOffsetStart, relativeOffsetEnd) }) { - val absoluteStart = relativeOffsetStart + startOffset - val absoluteEnd = relativeOffsetEnd + startOffset - applyHighlighting(TextRange(absoluteStart, absoluteEnd), highlightingLexer.tokenType!!) - } - - highlightingLexer.advance() - } - } - - private fun collectRanges(node: ASTNode): Pair, List> { - var tagStarted = -1 - val includeRanges = mutableListOf() - val excludedRanges = mutableListOf() - for (child in node.getChildren(null)) { - val elementType = child.elementType - if (tagStarted == -1) { - if (elementType == XmlTokenType.XML_START_TAG_START || - elementType == XmlTokenType.XML_END_TAG_START) { - tagStarted = child.startOffsetInParent - } - } - - if (tagStarted >= 0) { - if (elementType !is IXmlLeafElementType) { - addExcludedRangesForComposite(child, excludedRanges) - } - else if (elementType == XmlTokenType.XML_EMPTY_ELEMENT_END || elementType == XmlTokenType.XML_TAG_END) { - includeRanges.add(TextRange(tagStarted, child.startOffsetInParent + child.textLength)) - tagStarted = -1 - } - } - } - return includeRanges to excludedRanges - } - - fun addExcludedRangesForComposite(child: ASTNode, excludedRanges: MutableList) { - if (child is LeafElement) return - - when (child.psi) { - is XmlAttribute -> { - for (attrPartNode in child.getChildren(null)) { - addExcludedRangesForComposite(attrPartNode, excludedRanges) - } - } - is XmlAttributeValue -> { - for (attValuePartNode in child.getChildren(null)) { - addExcludedRangesForComposite(attValuePartNode, excludedRanges) - } - } - else -> { - excludedRanges.add(TextRange(child.startOffsetInParent, child.startOffsetInParent + child.textLength)) - } - } - } - - private fun applyHighlighting(textRange: TextRange, elementType: IElementType) { - val attributesKeys = myHighlighter.getTokenHighlights(elementType) - val newAttributesKeys = replaceTextAttributeKeys(attributesKeys) - if (!newAttributesKeys.contentEquals(attributesKeys)) { - myHolder.add(highlight(textRange, newAttributesKeys)) - } - } - - private fun replaceTextAttributeKeys(newAttributesKeys: Array): Array { - when { - hasKey(newAttributesKeys) -> { - return newAttributesKeys.map { attributeKeyMapping[it] ?: it }.toTypedArray() - } - else -> return newAttributesKeys - } - } - - private fun hasKey(keys: Array): Boolean { - return keys.firstOrNull { attributeKeyMapping.containsKey(it) } != null - } - - private fun highlight(range: TextRange, key: Array): HighlightInfo? { - return HighlightInfo.newHighlightInfo(HighlightInfoType.INFORMATION) - .severity(HighlightInfoType.SYMBOL_TYPE_SEVERITY) - .range(range) - .textAttributes(LayeredTextAttributes.create(colorsScheme ?: EditorColorsUtil.getGlobalOrDefaultColorScheme(), key)).create() - } - - override fun doApplyInformationToEditor() { - val highlights: MutableList = ArrayList() - for (i in 0 until myHolder.size()) { - highlights.add(myHolder[i]) - } - UpdateHighlightersUtil.setHighlightersToEditor(myProject, myDocument, 0, file.textLength, highlights, colorsScheme, id) - } -} \ No newline at end of file diff --git a/xml/xml-analysis-impl/src/com/intellij/xml/XmlCustomTagHighlightingPass.kt b/xml/xml-analysis-impl/src/com/intellij/xml/XmlCustomTagHighlightingPass.kt new file mode 100644 index 000000000000..a0cdf31c1529 --- /dev/null +++ b/xml/xml-analysis-impl/src/com/intellij/xml/XmlCustomTagHighlightingPass.kt @@ -0,0 +1,121 @@ +// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +package com.intellij.xml + +import com.intellij.codeHighlighting.TextEditorHighlightingPass +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.lang.ASTNode +import com.intellij.lang.html.HtmlCompatibleFile +import com.intellij.openapi.application.ApplicationManager +import com.intellij.openapi.editor.Editor +import com.intellij.openapi.editor.XmlHighlighterColors +import com.intellij.openapi.editor.colors.EditorColorsUtil +import com.intellij.openapi.editor.colors.TextAttributesKey +import com.intellij.openapi.editor.ex.util.LayeredTextAttributes +import com.intellij.openapi.fileTypes.SyntaxHighlighterFactory +import com.intellij.openapi.progress.ProgressIndicator +import com.intellij.openapi.util.NlsSafe +import com.intellij.psi.PsiFile +import com.intellij.psi.XmlRecursiveElementWalkingVisitor +import com.intellij.psi.impl.source.html.dtd.HtmlElementDescriptorImpl +import com.intellij.psi.impl.source.html.dtd.HtmlNSDescriptorImpl +import com.intellij.psi.impl.source.tree.LeafElement +import com.intellij.psi.tree.IElementType +import com.intellij.psi.xml.XmlElementType +import com.intellij.psi.xml.XmlTag +import com.intellij.xml.impl.schema.AnyXmlElementDescriptor +import com.intellij.xml.util.HtmlUtil + +val attributeKeyMapping = mapOf( + XmlHighlighterColors.HTML_TAG_NAME to XmlHighlighterColors.HTML_CUSTOM_TAG_NAME, + XmlHighlighterColors.XML_TAG_NAME to XmlHighlighterColors.XML_CUSTOM_TAG_NAME +) + +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) { + file.acceptChildren(object : XmlRecursiveElementWalkingVisitor() { + override fun visitXmlTag(tag: XmlTag) { + super.visitXmlTag(tag) + val descriptor = tag.descriptor ?: return + if (descriptor is AnyXmlElementDescriptor) return + if (isCustomTag(descriptor, tag)) { + tag.node?.let { + for (child in it.getChildren(null)) { + applyHighlighting(child, child.elementType) + } + } + } + } + }) + } + + private fun isCustomTag(descriptor: XmlElementDescriptor, tag: XmlTag): Boolean { + if (descriptor is XmlCustomElementDescriptor) return descriptor.isCustomElement() + + return isHtmlLikeFile() && !isHtmlTagName(descriptor, tag) + } + + private fun isHtmlLikeFile() = file.viewProvider.allFiles.any { it is HtmlCompatibleFile } || HtmlUtil.supportsXmlTypedHandlers(file) + + private fun isHtmlTagName(descriptor: XmlElementDescriptor, tag: XmlTag): Boolean { + if (descriptor is HtmlElementDescriptorImpl) return true + val nsDescriptor = tag.getNSDescriptor(tag.namespace, true) + if (nsDescriptor is HtmlNSDescriptorImpl) { + val htmlDescriptor = nsDescriptor.getElementDescriptorByName(tag.name) + if (htmlDescriptor != null) return true + } + return false + } + + private fun applyHighlighting(node: ASTNode, elementType: IElementType) { + if (node !is LeafElement) return + val effectiveElementType = if (elementType == XmlElementType.XML_NAME) XmlElementType.XML_TAG_NAME else elementType + + val attributesKeys = myHighlighter.getTokenHighlights(effectiveElementType) + val newAttributesKeys = replaceTextAttributeKeys(attributesKeys) + if (!newAttributesKeys.contentEquals(attributesKeys)) { + myHolder.add(highlight(node, newAttributesKeys)) + } + } + + private fun replaceTextAttributeKeys(newAttributesKeys: Array): Array { + when { + hasKey(newAttributesKeys) -> { + return newAttributesKeys.map { attributeKeyMapping[it] ?: it }.toTypedArray() + } + else -> return newAttributesKeys + } + } + + private fun hasKey(keys: Array): Boolean { + return keys.firstOrNull { attributeKeyMapping.containsKey(it) } != null + } + + private fun highlight(node: ASTNode, key: Array): HighlightInfo? { + //debug only + @NlsSafe val description = if (ApplicationManager.getApplication().isUnitTestMode) "Custom tag name" else null + var textAttributes = HighlightInfo.newHighlightInfo(INFORMATION) + .severity(SYMBOL_TYPE_SEVERITY) + .range(node) + .textAttributes(LayeredTextAttributes.create(colorsScheme ?: EditorColorsUtil.getGlobalOrDefaultColorScheme(), key)) + if (description != null) { + textAttributes = textAttributes.description(description) + } + return textAttributes.create() + } + + 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) + } +} \ No newline at end of file diff --git a/xml/xml-analysis-impl/src/com/intellij/html/HtmlCustomTagHighlightingPassFactory.kt b/xml/xml-analysis-impl/src/com/intellij/xml/XmlCustomTagHighlightingPassFactory.kt similarity index 56% rename from xml/xml-analysis-impl/src/com/intellij/html/HtmlCustomTagHighlightingPassFactory.kt rename to xml/xml-analysis-impl/src/com/intellij/xml/XmlCustomTagHighlightingPassFactory.kt index e777598be6f0..f5578ca54b27 100644 --- a/xml/xml-analysis-impl/src/com/intellij/html/HtmlCustomTagHighlightingPassFactory.kt +++ b/xml/xml-analysis-impl/src/com/intellij/xml/XmlCustomTagHighlightingPassFactory.kt @@ -1,31 +1,24 @@ // Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. -package com.intellij.html +package com.intellij.xml import com.intellij.codeHighlighting.* -import com.intellij.codeInsight.daemon.impl.tagTreeHighlighting.XmlTagTreeHighlightingUtil -import com.intellij.lang.html.HtmlCompatibleFile -import com.intellij.openapi.application.ApplicationManager +import com.intellij.codeInsight.daemon.impl.tagTreeHighlighting.XmlTagTreeHighlightingUtil.hasXmlViewProvider import com.intellij.openapi.editor.Editor import com.intellij.openapi.project.Project import com.intellij.psi.PsiFile -import com.intellij.psi.impl.source.html.HtmlFileImpl import com.intellij.psi.xml.XmlFile import com.intellij.xml.util.HtmlUtil -class HtmlCustomTagHighlightingPassFactory : TextEditorHighlightingPassFactory, TextEditorHighlightingPassFactoryRegistrar { +class XmlCustomTagHighlightingPassFactory : TextEditorHighlightingPassFactory, TextEditorHighlightingPassFactoryRegistrar { override fun registerHighlightingPassFactory(registrar: TextEditorHighlightingPassRegistrar, project: Project) { registrar.registerTextEditorHighlightingPass(this, null, null, false, -1) } override fun createHighlightingPass(file: PsiFile, editor: Editor): TextEditorHighlightingPass? { - if (!hasHtmlViewProvider(file) && !HtmlUtil.supportsXmlTypedHandlers(file)) { + if (!hasXmlViewProvider(file) && !HtmlUtil.supportsXmlTypedHandlers(file)) { return null } - return HtmlCustomTagHighlightingPass(file, editor) - } - - private fun hasHtmlViewProvider(file: PsiFile): Boolean { - return file.viewProvider.allFiles.any { it is HtmlCompatibleFile } + return XmlCustomTagHighlightingPass(file, editor) } } \ No newline at end of file diff --git a/xml/xml-psi-api/src/com/intellij/openapi/editor/XmlHighlighterColors.java b/xml/xml-psi-api/src/com/intellij/openapi/editor/XmlHighlighterColors.java index 3a4c27902545..5090703ba9d6 100644 --- a/xml/xml-psi-api/src/com/intellij/openapi/editor/XmlHighlighterColors.java +++ b/xml/xml-psi-api/src/com/intellij/openapi/editor/XmlHighlighterColors.java @@ -17,8 +17,6 @@ public final class XmlHighlighterColors { TextAttributesKey.createTextAttributesKey("XML_COMMENT", DefaultLanguageHighlighterColors.LINE_COMMENT); public static final TextAttributesKey XML_TAG = TextAttributesKey.createTextAttributesKey("XML_TAG", DefaultLanguageHighlighterColors.MARKUP_TAG); - public static final TextAttributesKey XML_CUSTOM_TAG = - TextAttributesKey.createTextAttributesKey("XML_CUSTOM_TAG", XML_TAG); public static final TextAttributesKey XML_TAG_NAME = TextAttributesKey.createTextAttributesKey("XML_TAG_NAME", DefaultLanguageHighlighterColors.KEYWORD); public static final TextAttributesKey XML_CUSTOM_TAG_NAME = @@ -38,8 +36,6 @@ public final class XmlHighlighterColors { TextAttributesKey.createTextAttributesKey("HTML_COMMENT", DefaultLanguageHighlighterColors.LINE_COMMENT); public static final TextAttributesKey HTML_TAG = TextAttributesKey.createTextAttributesKey("HTML_TAG", DefaultLanguageHighlighterColors.MARKUP_TAG); - public static final TextAttributesKey HTML_CUSTOM_TAG = - TextAttributesKey.createTextAttributesKey("HTML_CUSTOM_TAG", HTML_TAG); public static final TextAttributesKey HTML_TAG_NAME = TextAttributesKey.createTextAttributesKey("HTML_TAG_NAME", DefaultLanguageHighlighterColors.KEYWORD); diff --git a/xml/xml-psi-api/src/com/intellij/xml/XmlCustomElementDescriptor.java b/xml/xml-psi-api/src/com/intellij/xml/XmlCustomElementDescriptor.java new file mode 100644 index 000000000000..eef9569c11e8 --- /dev/null +++ b/xml/xml-psi-api/src/com/intellij/xml/XmlCustomElementDescriptor.java @@ -0,0 +1,15 @@ +// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +package com.intellij.xml; + +/** + * Interface-marker for customization of behaviour "Custom Tag Name" highlighting + */ +public interface XmlCustomElementDescriptor { + + /** + * @return true, if the element should be highlighted as "Custom Tag Name". + * For HTML files, there is also independent logic that checks that if no html tags with such name, + * then IDE will use "Custom tag name" highlighting + */ + boolean isCustomElement(); +} \ No newline at end of file diff --git a/xml/xml-psi-api/src/com/intellij/xml/XmlElementDescriptor.java b/xml/xml-psi-api/src/com/intellij/xml/XmlElementDescriptor.java index 0ecf41fcf8bb..d76ea38e612a 100644 --- a/xml/xml-psi-api/src/com/intellij/xml/XmlElementDescriptor.java +++ b/xml/xml-psi-api/src/com/intellij/xml/XmlElementDescriptor.java @@ -81,12 +81,4 @@ public interface XmlElementDescriptor extends PsiMetaData { @Nullable String getDefaultValue(); - /** - * @return true, if the element should be highlighted as "Custom tag name". - * For HTML files, there is also independent logic that checks that if no html tags with such name, - * then IDE will use "Custom tag name" highlighting - */ - default boolean isCustomElement() { - return false; - } } diff --git a/xml/xml-psi-impl/src/com/intellij/ide/highlighter/HtmlFileHighlighter.java b/xml/xml-psi-impl/src/com/intellij/ide/highlighter/HtmlFileHighlighter.java index 589832c2d0fd..e85276285167 100644 --- a/xml/xml-psi-impl/src/com/intellij/ide/highlighter/HtmlFileHighlighter.java +++ b/xml/xml-psi-impl/src/com/intellij/ide/highlighter/HtmlFileHighlighter.java @@ -35,7 +35,7 @@ import static com.intellij.psi.xml.XmlTokenType.*; public class HtmlFileHighlighter extends SyntaxHighlighterBase { private static final MultiMap ourMap = MultiMap.create(); - + static { ourMap.putValue(XML_TAG_CHARACTERS, XmlHighlighterColors.HTML_TAG); @@ -76,7 +76,7 @@ public class HtmlFileHighlighter extends SyntaxHighlighterBase { public Lexer getHighlightingLexer() { return new HtmlHighlightingLexer(FileTypeRegistry.getInstance().findFileTypeByName("CSS")); } - + @Override public TextAttributesKey @NotNull [] getTokenHighlights(IElementType tokenType) { //noinspection SynchronizationOnGetClass,SynchronizeOnThis