mirror of
https://github.com/chylex/IntelliJ-Rainbow-Brackets.git
synced 2025-01-30 22:46:00 +01:00
Compare commits
No commits in common. "5b5cf0aeb54a75b2e2069debf9fdb8c66a24cb20" and "ad617451c7288f9226ef666228499d13b322dadc" have entirely different histories.
5b5cf0aeb5
...
ad617451c7
@ -4,9 +4,6 @@ This is a fork of the [🌈Rainbow Brackets](https://github.com/izhangzhihao/int
|
||||
|
||||
## Key Changes
|
||||
|
||||
- Support for C# (Rider)
|
||||
- Support for C++ (Rider, CLion, CLion Nova)
|
||||
- Support for CLion and Rider
|
||||
- Support for Settings Sync
|
||||
- Improved highlighting performance
|
||||
- Increased default setting for maximum line count from 1K to 100K
|
||||
- Fixed service initialization warnings reported by 2024.2+
|
||||
|
@ -9,7 +9,7 @@ plugins {
|
||||
}
|
||||
|
||||
group = "com.chylex.intellij.coloredbrackets"
|
||||
version = "1.1.0"
|
||||
version = "1.0.0"
|
||||
|
||||
allprojects {
|
||||
apply(plugin = "org.jetbrains.kotlin.jvm")
|
||||
|
@ -38,7 +38,7 @@ class RainbowSettings : PersistentStateComponent<RainbowSettings> {
|
||||
var rainbowifyTagNameInXML = false
|
||||
var doNOTRainbowifyTemplateString = false
|
||||
var doNOTRainbowifyBigFiles = true
|
||||
var bigFilesLinesThreshold = 100_000
|
||||
var bigFilesLinesThreshold = 1000
|
||||
|
||||
var languageBlacklist: Set<String> = setOf("hocon", "mxml")
|
||||
|
||||
|
@ -9,31 +9,28 @@ import com.intellij.psi.PsiElement
|
||||
import com.intellij.psi.PsiFile
|
||||
import com.intellij.psi.impl.source.tree.LeafPsiElement
|
||||
import com.intellij.psi.tree.IElementType
|
||||
import it.unimi.dsi.fastutil.objects.Object2ByteOpenHashMap
|
||||
|
||||
class DefaultRainbowVisitor : RainbowHighlightVisitor() {
|
||||
|
||||
override fun clone(): HighlightVisitor = DefaultRainbowVisitor()
|
||||
|
||||
private var processor: Processor? = null
|
||||
|
||||
override fun onBeforeAnalyze(file: PsiFile, updateWholeFile: Boolean) {
|
||||
processor = Processor(RainbowSettings.instance)
|
||||
}
|
||||
|
||||
override fun visit(element: PsiElement) {
|
||||
val type = (element as? LeafPsiElement)?.elementType ?: return
|
||||
|
||||
val processor = processor!!
|
||||
val settings = RainbowSettings.instance
|
||||
val processor = Processor(settings)
|
||||
val matching = processor.filterPairs(type, element) ?: return
|
||||
|
||||
val pair = when (matching.size) {
|
||||
1 -> matching[0]
|
||||
else -> matching.find { processor.isValidBracket(element, it) } ?: return
|
||||
val pair =
|
||||
if (matching.size == 1) {
|
||||
matching[0]
|
||||
}
|
||||
else {
|
||||
matching.find { processor.isValidBracket(element, it) }
|
||||
} ?: return
|
||||
|
||||
val level = processor.getBracketLevel(element, pair)
|
||||
if (processor.settings.isDoNOTRainbowifyTheFirstLevel) {
|
||||
if (settings.isDoNOTRainbowifyTheFirstLevel) {
|
||||
if (level >= 1) {
|
||||
rainbowPairs(element, pair, level)
|
||||
}
|
||||
@ -45,35 +42,13 @@ class DefaultRainbowVisitor : RainbowHighlightVisitor() {
|
||||
}
|
||||
}
|
||||
|
||||
override fun onAfterAnalyze() {
|
||||
processor = null
|
||||
}
|
||||
|
||||
private fun rainbowPairs(element: LeafPsiElement, pair: BracePair, level: Int) {
|
||||
val startElement = element.takeIf { it.elementType == pair.leftBraceType }
|
||||
val endElement = element.takeIf { it.elementType == pair.rightBraceType }
|
||||
element.setHighlightInfo(element.parent, level, startElement, endElement)
|
||||
}
|
||||
|
||||
private class Processor(val settings: RainbowSettings) {
|
||||
|
||||
private companion object {
|
||||
private const val CACHE_MISS = (-1).toByte()
|
||||
}
|
||||
|
||||
private data class HasBracketsCacheKey(val element: PsiElement, val pair: BracePair) {
|
||||
private val hashCode = (31 * System.identityHashCode(element)) + System.identityHashCode(pair)
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
return other is HasBracketsCacheKey && element === other.element && pair === other.pair
|
||||
}
|
||||
|
||||
override fun hashCode(): Int {
|
||||
return hashCode
|
||||
}
|
||||
}
|
||||
|
||||
private val hasBracketsCache = Object2ByteOpenHashMap<HasBracketsCacheKey>().apply { defaultReturnValue(CACHE_MISS) }
|
||||
private class Processor(private val settings: RainbowSettings) {
|
||||
|
||||
fun getBracketLevel(element: LeafPsiElement, pair: BracePair): Int = iterateBracketParents(element.parent, pair, -1)
|
||||
|
||||
@ -84,19 +59,17 @@ class DefaultRainbowVisitor : RainbowHighlightVisitor() {
|
||||
|
||||
var nextCount = count
|
||||
if (!settings.cycleCountOnAllBrackets) {
|
||||
if (element.hasBrackets(
|
||||
pair,
|
||||
{ it.elementType == pair.leftBraceType },
|
||||
{ it.elementType == pair.rightBraceType })
|
||||
if (element.haveBrackets(
|
||||
{ it.elementType() == pair.leftBraceType },
|
||||
{ it.elementType() == pair.rightBraceType })
|
||||
) {
|
||||
nextCount++
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (element.hasBrackets(
|
||||
pair,
|
||||
{ element.language.braceTypeSet.contains(it.elementType) },
|
||||
{ element.language.braceTypeSet.contains(it.elementType) })
|
||||
if (element.haveBrackets(
|
||||
{ element.language.braceTypeSet.contains(it.elementType()) },
|
||||
{ element.language.braceTypeSet.contains(it.elementType()) })
|
||||
) {
|
||||
nextCount++
|
||||
}
|
||||
@ -105,27 +78,18 @@ class DefaultRainbowVisitor : RainbowHighlightVisitor() {
|
||||
return iterateBracketParents(element.parent, pair, nextCount)
|
||||
}
|
||||
|
||||
private inline fun PsiElement.hasBrackets(
|
||||
pair: BracePair,
|
||||
checkLeft: (LeafPsiElement) -> Boolean,
|
||||
checkRight: (LeafPsiElement) -> Boolean,
|
||||
private inline fun PsiElement.haveBrackets(
|
||||
checkLeft: (PsiElement) -> Boolean,
|
||||
checkRight: (PsiElement) -> Boolean,
|
||||
): Boolean {
|
||||
if (this is LeafPsiElement) {
|
||||
return false
|
||||
}
|
||||
|
||||
val cacheKey = HasBracketsCacheKey(this, pair)
|
||||
val cacheValue = hasBracketsCache.getByte(cacheKey)
|
||||
if (cacheValue != CACHE_MISS) {
|
||||
return cacheValue == 1.toByte()
|
||||
}
|
||||
|
||||
val hasBrackets = run {
|
||||
var findLeftBracket = false
|
||||
var findRightBracket = false
|
||||
var left: PsiElement? = firstChild
|
||||
var right: PsiElement? = lastChild
|
||||
|
||||
while (left != right && (!findLeftBracket || !findRightBracket)) {
|
||||
val needBreak = left == null || left.nextSibling == right
|
||||
|
||||
@ -148,16 +112,15 @@ class DefaultRainbowVisitor : RainbowHighlightVisitor() {
|
||||
}
|
||||
|
||||
//For https://github.com/izhangzhihao/intellij-rainbow-brackets/issues/830
|
||||
if (settings.doNOTRainbowifyTemplateString && left?.prevSibling?.textMatches("$") == true) {
|
||||
false
|
||||
}
|
||||
else {
|
||||
findLeftBracket && findRightBracket
|
||||
}
|
||||
if (settings.doNOTRainbowifyTemplateString) {
|
||||
if (left?.prevSibling?.textMatches("$") == true) return false
|
||||
}
|
||||
|
||||
hasBracketsCache.put(cacheKey, if (hasBrackets) 1.toByte() else 0.toByte())
|
||||
return hasBrackets
|
||||
return findLeftBracket && findRightBracket
|
||||
}
|
||||
|
||||
private fun PsiElement.elementType(): IElementType? {
|
||||
return (this as? LeafPsiElement)?.elementType
|
||||
}
|
||||
|
||||
fun isValidBracket(element: LeafPsiElement, pair: BracePair): Boolean {
|
||||
@ -197,21 +160,24 @@ class DefaultRainbowVisitor : RainbowHighlightVisitor() {
|
||||
val pairs = element.language.bracePairs ?: return null
|
||||
val filterBraceType = pairs[type.toString()]
|
||||
return when {
|
||||
filterBraceType.isNullOrEmpty() -> null
|
||||
|
||||
filterBraceType.isNullOrEmpty() -> {
|
||||
null
|
||||
}
|
||||
// https://github.com/izhangzhihao/intellij-rainbow-brackets/issues/198
|
||||
element.javaClass.simpleName == "OCMacroForeignLeafElement" -> null
|
||||
element.javaClass.simpleName == "OCMacroForeignLeafElement" -> {
|
||||
null
|
||||
}
|
||||
|
||||
settings.isDoNOTRainbowifyBracketsWithoutContent -> filterBraceType
|
||||
settings.isDoNOTRainbowifyBracketsWithoutContent -> {
|
||||
filterBraceType
|
||||
.filterNot { it.leftBraceType == type && element.nextSibling?.elementType() == it.rightBraceType }
|
||||
.filterNot { it.rightBraceType == type && element.prevSibling?.elementType() == it.leftBraceType }
|
||||
|
||||
else -> filterBraceType
|
||||
}
|
||||
}
|
||||
|
||||
private fun PsiElement.elementType(): IElementType? {
|
||||
return (this as? LeafPsiElement)?.elementType
|
||||
else -> {
|
||||
filterBraceType
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -8,26 +8,16 @@
|
||||
<br><br>
|
||||
<b>Key Changes</b>
|
||||
<ul>
|
||||
<li>Support for C# (Rider)</li>
|
||||
<li>Support for C++ (Rider, CLion, CLion Nova)</li>
|
||||
<li>Support for CLion and Rider</li>
|
||||
<li>Support for Settings Sync</li>
|
||||
<li>Improved highlighting performance</li>
|
||||
<li>Increased default setting for maximum line count from 1K to 100K</li>
|
||||
<li>Fixed service initialization warnings reported by 2024.2+</li>
|
||||
</ul>
|
||||
]]></description>
|
||||
|
||||
<change-notes><![CDATA[
|
||||
<b>1.1.0</b>
|
||||
<ul>
|
||||
<li>Added support for C++ in Rider and CLion Nova</li>
|
||||
<li>Fixed broken option to not color parentheses without content in C#</li>
|
||||
<li>Improved highlighting performance</li>
|
||||
<li>Increased default setting for maximum line count from 1K to 100K</li>
|
||||
</ul>
|
||||
<b>1.0.0</b>
|
||||
<ul>
|
||||
<li>Restored support for CLion and Rider</li>
|
||||
<li>Added support for CLion and Rider</li>
|
||||
<li>Added support for Settings Sync</li>
|
||||
<li>Fixed service initialization warnings reported by IJ 2024.2+</li>
|
||||
</ul>
|
||||
|
Loading…
Reference in New Issue
Block a user