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

Support Code With Me client ()

* Using TextAttributesKey instead of TextAttributes

* Fix tests

* Update change log
This commit is contained in:
张志豪 2022-04-28 21:06:26 +08:00 committed by GitHub
parent 8a8716b172
commit eac6360f9a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 84 additions and 63 deletions

View File

@ -6,7 +6,7 @@ javaVersion=11
kotlinVersion=1.4.21
kotlinLanguageVersion=1.4
kotlinTargetVersion=1.4
version=6.21
version=6.22
publishChannels=Stable
kotlin.stdlib.default.dependency=false
pluginVerifierIdeVersions=WS-2020.3, IIC-2021.1, IIU-2021.2

View File

@ -19,6 +19,7 @@ import org.intellij.lang.annotations.Language
import org.jetbrains.annotations.TestOnly
import java.awt.Color
import java.awt.Font
import java.util.UUID
object RainbowHighlighter {
@ -100,7 +101,7 @@ object RainbowHighlighter {
fun isDarkEditor() = EditorColorsManager.getInstance().isDarkEditor
fun getRainbowColorByLevel(colorsScheme: TextAttributesScheme, rainbowName: String, level: Int): TextAttributes {
fun getRainbowColorByLevel(colorsScheme: TextAttributesScheme, rainbowName: String, level: Int): TextAttributesKey {
val ind = level % settings.numberOfColors
if (settings.useColorGenerator) {
return memGetRainbowColorByLevel(isDarkEditor(), rainbowName, ind)
@ -108,10 +109,10 @@ object RainbowHighlighter {
val key = getRainbowAttributesKeys(rainbowName).getOrNull(ind)
return try {
val result = colorsScheme.getAttributes(key)
if (result == null || result.foregroundColor == null) {
if (key == null || result == null || result.foregroundColor == null) {
memGetRainbowColorByLevel(isDarkEditor(), rainbowName, ind)
} else {
result
key
}
} catch (e: Exception) {
memGetRainbowColorByLevel(isDarkEditor(), rainbowName, ind)
@ -119,20 +120,21 @@ object RainbowHighlighter {
}
@Suppress("UNUSED_PARAMETER") // we use parameter as cache key
private fun generateColor(isDark: Boolean, rainbowName: String, level: Int): TextAttributes {
private fun generateColor(isDark: Boolean, rainbowName: String, level: Int): TextAttributesKey {
if (!settings.customColorGeneratorOption.isNullOrBlank()) {
return genByOption(settings.customColorGeneratorOption!!)
return genByOption(settings.customColorGeneratorOption!!, rainbowName, level)
}
if (isDark) {
@Language("JSON") val darkOption = """{"luminosity": "light"}"""
return genByOption(darkOption)
return genByOption(darkOption, rainbowName, level)
}
@Language("JSON") val lightOption = """{"luminosity": "dark"}"""
return genByOption(lightOption)
return genByOption(lightOption, rainbowName, level)
}
private fun genByOption(option: String) =
TextAttributes(randomColor(option), null, null, null, 0)
private fun genByOption(option: String, rainbowName: String, level: Int) =
com.github.izhangzhihao.rainbow.brackets.util.create("$rainbowName-$level",
TextAttributes(randomColor(option), null, null, null, 0))
val memGetRainbowColorByLevel = { isDark: Boolean, rainbowName: String, level: Int -> generateColor(isDark, rainbowName, level) }.memoize()
@ -141,12 +143,12 @@ object RainbowHighlighter {
@TestOnly
fun getRainbowColor(rainbowName: String, level: Int): Color? {
return getRainbowColorByLevel(EditorColorsManager.getInstance().globalScheme, rainbowName, level).foregroundColor
return getRainbowColorByLevel(EditorColorsManager.getInstance().globalScheme, rainbowName, level).defaultAttributes.foregroundColor
}
private fun getTextAttributes(colorsScheme: TextAttributesScheme,
element: PsiElement,
level: Int): TextAttributes? {
level: Int): TextAttributesKey? {
if (!settings.isRainbowEnabled) {
return null
}

View File

@ -67,7 +67,10 @@ class KotlinLabelAnnotator : Annotator {
.let {
holder.newSilentAnnotation(HighlightSeverity.INFORMATION)
.range(target)
.enforcedTextAttributes(TextAttributes(it, null, null, EffectType.BOXED, Font.PLAIN))
.textAttributes(com.github.izhangzhihao.rainbow.brackets.util.create(
"rainbow-kotlin-label",
TextAttributes(it, null, null, EffectType.BOXED, Font.PLAIN)
))
.create()
}
}

View File

@ -17,9 +17,14 @@ class KotlinLambdaExpressionArrowAnnotator : Annotator {
if ((element as? LeafPsiElement)?.elementType == KtTokens.ARROW) {
RainbowInfo.RAINBOW_INFO_KEY[element.parent]?.color?.let {
holder.newSilentAnnotation(HighlightSeverity.INFORMATION)
.range(element)
.enforcedTextAttributes(TextAttributes(it, null, null, EffectType.BOXED, Font.PLAIN))
.create()
.range(element)
.textAttributes(
com.github.izhangzhihao.rainbow.brackets.util.create(
"rainbow-kotlin-arrow",
TextAttributes(it, null, null, EffectType.BOXED, Font.PLAIN)
)
)
.create()
}
}
}

View File

@ -87,14 +87,14 @@ object RainbowUtils {
if (level >= 1) {
holder.newSilentAnnotation(HighlightSeverity.INFORMATION)
.range(element.psi)
.enforcedTextAttributes(getRainbowColorByLevel(scheme, rainbowName, level))
.textAttributes(getRainbowColorByLevel(scheme, rainbowName, level))
.create()
}
} else {
if (level >= 0) {
holder.newSilentAnnotation(HighlightSeverity.INFORMATION)
.range(element.psi)
.enforcedTextAttributes(getRainbowColorByLevel(scheme, rainbowName, level))
.textAttributes(getRainbowColorByLevel(scheme, rainbowName, level))
.create()
}
}

View File

@ -58,7 +58,7 @@ abstract class RainbowHighlightVisitor : HighlightVisitor {
holder.add(it)
if (startElement != null || endElement != null) {
val color: Color? = it.forcedTextAttributes.foregroundColor
val color: Color? = it.forcedTextAttributesKey?.defaultAttributes?.foregroundColor
color?.let {
parent?.saveRainbowInfo(level, color, startElement, endElement)
}

View File

@ -57,6 +57,12 @@
]]></description>
<change-notes><![CDATA[
<p>6.22</p>
<ul>
<li><a href="https://github.com/izhangzhihao/intellij-rainbow-brackets/issues/2408">#2408 Support Code With Me client(Doesn't even need to be installed on the client side)</a></li>
</ul>
<br/>
<p>6.21</p>
<ul>
<li>Handle exceptions in `RainbowHighlightVisitor.analyze()`</a></li>

View File

@ -23,7 +23,7 @@ void main() {
val doHighlighting = myFixture.doHighlighting()
assertFalse(doHighlighting.isEmpty())
doHighlighting
.map { it.forcedTextAttributes.foregroundColor }
.map { it.forcedTextAttributesKey.defaultAttributes.foregroundColor }
.toTypedArray()
.shouldBe(
arrayOf(

View File

@ -23,7 +23,7 @@ Map<String, Map<String, String>> convertObjectsToMapProperties(Map<String, Objec
val doHighlighting = myFixture.doHighlighting()
assertFalse(doHighlighting.isEmpty())
doHighlighting.filter { brackets.contains(it.text.toChar()) }
.map { it.forcedTextAttributes.foregroundColor }
.map { it.forcedTextAttributesKey.defaultAttributes.foregroundColor }
.toTypedArray()
.shouldBe(
arrayOf(

View File

@ -29,7 +29,7 @@ const moment = require('moment')
val doHighlighting = myFixture.doHighlighting()
assertFalse(doHighlighting.isEmpty())
doHighlighting.filter { brackets.contains(it.text.toChar()) }
.map { it.forcedTextAttributes.foregroundColor }
.map { it.forcedTextAttributesKey.defaultAttributes.foregroundColor }
.toTypedArray()
.shouldBe(
arrayOf(
@ -52,7 +52,7 @@ console.log(a == b)
val doHighlighting = myFixture.doHighlighting()
assertFalse(doHighlighting.isEmpty())
doHighlighting.filter { brackets.contains(it.text.toChar()) }
.map { it.forcedTextAttributes.foregroundColor }
.map { it.forcedTextAttributesKey.defaultAttributes.foregroundColor }
.toTypedArray()
.shouldBe(
arrayOf(
@ -73,7 +73,7 @@ console.log(a == b)
val doHighlighting = myFixture.doHighlighting()
assertFalse(doHighlighting.isEmpty())
doHighlighting.filter { brackets.contains(it.text.toChar()) }
.map { it.forcedTextAttributes.foregroundColor }
.map { it.forcedTextAttributesKey.defaultAttributes.foregroundColor }
.toTypedArray()
.shouldBe(
arrayOf(
@ -107,7 +107,7 @@ if ((a.field_detail && a.is) ||
val doHighlighting = myFixture.doHighlighting()
assertFalse(doHighlighting.isEmpty())
doHighlighting.filter { brackets.contains(it.text.toChar()) }
.map { it.forcedTextAttributes.foregroundColor }
.map { it.forcedTextAttributesKey.defaultAttributes.foregroundColor }
.toTypedArray()
.shouldBe(
arrayOf(
@ -141,7 +141,7 @@ const element = ( <div> <h1>Hello, world!</h1> </div> );
val doHighlighting = myFixture.doHighlighting()
assertFalse(doHighlighting.isEmpty())
doHighlighting.filter { brackets.contains(it.text.toChar()) }
.map { it.forcedTextAttributes.foregroundColor }
.map { it.forcedTextAttributesKey.defaultAttributes.foregroundColor }
.filterNot { it == null }
.toTypedArray()
.shouldBe(
@ -172,7 +172,7 @@ const element = ( <div> <h1>Hello, world!</h1> </div> );
val doHighlighting = myFixture.doHighlighting()
assertFalse(doHighlighting.isEmpty())
doHighlighting.filter { brackets.contains(it.text.toChar()) }
.map { it.forcedTextAttributes.foregroundColor }
.map { it.forcedTextAttributesKey.defaultAttributes.foregroundColor }
.filterNot { it == null }
.toTypedArray()
.shouldBe(
@ -206,7 +206,7 @@ const element = ( <div> <h1>Hello, world!</h1> </div> );
val doHighlighting = myFixture.doHighlighting()
assertFalse(doHighlighting.isEmpty())
doHighlighting.filter { brackets.contains(it.text.toChar()) }
.map { it.forcedTextAttributes.foregroundColor }
.map { it.forcedTextAttributesKey.defaultAttributes.foregroundColor }
.filterNot { it == null }
.toTypedArray()
.shouldBe(
@ -231,7 +231,7 @@ const element = ( <div> <h1>Hello, world!</h1> </div> );
val doHighlighting = myFixture.doHighlighting()
assertFalse(doHighlighting.isEmpty())
doHighlighting.filter { brackets.contains(it.text.toChar()) }
.map { it.forcedTextAttributes.foregroundColor }
.map { it.forcedTextAttributesKey.defaultAttributes.foregroundColor }
.filterNot { it == null }
.toTypedArray()
.shouldBe(

View File

@ -36,7 +36,7 @@ public class Test<T> {
val doHighlighting = myFixture.doHighlighting()
assertFalse(doHighlighting.isEmpty())
doHighlighting.filter { brackets.contains(it.text.toChar()) }
.map { it.forcedTextAttributes.foregroundColor }
.map { it.forcedTextAttributesKey.defaultAttributes.foregroundColor }
.toTypedArray()
.shouldBe(
arrayOf(
@ -76,7 +76,7 @@ public class Test<T> {
val doHighlighting = myFixture.doHighlighting()
assertFalse(doHighlighting.isEmpty())
doHighlighting.filter { brackets.contains(it.text.toChar()) }
.map { it.forcedTextAttributes.foregroundColor }
.map { it.forcedTextAttributesKey.defaultAttributes.foregroundColor }
.toTypedArray()
.shouldBe(
arrayOf()
@ -99,7 +99,7 @@ public class Test<T> {
val doHighlighting = myFixture.doHighlighting()
assertFalse(doHighlighting.isEmpty())
doHighlighting.filter { brackets.contains(it.text.toChar()) }
.map { it.forcedTextAttributes.foregroundColor }
.map { it.forcedTextAttributesKey.defaultAttributes.foregroundColor }
.toTypedArray()
.shouldBe(
arrayOf(
@ -137,7 +137,7 @@ public class Test<T> {
val doHighlighting = myFixture.doHighlighting()
assertFalse(doHighlighting.isEmpty())
doHighlighting.filter { brackets.contains(it.text.toChar()) }
.map { it.forcedTextAttributes.foregroundColor }
.map { it.forcedTextAttributesKey.defaultAttributes.foregroundColor }
.toTypedArray()
.shouldBe(
arrayOf(
@ -167,7 +167,7 @@ public class Test<T> {
val doHighlighting = myFixture.doHighlighting()
assertFalse(doHighlighting.isEmpty())
doHighlighting.filter { brackets.contains(it.text.toChar()) }
.map { it.forcedTextAttributes.foregroundColor }
.map { it.forcedTextAttributesKey.defaultAttributes.foregroundColor }
.toTypedArray()
.shouldBe(
arrayOf(
@ -203,7 +203,7 @@ public class Test<T> {
val doHighlighting = myFixture.doHighlighting()
assertFalse(doHighlighting.isEmpty())
doHighlighting.filter { brackets.contains(it.text.toChar()) }
.map { it.forcedTextAttributes.foregroundColor }
.map { it.forcedTextAttributesKey.defaultAttributes.foregroundColor }
.toTypedArray()
.shouldBe(
arrayOf(
@ -240,7 +240,7 @@ public class Test<T> {
val doHighlighting = myFixture.doHighlighting()
assertFalse(doHighlighting.isEmpty())
doHighlighting.filter { brackets.contains(it.text.toChar()) }
.map { it.forcedTextAttributes.foregroundColor }
.map { it.forcedTextAttributesKey.defaultAttributes.foregroundColor }
.toTypedArray()
.size
.shouldBe(0)
@ -263,7 +263,7 @@ public class Test {
val doHighlighting = myFixture.doHighlighting()
assertFalse(doHighlighting.isEmpty())
doHighlighting.filter { brackets.contains(it.text.toChar()) }
.map { it.forcedTextAttributes.foregroundColor }
.map { it.forcedTextAttributesKey.defaultAttributes.foregroundColor }
.toTypedArray()
.shouldBe(
arrayOf(

View File

@ -21,7 +21,7 @@ fun <T> filter(l: List<T>, f: (T) -> Boolean): MutableList<T> {
val doHighlighting = myFixture.doHighlighting()
assertFalse(doHighlighting.isEmpty())
doHighlighting.filter { brackets.contains(it.text.toChar()) }
.map { it.forcedTextAttributes.foregroundColor }
.map { it.forcedTextAttributesKey.defaultAttributes.foregroundColor }
.toTypedArray()
.shouldBe(
arrayOf(
@ -81,8 +81,9 @@ val a: (Int) -> Unit = { aa ->
val doHighlighting = myFixture.doHighlighting()
assertFalse(doHighlighting.isEmpty())
doHighlighting
.filter { it.forcedTextAttributes != null }
.map { it.forcedTextAttributes.foregroundColor }
.filter { brackets.contains(it.text.toChar()) || it.text.contains("->") }
.filter { it?.forcedTextAttributesKey?.defaultAttributes != null }
.map { it.forcedTextAttributesKey.defaultAttributes.foregroundColor }
.toTypedArray()
.shouldBe(
arrayOf(
@ -147,7 +148,7 @@ class AA {
doHighlighting
.filter { it.forcedTextAttributes != null && it.text.contains("@") }
.map { it.forcedTextAttributes.foregroundColor }
.map { it.forcedTextAttributesKey.defaultAttributes.foregroundColor }
.toTypedArray()
.shouldBe(
arrayOf(
@ -175,8 +176,9 @@ fun t() {
assertFalse(doHighlighting.isEmpty())
doHighlighting
.filter { it.forcedTextAttributes != null }
.map { it.forcedTextAttributes.foregroundColor }
.filter { brackets.contains(it.text.toChar()) }
.filter { it?.forcedTextAttributesKey?.defaultAttributes != null }
.map { it.forcedTextAttributesKey.defaultAttributes.foregroundColor }
.toTypedArray()
.shouldBe(
arrayOf(

View File

@ -28,7 +28,7 @@ function padZero(string data): string
val doHighlighting = myFixture.doHighlighting()
assertFalse(doHighlighting.isEmpty())
doHighlighting.filter { brackets.contains(it.text.toChar()) }
.map { it.forcedTextAttributes.foregroundColor }
.map { it.forcedTextAttributesKey.defaultAttributes.foregroundColor }
.toTypedArray()
.shouldBe(
arrayOf(

View File

@ -26,7 +26,7 @@ end
val doHighlighting = myFixture.doHighlighting()
assertFalse(doHighlighting.isEmpty())
doHighlighting.filter { brackets.contains(it.text.toChar()) }
.map { it.forcedTextAttributes.foregroundColor }
.map { it.forcedTextAttributesKey.defaultAttributes.foregroundColor }
.toTypedArray()
.shouldBe(
arrayOf(
@ -48,7 +48,7 @@ foobar(p1: "", p2: false, p3: 1)
val doHighlighting = myFixture.doHighlighting()
assertFalse(doHighlighting.isEmpty())
doHighlighting.filter { brackets.contains(it.text.toChar()) }
.map { it.forcedTextAttributes.foregroundColor }
.map { it.forcedTextAttributesKey.defaultAttributes.foregroundColor }
.toTypedArray()
.shouldBe(
arrayOf(
@ -72,9 +72,10 @@ end
PsiDocumentManager.getInstance(project).commitAllDocuments()
val doHighlighting = myFixture.doHighlighting()
assertFalse(doHighlighting.isEmpty())
doHighlighting//.filter { brackets.contains(it.text.toChar()) }
.filterNot { it.forcedTextAttributes == null }
.map { it.forcedTextAttributes.foregroundColor }
doHighlighting
.filter { brackets.contains(it.text.toChar()) }
.filterNot { it?.forcedTextAttributesKey?.defaultAttributes == null }
.map { it.forcedTextAttributesKey.defaultAttributes.foregroundColor }
.toTypedArray()
.shouldBe(
arrayOf(
@ -109,9 +110,10 @@ end
PsiDocumentManager.getInstance(project).commitAllDocuments()
val doHighlighting = myFixture.doHighlighting()
assertFalse(doHighlighting.isEmpty())
doHighlighting//.filter { brackets.contains(it.text.toChar()) }
.filterNot { it.forcedTextAttributes == null }
.map { it.forcedTextAttributes.foregroundColor }
doHighlighting
.filter { brackets.contains(it.text.toChar()) }
.filterNot { it?.forcedTextAttributesKey?.defaultAttributes == null }
.map { it.forcedTextAttributesKey.defaultAttributes.foregroundColor }
.toTypedArray()
.shouldBe(
arrayOf(
@ -134,9 +136,10 @@ end
PsiDocumentManager.getInstance(project).commitAllDocuments()
val doHighlighting = myFixture.doHighlighting()
assertFalse(doHighlighting.isEmpty())
doHighlighting//.filter { brackets.contains(it.text.toChar()) }
.filterNot { it.forcedTextAttributes == null }
.map { it.forcedTextAttributes.foregroundColor }
doHighlighting
.filter { brackets.contains(it.text.toChar()) }
.filterNot { it?.forcedTextAttributesKey?.defaultAttributes == null }
.map { it.forcedTextAttributesKey.defaultAttributes.foregroundColor }
.toTypedArray()
.shouldBe(
arrayOf(

View File

@ -37,8 +37,8 @@ import scala.annotation.tailrec
val doHighlighting = myFixture.doHighlighting()
assertFalse(doHighlighting.isEmpty())
doHighlighting.filter { brackets.contains(it.text.toChar()) }
.filter { it?.forcedTextAttributes != null }
.map { it.forcedTextAttributes.foregroundColor }
.filter { it?.forcedTextAttributesKey != null }
.map { it.forcedTextAttributesKey.defaultAttributes.foregroundColor }
.toTypedArray()
.shouldBe(
arrayOf(
@ -79,8 +79,8 @@ import scala.annotation.tailrec
val doHighlighting = myFixture.doHighlighting()
assertFalse(doHighlighting.isEmpty())
doHighlighting.filter { brackets.contains(it.text.toChar()) }
.filter { it?.forcedTextAttributes != null }
.map { it.forcedTextAttributes.foregroundColor }
.filter { it?.forcedTextAttributesKey != null }
.map { it.forcedTextAttributesKey.defaultAttributes.foregroundColor }
.toTypedArray()
.shouldBe(
arrayOf(

View File

@ -29,7 +29,7 @@ class RainbowXMLTest : LightJavaCodeInsightFixtureTestCase() {
val doHighlighting = myFixture.doHighlighting()
assertFalse(doHighlighting.isEmpty())
doHighlighting
.map { it.forcedTextAttributes.foregroundColor }
.map { it.forcedTextAttributesKey.defaultAttributes.foregroundColor }
.toTypedArray()
.shouldBe(
arrayOf(
@ -104,7 +104,7 @@ class RainbowXMLTest : LightJavaCodeInsightFixtureTestCase() {
val doHighlighting = myFixture.doHighlighting()
assertFalse(doHighlighting.isEmpty())
doHighlighting
.map { it.forcedTextAttributes.foregroundColor }
.map { it.forcedTextAttributesKey.defaultAttributes.foregroundColor }
.toTypedArray()
.shouldBe(
arrayOf(

View File

@ -26,8 +26,8 @@ public class Test<T> {
val doHighlighting = myFixture.doHighlighting()
assertFalse(doHighlighting.isEmpty())
val highlightSize = doHighlighting.filter { brackets.contains(it.text.toChar()) }
.filter { it.forcedTextAttributes.foregroundColor != null }
.map { it.forcedTextAttributes.foregroundColor }
.filter { it.forcedTextAttributesKey.defaultAttributes.foregroundColor != null }
.map { it.forcedTextAttributesKey.defaultAttributes.foregroundColor }
.toTypedArray()
.size
assert(highlightSize == 16)