1
0
mirror of https://github.com/chylex/IntelliJ-Rainbow-Brackets.git synced 2025-05-13 18:34:03 +02:00

Initial support for Pug Language

This commit is contained in:
张志豪 2021-01-30 12:47:26 +08:00
parent 32cd6f8958
commit 85db8483f1
3 changed files with 54 additions and 1 deletions
src/main
kotlin/com/github/izhangzhihao/rainbow/brackets/visitor
resources/META-INF

View File

@ -0,0 +1,52 @@
package com.github.izhangzhihao.rainbow.brackets.visitor
import com.github.izhangzhihao.rainbow.brackets.settings.RainbowSettings
import com.github.izhangzhihao.rainbow.brackets.visitor.XmlRainbowVisitor.Companion.xmlParent
import com.intellij.codeInsight.daemon.impl.HighlightVisitor
import com.intellij.psi.PsiElement
import com.intellij.psi.PsiFile
import com.intellij.psi.xml.XmlTag
import com.intellij.psi.xml.XmlToken
import com.intellij.psi.xml.XmlTokenType
class PugRainbowVisitor : RainbowHighlightVisitor() {
override fun suitableForFile(file: PsiFile)
: Boolean = super.suitableForFile(file) &&
RainbowSettings.instance.isEnableRainbowAngleBrackets &&
(file.language.id == "Jade")
override fun clone(): HighlightVisitor = PugRainbowVisitor()
override fun visit(element: PsiElement) {
if (element !is XmlToken) {
return
}
if (element.tokenType == XmlTokenType.XML_TAG_NAME) {
val parent = element.parent
if (parent != null && parent is XmlTag) {
parent.level.let { element.setHighlightInfo(element.xmlParent, it, element, null) }
}
}
}
companion object {
private tailrec fun iterateXmlTagParents(element: PsiElement?, count: Int, name: String): Int {
if (element == null || element is PsiFile || (element is XmlTag && element.name != name)) {
return count
}
var nextCount = count
if (element is XmlTag && element.name == name) {
nextCount++
}
return iterateXmlTagParents(element.parent, nextCount, name)
}
private val XmlTag.level: Int
get() = iterateXmlTagParents(parent, 0, this.name)
}
}

View File

@ -69,7 +69,7 @@ open class XmlRainbowVisitor : RainbowHighlightVisitor() {
}
companion object {
private val PsiElement.xmlParent: PsiElement?
val PsiElement.xmlParent: PsiElement?
get() {
var pElement = parent
while (pElement != null && pElement !is XmlTag && pElement !is PsiFile) {

View File

@ -667,6 +667,7 @@
<highlightVisitor implementation="com.github.izhangzhihao.rainbow.brackets.visitor.DefaultRainbowVisitor"/>
<highlightVisitor implementation="com.github.izhangzhihao.rainbow.brackets.visitor.XmlRainbowVisitor"/>
<highlightVisitor implementation="com.github.izhangzhihao.rainbow.brackets.visitor.PugRainbowVisitor"/>
<applicationConfigurable instance="com.github.izhangzhihao.rainbow.brackets.settings.RainbowConfigurable"/>
<applicationService