1
0
mirror of https://github.com/chylex/IntelliJ-Rainbow-Brackets.git synced 2026-06-14 07:02:29 +02:00

Compare commits

7 Commits

94 changed files with 878 additions and 1037 deletions

1
.gitignore vendored
View File

@@ -2,5 +2,6 @@
!/.idea/runConfigurations
/.gradle/
/.kotlin/
/.intellijPlatform/
/build/

View File

@@ -17,8 +17,11 @@
</ExternalSystemSettings>
<ExternalSystemDebugServerProcess>true</ExternalSystemDebugServerProcess>
<ExternalSystemReattachDebugProcess>true</ExternalSystemReattachDebugProcess>
<ExternalSystemDebugDisabled>false</ExternalSystemDebugDisabled>
<DebugAllEnabled>false</DebugAllEnabled>
<RunAsTest>false</RunAsTest>
<GradleProfilingDisabled>false</GradleProfilingDisabled>
<GradleCoverageDisabled>false</GradleCoverageDisabled>
<method v="2" />
</configuration>
</component>
</component>

View File

@@ -10,15 +10,18 @@
</option>
<option name="taskNames">
<list>
<option value=":runIde" />
<option value=":base:runIde" />
</list>
</option>
<option name="vmOptions" />
</ExternalSystemSettings>
<ExternalSystemDebugServerProcess>true</ExternalSystemDebugServerProcess>
<ExternalSystemReattachDebugProcess>true</ExternalSystemReattachDebugProcess>
<ExternalSystemDebugDisabled>false</ExternalSystemDebugDisabled>
<DebugAllEnabled>false</DebugAllEnabled>
<RunAsTest>false</RunAsTest>
<GradleProfilingDisabled>false</GradleProfilingDisabled>
<GradleCoverageDisabled>false</GradleCoverageDisabled>
<method v="2" />
</configuration>
</component>

View File

@@ -17,8 +17,11 @@
</ExternalSystemSettings>
<ExternalSystemDebugServerProcess>true</ExternalSystemDebugServerProcess>
<ExternalSystemReattachDebugProcess>true</ExternalSystemReattachDebugProcess>
<ExternalSystemDebugDisabled>false</ExternalSystemDebugDisabled>
<DebugAllEnabled>false</DebugAllEnabled>
<RunAsTest>false</RunAsTest>
<GradleProfilingDisabled>false</GradleProfilingDisabled>
<GradleCoverageDisabled>false</GradleCoverageDisabled>
<method v="2" />
</configuration>
</component>
</component>

View File

@@ -1,8 +0,0 @@
val ideaVersion: String by project
dependencies {
intellijPlatform {
@Suppress("DEPRECATION")
intellijIdeaUltimate(ideaVersion)
}
}

45
base/build.gradle.kts Normal file
View File

@@ -0,0 +1,45 @@
import org.jetbrains.intellij.platform.gradle.TestFrameworkType
import org.jetbrains.intellij.platform.gradle.extensions.excludeCoroutines
import org.jetbrains.intellij.platform.gradle.extensions.excludeKotlinStdlib
val ideaVersion: String by project
dependencies {
intellijPlatform {
@Suppress("DEPRECATION")
intellijIdeaUltimate(ideaVersion)
bundledPlugin("JavaScript")
bundledPlugin("com.intellij.css")
bundledPlugin("com.intellij.database")
bundledPlugin("com.intellij.java")
bundledPlugin("org.intellij.groovy")
bundledPlugin("org.intellij.plugins.markdown")
bundledPlugin("org.jetbrains.kotlin")
bundledPlugin("org.jetbrains.plugins.yaml")
compatiblePlugin("PythonCore")
compatiblePlugin("com.jetbrains.php")
compatiblePlugin("com.jetbrains.plugins.jade")
compatiblePlugin("com.jetbrains.sh")
compatiblePlugin("org.intellij.scala")
compatiblePlugin("org.jetbrains.plugins.go-template")
compatiblePlugin("org.jetbrains.plugins.ruby")
plugin("Dart:504.0.0") // https://plugins.jetbrains.com/plugin/6351-dart/versions/stable
testFramework(TestFrameworkType.Platform)
testFramework(TestFrameworkType.Plugin.Java)
testFramework(TestFrameworkType.Plugin.JavaScript)
}
testImplementation("junit:junit:4.13.2")
testImplementation("io.kotest:kotest-assertions-core:5.8.0") {
excludeKotlinStdlib()
excludeCoroutines()
}
}
intellijPlatform {
buildSearchableOptions = true
}

View File

@@ -1,6 +1,7 @@
package com.chylex.intellij.coloredbrackets
import com.chylex.intellij.coloredbrackets.settings.RainbowSettings
import com.chylex.intellij.coloredbrackets.util.alphaBlend
import com.chylex.intellij.coloredbrackets.util.create
import com.chylex.intellij.coloredbrackets.util.memoize
import com.intellij.codeInsight.daemon.impl.HighlightInfo
@@ -56,6 +57,9 @@ object RainbowHighlighter {
createRainbowAttributesKeys(KEY_ANGLE_BRACKETS, settings.numberOfColors)
}
private val SCOPE_HIGHLIGHTING_KEY = TextAttributesKey.createTempTextAttributesKey("ColoredBrackets:ScopeHighlighting", TextAttributes.ERASE_MARKER)
private val SCOPE_OUTSIDE_HIGHLIGHTING_KEY = TextAttributesKey.createTempTextAttributesKey("ColoredBrackets:ScopeOutsideHighlighting", TextAttributes.ERASE_MARKER)
private val rainbowElement: HighlightInfoType = HighlightInfoType
.HighlightInfoTypeImpl(HighlightSeverity.INFORMATION, DefaultLanguageHighlighterColors.CONSTANT)
@@ -226,4 +230,23 @@ object RainbowHighlighter {
private fun EditorColorsScheme.setInherited(key: TextAttributesKey, inherited: Boolean) {
setAttributes(key, if (inherited) AbstractColorsScheme.INHERITED_ATTRS_MARKER else TextAttributes())
}
fun updateScopeHighlightingAttributes(scheme: EditorColorsScheme, rainbowInfo: RainbowInfo): TextAttributesKey {
val defaultBackground = EditorColorsManager.getInstance().globalScheme.defaultBackground
val background = rainbowInfo.color.alphaBlend(defaultBackground, 0.2f)
val attributes = TextAttributes(null, background, rainbowInfo.color, EffectType.BOXED, Font.PLAIN)
scheme.setAttributes(SCOPE_HIGHLIGHTING_KEY, attributes)
return SCOPE_HIGHLIGHTING_KEY
}
fun updateScopeOutsideHighlightingAttributes(scheme: EditorColorsScheme): TextAttributesKey {
val defaultBackground = scheme.defaultBackground
val background = Color.GRAY.alphaBlend(defaultBackground, 0.05f)
val foreground = Color.GRAY.alphaBlend(defaultBackground, 0.55f)
val attributes = TextAttributes(foreground, background, background, EffectType.BOXED, Font.PLAIN)
scheme.setAttributes(SCOPE_OUTSIDE_HIGHLIGHTING_KEY, attributes)
return SCOPE_OUTSIDE_HIGHLIGHTING_KEY
}
}

View File

@@ -35,7 +35,7 @@ abstract class AbstractScopeHighlightingAction : AnAction() {
val offset = editor.caretModel.offset
val rainbowInfo = psiFile.findRainbowInfoAt(offset) ?: return
val highlightManager = HighlightManager.getInstance(project)
val highlighters = editor.addHighlighter(highlightManager, rainbowInfo)
val highlighters = editor.addHighlighter(editor, highlightManager, rainbowInfo)
editor.highlightingDisposer?.dispose()
if (highlighters.isNotEmpty()) {
@@ -47,6 +47,7 @@ abstract class AbstractScopeHighlightingAction : AnAction() {
}
protected abstract fun Editor.addHighlighter(
editor: Editor,
highlightManager: HighlightManager,
rainbowInfo: RainbowInfo,
): Collection<RangeHighlighter>

View File

@@ -1,38 +1,33 @@
package com.chylex.intellij.coloredbrackets.action
import com.chylex.intellij.coloredbrackets.RainbowHighlighter
import com.chylex.intellij.coloredbrackets.RainbowInfo
import com.chylex.intellij.coloredbrackets.settings.RainbowSettings
import com.chylex.intellij.coloredbrackets.util.alphaBlend
import com.intellij.codeInsight.highlighting.HighlightManager
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.editor.colors.EditorColorsManager
import com.intellij.openapi.editor.markup.EffectType
import com.intellij.openapi.editor.markup.RangeHighlighter
import com.intellij.openapi.editor.markup.TextAttributes
import java.awt.Font
import java.util.LinkedList
class ScopeHighlightingAction : AbstractScopeHighlightingAction() {
override fun Editor.addHighlighter(
editor: Editor,
highlightManager: HighlightManager,
rainbowInfo: RainbowInfo,
): Collection<RangeHighlighter> {
val defaultBackground = EditorColorsManager.getInstance().globalScheme.defaultBackground
val background = rainbowInfo.color.alphaBlend(defaultBackground, 0.2f)
val attributes = TextAttributes(null, background, rainbowInfo.color, EffectType.BOXED, Font.PLAIN)
val attributesKey = RainbowHighlighter.updateScopeHighlightingAttributes(editor.colorsScheme, rainbowInfo)
val highlighters = LinkedList<RangeHighlighter>()
highlightManager.addRangeHighlight(
this,
rainbowInfo.startOffset,
rainbowInfo.endOffset,
attributes, //create("ScopeHighlightingAction", attributes),
false, //hideByTextChange
RainbowSettings.instance.pressAnyKeyToRemoveTheHighlightingEffects, //hideByAnyKey
attributesKey,
false,
RainbowSettings.instance.pressAnyKeyToRemoveTheHighlightingEffects,
highlighters
)
return highlighters
}
}

View File

@@ -1,28 +1,21 @@
package com.chylex.intellij.coloredbrackets.action
import com.chylex.intellij.coloredbrackets.RainbowHighlighter
import com.chylex.intellij.coloredbrackets.RainbowInfo
import com.chylex.intellij.coloredbrackets.settings.RainbowSettings
import com.chylex.intellij.coloredbrackets.util.alphaBlend
import com.intellij.codeInsight.highlighting.HighlightManager
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.editor.colors.EditorColorsManager
import com.intellij.openapi.editor.markup.EffectType
import com.intellij.openapi.editor.markup.RangeHighlighter
import com.intellij.openapi.editor.markup.TextAttributes
import java.awt.Color
import java.awt.Font
import java.util.LinkedList
class ScopeOutsideHighlightingRestrainAction : AbstractScopeHighlightingAction() {
override fun Editor.addHighlighter(
editor: Editor,
highlightManager: HighlightManager,
rainbowInfo: RainbowInfo,
): Collection<RangeHighlighter> {
val defaultBackground = EditorColorsManager.getInstance().globalScheme.defaultBackground
val background = Color.GRAY.alphaBlend(defaultBackground, 0.05f)
val foreground = Color.GRAY.alphaBlend(defaultBackground, 0.55f)
val attributes = TextAttributes(foreground, background, background, EffectType.BOXED, Font.PLAIN)
val attributesKey = RainbowHighlighter.updateScopeOutsideHighlightingAttributes(editor.colorsScheme)
val highlighters = LinkedList<RangeHighlighter>()
val startOffset = rainbowInfo.startOffset
@@ -33,9 +26,9 @@ class ScopeOutsideHighlightingRestrainAction : AbstractScopeHighlightingAction()
this,
0,
startOffset,
attributes, //create("ScopeOutsideHighlightingRestrainAction", attributes),
false, //hideByTextChange
hideByAnyKey, //hideByAnyKey
attributesKey,
false,
hideByAnyKey,
highlighters
)
}
@@ -47,14 +40,13 @@ class ScopeOutsideHighlightingRestrainAction : AbstractScopeHighlightingAction()
this,
endOffset,
lastOffset,
attributes, //create("ScopeOutsideHighlightingRestrainAction", attributes),
false, //hideByTextChange
hideByAnyKey, //hideByAnyKey
attributesKey,
false,
hideByAnyKey,
highlighters
)
}
return highlighters
}
}

View File

@@ -46,7 +46,7 @@ class RainbowIndentsPass internal constructor(
override fun doCollectInformation(progress: ProgressIndicator) {
val stamp = myEditor.getUserData(LAST_TIME_INDENTS_BUILT)
if (stamp != null && stamp.toLong() == nowStamp()) return
if (stamp != null && stamp == nowStamp()) return
myDescriptors = buildDescriptors()

View File

@@ -49,7 +49,7 @@ class RainbowConfigurable : SearchableConfigurable {
settings.rainbowifyPythonKeywords = settingsForm?.rainbowifyPythonKeywords() ?: false
ProjectManager.getInstanceIfCreated()?.openProjects?.forEach {
DaemonCodeAnalyzer.getInstance(it).restart()
DaemonCodeAnalyzer.getInstance(it).restart(this)
}
}

View File

@@ -6,9 +6,7 @@ import com.chylex.intellij.coloredbrackets.settings.RainbowSettings
import com.chylex.intellij.coloredbrackets.util.memoizedFileExtension
import com.intellij.codeInsight.daemon.impl.HighlightVisitor
import com.intellij.codeInsight.daemon.impl.analysis.HighlightInfoHolder
import com.intellij.ide.plugins.PluginManagerCore
import com.intellij.openapi.editor.colors.EditorColorsManager
import com.intellij.openapi.extensions.PluginId
import com.intellij.openapi.util.TextRange
import com.intellij.openapi.util.text.StringUtil
import com.intellij.psi.PsiDocumentManager
@@ -26,8 +24,7 @@ abstract class RainbowHighlightVisitor : HighlightVisitor {
return settings.isRainbowEnabled &&
checkForBigFile(file) &&
!settings.languageBlacklist.contains(file.fileType.name) &&
!settings.languageBlacklist.contains(memoizedFileExtension(file.name)) &&
fileIsNotHaskellOrIntelliJHaskellPluginNotEnabled(file.fileType.name)
!settings.languageBlacklist.contains(memoizedFileExtension(file.name))
}
final override fun analyze(file: PsiFile, updateWholeFile: Boolean, holder: HighlightInfoHolder, action: Runnable): Boolean {
@@ -84,19 +81,11 @@ abstract class RainbowHighlightVisitor : HighlightVisitor {
}
companion object {
private val isIntelliJHaskellEnabled: Boolean by lazy {
PluginManagerCore.getPlugin(
PluginId.getId("intellij.haskell")
)?.isEnabled ?: false
}
fun checkForBigFile(file: PsiFile): Boolean =
!(RainbowSettings.instance.doNOTRainbowifyBigFiles &&
file.getLineCount() > RainbowSettings.instance.bigFilesLinesThreshold)
private fun fileIsNotHaskellOrIntelliJHaskellPluginNotEnabled(fileType: String) =
fileType != "Haskell" || !isIntelliJHaskellEnabled
private fun PsiElement.getLineCount(): Int {
try {
val doc = containingFile?.let { PsiDocumentManager.getInstance(project).getDocument(it) }

View File

@@ -1,12 +1,12 @@
<idea-plugin>
<extensions defaultExtensionNs="com.chylex.coloredbrackets">
<bracePairProvider language="kotlin"
implementationClass="com.chylex.intellij.coloredbrackets.provider.KotlinBracePairProvider" />
</extensions>
<extensions defaultExtensionNs="com.intellij">
<annotator language="kotlin"
implementationClass="com.chylex.intellij.coloredbrackets.annotator.KotlinLambdaExpressionArrowAnnotator" />
<annotator language="kotlin"
implementationClass="com.chylex.intellij.coloredbrackets.annotator.KotlinLabelAnnotator" />
</extensions>
<extensions defaultExtensionNs="com.chylex.coloredbrackets">
<bracePairProvider language="kotlin"
implementationClass="com.chylex.intellij.coloredbrackets.provider.KotlinBracePairProvider" />
</extensions>
</idea-plugin>

View File

@@ -43,26 +43,23 @@
]]></change-notes>
<depends>com.intellij.modules.lang</depends>
<depends optional="true" config-file="kotlin-brackets.xml">org.jetbrains.kotlin</depends>
<depends optional="true" config-file="JSX.xml">JavaScript</depends>
<depends optional="true" config-file="dart-brackets.xml">Dart</depends>
<depends optional="true" config-file="groovy-brackets.xml">org.intellij.groovy</depends>
<depends optional="true" config-file="cpp-nova-brackets.xml">org.jetbrains.plugins.clion.radler</depends>
<depends optional="true" config-file="cpp-rider-brackets.xml">com.intellij.modules.rider</depends>
<depends optional="true" config-file="csharp-brackets.xml">com.intellij.modules.rider</depends>
<depends optional="true" config-file="intellij-haskell-annotator.xml">intellij.haskell</depends>
<depends optional="true" config-file="sql-brackets.xml">com.intellij.database</depends>
<depends optional="true" config-file="oc-brackets.xml">com.intellij.modules.clion</depends>
<depends optional="true" config-file="sh-brackets.xml">com.jetbrains.sh</depends>
<depends optional="true" config-file="php-brackets.xml">com.jetbrains.php</depends>
<depends optional="true" config-file="go-template-brackets.xml">org.jetbrains.plugins.go-template</depends>
<depends optional="true" config-file="jade-rainbow-visitor.xml">com.jetbrains.plugins.jade</depends>
<depends optional="true" config-file="python-brackets.xml">com.intellij.modules.python</depends>
<depends optional="true" config-file="plugin-clion-nova.xml">org.jetbrains.plugins.clion.radler</depends>
<depends optional="true" config-file="plugin-clion.xml">com.intellij.modules.clion</depends>
<depends optional="true" config-file="plugin-dart.xml">Dart</depends>
<depends optional="true" config-file="plugin-go-template.xml">org.jetbrains.plugins.go-template</depends>
<depends optional="true" config-file="plugin-groovy.xml">org.intellij.groovy</depends>
<depends optional="true" config-file="plugin-jade.xml">com.jetbrains.plugins.jade</depends>
<depends optional="true" config-file="plugin-javascript.xml">JavaScript</depends>
<depends optional="true" config-file="plugin-kotlin.xml">org.jetbrains.kotlin</depends>
<depends optional="true" config-file="plugin-php.xml">com.jetbrains.php</depends>
<depends optional="true" config-file="plugin-python.xml">com.intellij.modules.python</depends>
<depends optional="true" config-file="plugin-rider.xml">com.intellij.modules.rider</depends>
<depends optional="true" config-file="plugin-sh.xml">com.jetbrains.sh</depends>
<depends optional="true" config-file="plugin-sql.xml">com.intellij.database</depends>
<extensionPoints>
<extensionPoint name="bracePairProvider" beanClass="com.intellij.lang.LanguageExtensionPoint" dynamic="true">
<with attribute="implementationClass"
implements="com.chylex.intellij.coloredbrackets.provider.BracePairProvider" />
<with attribute="implementationClass" implements="com.chylex.intellij.coloredbrackets.provider.BracePairProvider" />
</extensionPoint>
</extensionPoints>
@@ -71,12 +68,9 @@
<highlightVisitor implementation="com.chylex.intellij.coloredbrackets.visitor.XmlRainbowVisitor" />
<applicationConfigurable instance="com.chylex.intellij.coloredbrackets.settings.RainbowConfigurable" displayName="Colored Brackets" parentId="appearance" />
<applicationService
serviceImplementation="com.chylex.intellij.coloredbrackets.settings.RainbowSettings" />
<colorAndFontPanelFactory
implementation="com.chylex.intellij.coloredbrackets.settings.RainbowColorsPageFactory" />
<colorAndFontDescriptorProvider
implementation="com.chylex.intellij.coloredbrackets.settings.RainbowColorsPageFactory" />
<applicationService serviceImplementation="com.chylex.intellij.coloredbrackets.settings.RainbowSettings" />
<colorAndFontPanelFactory implementation="com.chylex.intellij.coloredbrackets.settings.RainbowColorsPageFactory" />
<colorAndFontDescriptorProvider implementation="com.chylex.intellij.coloredbrackets.settings.RainbowColorsPageFactory" />
<additionalTextAttributes scheme="Default" file="colorSchemes/rainbow-color-default.xml" />
<additionalTextAttributes scheme="Darcula" file="colorSchemes/rainbow-color-default-darcula.xml" />

View File

@@ -22,32 +22,29 @@ void main() {
PsiDocumentManager.getInstance(project).commitAllDocuments()
val doHighlighting = myFixture.doHighlighting()
assertFalse(doHighlighting.isEmpty())
doHighlighting
.map { it.forcedTextAttributesKey.defaultAttributes.foregroundColor }
.toTypedArray()
.shouldBe(
arrayOf(
roundLevel(0),
angleLevel(0),
angleLevel(0),
roundLevel(0),
roundLevel(0),
roundLevel(0),
roundLevel(0),
roundLevel(0),
squigglyLevel(0),
angleLevel(0),
angleLevel(0),
squareLevel(0),
squareLevel(0),
roundLevel(0),
roundLevel(0),
roundLevel(0),
roundLevel(0),
roundLevel(0),
roundLevel(0),
squigglyLevel(0)
)
doHighlighting.getBrackets().shouldBe(
arrayOf(
roundLevel(0),
angleLevel(0),
angleLevel(0),
roundLevel(0),
roundLevel(0),
roundLevel(0),
roundLevel(0),
roundLevel(0),
squigglyLevel(0),
angleLevel(0),
angleLevel(0),
squareLevel(0),
squareLevel(0),
roundLevel(0),
roundLevel(0),
roundLevel(0),
roundLevel(0),
roundLevel(0),
roundLevel(0),
squigglyLevel(0)
)
)
}
}

View File

@@ -22,39 +22,36 @@ Map<String, Map<String, String>> convertObjectsToMapProperties(Map<String, Objec
PsiDocumentManager.getInstance(project).commitAllDocuments()
val doHighlighting = myFixture.doHighlighting()
assertFalse(doHighlighting.isEmpty())
doHighlighting.filter { brackets.contains(it.text.toChar()) }
.map { it.forcedTextAttributesKey.defaultAttributes.foregroundColor }
.toTypedArray()
.shouldBe(
arrayOf(
angleLevel(0),
angleLevel(1),
angleLevel(1),
angleLevel(0),
roundLevel(0),
angleLevel(0),
angleLevel(0),
roundLevel(0),
squigglyLevel(0),
squigglyLevel(1),
angleLevel(0),
angleLevel(0),
squareLevel(0),
squareLevel(0),
squigglyLevel(1),
angleLevel(0),
angleLevel(1),
angleLevel(1),
angleLevel(0),
squigglyLevel(0)
)
doHighlighting.getBrackets().shouldBe(
arrayOf(
angleLevel(0),
angleLevel(1),
angleLevel(1),
angleLevel(0),
roundLevel(0),
angleLevel(0),
angleLevel(0),
roundLevel(0),
squigglyLevel(0),
squigglyLevel(1),
angleLevel(0),
angleLevel(0),
squareLevel(0),
squareLevel(0),
squigglyLevel(1),
angleLevel(0),
angleLevel(1),
angleLevel(1),
angleLevel(0),
squigglyLevel(0)
)
)
}
}

View File

@@ -0,0 +1,219 @@
package com.chylex.intellij.coloredbrackets
import com.intellij.ide.plugins.PluginManagerCore
import com.intellij.lang.javascript.JSXFileType
import com.intellij.lang.javascript.JavaScriptFileType
import com.intellij.lang.javascript.TypeScriptFileType
import com.intellij.openapi.extensions.PluginId
import com.intellij.psi.PsiDocumentManager
import com.intellij.testFramework.fixtures.LightJavaCodeInsightFixtureTestCase
import io.kotest.matchers.shouldBe
import org.intellij.lang.annotations.Language
class RainbowJavaScriptTest : LightJavaCodeInsightFixtureTestCase() {
fun testJavaScriptPluginEnabled() {
assertTrue(PluginManagerCore.isLoaded(PluginId("JavaScript")))
}
fun testIssue11() {
@Language("JavaScript") val code = """
"use strict";
const _ = require('lodash') || false
const moment = require('moment')
""".trimIndent()
myFixture.configureByText(JavaScriptFileType, code)
PsiDocumentManager.getInstance(project).commitAllDocuments()
val doHighlighting = myFixture.doHighlighting()
assertFalse(doHighlighting.isEmpty())
doHighlighting.getBrackets().shouldBe(
arrayOf(
roundLevel(0),
roundLevel(0),
roundLevel(0),
roundLevel(0)
)
)
}
fun testIssue12() {
@Language("JavaScript") val code = """
"use strict";
console.log(a > b)
console.log(a == b)
""".trimIndent()
myFixture.configureByText(JavaScriptFileType, code)
PsiDocumentManager.getInstance(project).commitAllDocuments()
val doHighlighting = myFixture.doHighlighting()
assertFalse(doHighlighting.isEmpty())
doHighlighting.getBrackets().shouldBe(
arrayOf(
roundLevel(0),
roundLevel(0),
roundLevel(0),
roundLevel(0)
)
)
}
fun testIssue21() {
@Language("JavaScript") val code = "open (\$" + "{f})\n" + "open (\$" + "{f} )"
myFixture.configureByText(JavaScriptFileType, code)
PsiDocumentManager.getInstance(project).commitAllDocuments()
val doHighlighting = myFixture.doHighlighting()
assertFalse(doHighlighting.isEmpty())
doHighlighting.getBrackets().shouldBe(
arrayOf(
roundLevel(0),
roundLevel(0),
roundLevel(0),
roundLevel(0)
)
)
}
fun testIssue23() {
@Language("JavaScript") val code = """
"use strict";
var a;
if ((a.field_detail && a.is) ||
(a.field_detail && a.is) ||
(a.field_detail && a.is) ||
(a.field_detail && a.is) ||
(a.field_detail && a.is) ||
(a.field_detail && a.is) ||
(a.field_detail && a.is)
) ;
""".trimIndent()
myFixture.configureByText(JavaScriptFileType, code)
PsiDocumentManager.getInstance(project).commitAllDocuments()
val doHighlighting = myFixture.doHighlighting()
assertFalse(doHighlighting.isEmpty())
doHighlighting.getBrackets().shouldBe(
arrayOf(
roundLevel(0),
roundLevel(1),
roundLevel(1),
roundLevel(1),
roundLevel(1),
roundLevel(1),
roundLevel(1),
roundLevel(1),
roundLevel(1),
roundLevel(1),
roundLevel(1),
roundLevel(1),
roundLevel(1),
roundLevel(1),
roundLevel(1),
roundLevel(0)
)
)
}
fun testIssue38() {
@Language("JavaScript") val code = """
const element = ( <div> <h1>Hello, world!</h1> </div> );
""".trimIndent()
myFixture.configureByText(JSXFileType, code)
PsiDocumentManager.getInstance(project).commitAllDocuments()
val doHighlighting = myFixture.doHighlighting()
assertFalse(doHighlighting.isEmpty())
doHighlighting.getBrackets().shouldBe(
arrayOf(
roundLevel(0),
angleLevel(0),
angleLevel(0),
angleLevel(1),
angleLevel(1),
angleLevel(1),
angleLevel(1),
angleLevel(0),
angleLevel(0),
roundLevel(0)
)
)
}
fun testIssue39() {
@Language("JavaScript") val code = """
const html = '<div><div><div>Hello</div></div></div>'
""".trimIndent()
myFixture.configureByText(JavaScriptFileType, code)
PsiDocumentManager.getInstance(project).commitAllDocuments()
val doHighlighting = myFixture.doHighlighting()
assertFalse(doHighlighting.isEmpty())
doHighlighting.getBrackets().shouldBe(
arrayOf(
angleLevel(0),
angleLevel(0),
angleLevel(1),
angleLevel(1),
angleLevel(2),
angleLevel(2),
angleLevel(2),
angleLevel(2),
angleLevel(1),
angleLevel(1),
angleLevel(0),
angleLevel(0)
)
)
}
fun testIssue31() {
@Language("JavaScript") val code = """
"use strict";
const f = () => {}
const a = [1,2,3]
const s = `<ololo>`
""".trimIndent()
myFixture.configureByText(TypeScriptFileType, code)
PsiDocumentManager.getInstance(project).commitAllDocuments()
val doHighlighting = myFixture.doHighlighting()
assertFalse(doHighlighting.isEmpty())
doHighlighting.getBrackets().shouldBe(
arrayOf(
roundLevel(0),
roundLevel(0),
squigglyLevel(0),
squigglyLevel(0),
squareLevel(0),
squareLevel(0),
angleLevel(0),
angleLevel(0)
)
)
}
fun testIssue427() {
@Language("TypeScript") val code = """let example: Array<Map<string,string>>;""".trimIndent()
myFixture.configureByText(TypeScriptFileType, code)
PsiDocumentManager.getInstance(project).commitAllDocuments()
val doHighlighting = myFixture.doHighlighting()
assertFalse(doHighlighting.isEmpty())
doHighlighting.getBrackets().shouldBe(
arrayOf(
angleLevel(0),
angleLevel(1),
angleLevel(1),
angleLevel(0)
)
)
}
}

View File

@@ -35,29 +35,26 @@ public class Test<T> {
PsiDocumentManager.getInstance(project).commitAllDocuments()
val doHighlighting = myFixture.doHighlighting()
assertFalse(doHighlighting.isEmpty())
doHighlighting.filter { brackets.contains(it.text.toChar()) }
.map { it.forcedTextAttributesKey.defaultAttributes.foregroundColor }
.toTypedArray()
.shouldBe(
arrayOf(
angleLevel(0),
angleLevel(0),
squigglyLevel(0),
roundLevel(0),
roundLevel(0),
squigglyLevel(1),
roundLevel(0),
roundLevel(0),
roundLevel(0),
roundLevel(1),
roundLevel(2),
roundLevel(2),
roundLevel(1),
roundLevel(0),
squigglyLevel(1),
squigglyLevel(0)
)
doHighlighting.getBrackets().shouldBe(
arrayOf(
angleLevel(0),
angleLevel(0),
squigglyLevel(0),
roundLevel(0),
roundLevel(0),
squigglyLevel(1),
roundLevel(0),
roundLevel(0),
roundLevel(0),
roundLevel(1),
roundLevel(2),
roundLevel(2),
roundLevel(1),
roundLevel(0),
squigglyLevel(1),
squigglyLevel(0)
)
)
}
fun testDisableRainbowForJava() {
@@ -75,12 +72,9 @@ public class Test<T> {
PsiDocumentManager.getInstance(project).commitAllDocuments()
val doHighlighting = myFixture.doHighlighting()
assertFalse(doHighlighting.isEmpty())
doHighlighting.filter { brackets.contains(it.text.toChar()) }
.map { it.forcedTextAttributesKey.defaultAttributes.foregroundColor }
.toTypedArray()
.shouldBe(
arrayOf()
)
doHighlighting.getBrackets().shouldBe(
arrayOf()
)
}
fun testDisableRainbowAngleBracketsForJava() {
@@ -98,27 +92,24 @@ public class Test<T> {
PsiDocumentManager.getInstance(project).commitAllDocuments()
val doHighlighting = myFixture.doHighlighting()
assertFalse(doHighlighting.isEmpty())
doHighlighting.filter { brackets.contains(it.text.toChar()) }
.map { it.forcedTextAttributesKey.defaultAttributes.foregroundColor }
.toTypedArray()
.shouldBe(
arrayOf(
squigglyLevel(0),
roundLevel(0),
roundLevel(0),
squigglyLevel(1),
roundLevel(0),
roundLevel(0),
roundLevel(0),
roundLevel(1),
roundLevel(2),
roundLevel(2),
roundLevel(1),
roundLevel(0),
squigglyLevel(1),
squigglyLevel(0)
)
doHighlighting.getBrackets().shouldBe(
arrayOf(
squigglyLevel(0),
roundLevel(0),
roundLevel(0),
squigglyLevel(1),
roundLevel(0),
roundLevel(0),
roundLevel(0),
roundLevel(1),
roundLevel(2),
roundLevel(2),
roundLevel(1),
roundLevel(0),
squigglyLevel(1),
squigglyLevel(0)
)
)
}
fun testDisableRainbowRoundBracketsForJava() {
@@ -136,19 +127,16 @@ public class Test<T> {
PsiDocumentManager.getInstance(project).commitAllDocuments()
val doHighlighting = myFixture.doHighlighting()
assertFalse(doHighlighting.isEmpty())
doHighlighting.filter { brackets.contains(it.text.toChar()) }
.map { it.forcedTextAttributesKey.defaultAttributes.foregroundColor }
.toTypedArray()
.shouldBe(
arrayOf(
angleLevel(0),
angleLevel(0),
squigglyLevel(0),
squigglyLevel(1),
squigglyLevel(1),
squigglyLevel(0)
)
doHighlighting.getBrackets().shouldBe(
arrayOf(
angleLevel(0),
angleLevel(0),
squigglyLevel(0),
squigglyLevel(1),
squigglyLevel(1),
squigglyLevel(0)
)
)
}
fun testDisableRainbowSquigglyBracketsForJava() {
@@ -166,25 +154,22 @@ public class Test<T> {
PsiDocumentManager.getInstance(project).commitAllDocuments()
val doHighlighting = myFixture.doHighlighting()
assertFalse(doHighlighting.isEmpty())
doHighlighting.filter { brackets.contains(it.text.toChar()) }
.map { it.forcedTextAttributesKey.defaultAttributes.foregroundColor }
.toTypedArray()
.shouldBe(
arrayOf(
angleLevel(0),
angleLevel(0),
roundLevel(0),
roundLevel(0),
roundLevel(0),
roundLevel(0),
roundLevel(0),
roundLevel(1),
roundLevel(2),
roundLevel(2),
roundLevel(1),
roundLevel(0)
)
doHighlighting.getBrackets().shouldBe(
arrayOf(
angleLevel(0),
angleLevel(0),
roundLevel(0),
roundLevel(0),
roundLevel(0),
roundLevel(0),
roundLevel(0),
roundLevel(1),
roundLevel(2),
roundLevel(2),
roundLevel(1),
roundLevel(0)
)
)
}
fun testDoNOTRainbowifyBracketsWithoutContentForJava() {
@@ -202,25 +187,22 @@ public class Test<T> {
PsiDocumentManager.getInstance(project).commitAllDocuments()
val doHighlighting = myFixture.doHighlighting()
assertFalse(doHighlighting.isEmpty())
doHighlighting.filter { brackets.contains(it.text.toChar()) }
.map { it.forcedTextAttributesKey.defaultAttributes.foregroundColor }
.toTypedArray()
.shouldBe(
arrayOf(
angleLevel(0),
angleLevel(0),
squigglyLevel(0),
squigglyLevel(1),
roundLevel(0),
roundLevel(0),
roundLevel(0),
roundLevel(1),
roundLevel(1),
roundLevel(0),
squigglyLevel(1),
squigglyLevel(0)
)
doHighlighting.getBrackets().shouldBe(
arrayOf(
angleLevel(0),
angleLevel(0),
squigglyLevel(0),
squigglyLevel(1),
roundLevel(0),
roundLevel(0),
roundLevel(0),
roundLevel(1),
roundLevel(1),
roundLevel(0),
squigglyLevel(1),
squigglyLevel(0)
)
)
}
fun testDoNOTRainbowifyBracketsWhenJavaInBlacklist() {
@@ -239,11 +221,7 @@ public class Test<T> {
PsiDocumentManager.getInstance(project).commitAllDocuments()
val doHighlighting = myFixture.doHighlighting()
assertFalse(doHighlighting.isEmpty())
doHighlighting.filter { brackets.contains(it.text.toChar()) }
.map { it.forcedTextAttributesKey.defaultAttributes.foregroundColor }
.toTypedArray()
.size
.shouldBe(0)
doHighlighting.getBrackets().size.shouldBe(0)
}
fun testIssue391() {
@@ -262,31 +240,28 @@ public class Test {
PsiDocumentManager.getInstance(project).commitAllDocuments()
val doHighlighting = myFixture.doHighlighting()
assertFalse(doHighlighting.isEmpty())
doHighlighting.filter { brackets.contains(it.text.toChar()) }
.map { it.forcedTextAttributesKey.defaultAttributes.foregroundColor }
.toTypedArray()
.shouldBe(
arrayOf(
roundLevel(0),//{
roundLevel(1),//(
roundLevel(1),//)
roundLevel(1),//{
roundLevel(2),
roundLevel(2),
roundLevel(2),
roundLevel(3),
roundLevel(4),
roundLevel(4),
roundLevel(3),
roundLevel(2),
roundLevel(1),//}
roundLevel(0)//}
)
doHighlighting.getBrackets().shouldBe(
arrayOf(
roundLevel(0),//{
roundLevel(1),//(
roundLevel(1),//)
roundLevel(1),//{
roundLevel(2),
roundLevel(2),
roundLevel(2),
roundLevel(3),
roundLevel(4),
roundLevel(4),
roundLevel(3),
roundLevel(2),
roundLevel(1),//}
roundLevel(0)//}
)
)
}
}

View File

@@ -0,0 +1,134 @@
package com.chylex.intellij.coloredbrackets
import com.intellij.psi.PsiDocumentManager
import com.intellij.testFramework.fixtures.LightJavaCodeInsightFixtureTestCase
import io.kotest.matchers.shouldBe
import org.intellij.lang.annotations.Language
import org.jetbrains.kotlin.idea.KotlinFileType
class RainbowKotlinTest : LightJavaCodeInsightFixtureTestCase() {
fun testRainbowForKotlin() {
@Language("kotlin") val code =
"""
fun <T> filter(l: List<T>, f: (T) -> Boolean): MutableList<T> {
val res = mutableListOf<T>()
l.forEach { if (f(it)) { res += it } }
return res
}
""".trimIndent()
myFixture.configureByText(KotlinFileType.INSTANCE, code)
PsiDocumentManager.getInstance(project).commitAllDocuments()
val doHighlighting = myFixture.doHighlighting()
assertFalse(doHighlighting.isEmpty())
doHighlighting.getBrackets().shouldBe(
arrayOf(
angleLevel(0),
angleLevel(0),
roundLevel(0),
angleLevel(0),
angleLevel(0),
roundLevel(1),
roundLevel(1),
roundLevel(0),
angleLevel(0),
angleLevel(0),
squigglyLevel(0),
angleLevel(0),
angleLevel(0),
roundLevel(0),
roundLevel(0),
squigglyLevel(1),
roundLevel(0),
roundLevel(1),
roundLevel(1),
roundLevel(0),
squigglyLevel(2),
squigglyLevel(2),
squigglyLevel(1),
squigglyLevel(0)
)
)
}
fun testRainbowArrowForKotlin() {
@Language("kotlin") val code =
"""
val a: (Int) -> Unit = { aa ->
val b: (Int) -> Unit = { bb ->
val c: (Int) -> Unit = { cc ->
val d: (Int) -> Unit = { dd ->
}
}
}
}
""".trimIndent()
myFixture.configureByText(KotlinFileType.INSTANCE, code)
PsiDocumentManager.getInstance(project).commitAllDocuments()
val doHighlighting = myFixture.doHighlighting()
assertFalse(doHighlighting.isEmpty())
doHighlighting.getBrackets().shouldBe(
arrayOf(
roundLevel(0),
roundLevel(0),
squigglyLevel(0),
roundLevel(0),
roundLevel(0),
squigglyLevel(1),
roundLevel(0),
roundLevel(0),
squigglyLevel(2),
roundLevel(0),
roundLevel(0),
squigglyLevel(3),
squigglyLevel(3),
squigglyLevel(2),
squigglyLevel(1),
squigglyLevel(0)
)
)
}
fun testKotlinFunctionLiteralBracesAndArrow() {
@Language("kotlin") val code =
"""
val a :Int = 1
fun t() {
a?.let {
}
}
""".trimIndent()
myFixture.configureByText(KotlinFileType.INSTANCE, code)
PsiDocumentManager.getInstance(project).commitAllDocuments()
val doHighlighting = myFixture.doHighlighting()
assertFalse(doHighlighting.isEmpty())
doHighlighting.getBrackets().shouldBe(
arrayOf(
roundLevel(0),
roundLevel(0),
squigglyLevel(0),
squigglyLevel(1),
squigglyLevel(1),
squigglyLevel(0)
)
)
}
}

View File

@@ -1,6 +1,5 @@
package com.chylex.intellij.coloredbrackets
import com.intellij.codeInsight.daemon.impl.HighlightInfoType
import com.intellij.psi.PsiDocumentManager
import com.intellij.testFramework.fixtures.LightJavaCodeInsightFixtureTestCase
import com.jetbrains.php.lang.PhpFileType
@@ -28,29 +27,26 @@ function padZero(string data): string
PsiDocumentManager.getInstance(project).commitAllDocuments()
val doHighlighting = myFixture.doHighlighting()
assertFalse(doHighlighting.isEmpty())
doHighlighting.filter { brackets.contains(it.text.toChar()) && it.severity != HighlightInfoType.INJECTED_FRAGMENT_SEVERITY }
.map { it.forcedTextAttributesKey.defaultAttributes.foregroundColor }
.toTypedArray()
.shouldBe(
arrayOf(
roundLevel(0),
roundLevel(0),
squigglyLevel(0),
roundLevel(1),
roundLevel(1),
roundLevel(1),
roundLevel(1),
squigglyLevel(1),
roundLevel(2),
roundLevel(2),
squigglyLevel(1),
squigglyLevel(0)
)
doHighlighting.getBrackets().shouldBe(
arrayOf(
roundLevel(0),
roundLevel(0),
squigglyLevel(0),
roundLevel(1),
roundLevel(1),
roundLevel(1),
roundLevel(1),
squigglyLevel(1),
roundLevel(2),
roundLevel(2),
squigglyLevel(1),
squigglyLevel(0)
)
)
}
}

View File

@@ -10,7 +10,7 @@ import org.jetbrains.plugins.ruby.ruby.lang.RubyFileType
class RainbowRubyTest : LightJavaCodeInsightFixtureTestCase() {
fun testRubyPluginEnabled() {
assertTrue(PluginManagerCore.getPlugin(PluginId.getId("org.jetbrains.plugins.ruby"))?.isEnabled!!)
assertTrue(PluginManagerCore.isLoaded(PluginId("org.jetbrains.plugins.ruby")))
}
fun testRainbowForIssue53Part0() {
@@ -23,18 +23,15 @@ end
myFixture.configureByText(RubyFileType.RUBY, code)
PsiDocumentManager.getInstance(project).commitAllDocuments()
val doHighlighting = myFixture.doHighlighting()
assertFalse(doHighlighting.isEmpty())
doHighlighting.filter { brackets.contains(it.text.toChar()) }
.map { it.forcedTextAttributesKey.defaultAttributes.foregroundColor }
.toTypedArray()
.shouldBe(
arrayOf(
roundLevel(0),
roundLevel(1),
roundLevel(1),
roundLevel(0)
)
assertFalse(doHighlighting.isEmpty());
doHighlighting.getBrackets().shouldBe(
arrayOf(
roundLevel(0),
roundLevel(1),
roundLevel(1),
roundLevel(0)
)
)
}
fun testRainbowForIssue53Part1() {
@@ -45,16 +42,13 @@ foobar(p1: "", p2: false, p3: 1)
myFixture.configureByText(RubyFileType.RUBY, code)
PsiDocumentManager.getInstance(project).commitAllDocuments()
val doHighlighting = myFixture.doHighlighting()
assertFalse(doHighlighting.isEmpty())
doHighlighting.filter { brackets.contains(it.text.toChar()) }
.map { it.forcedTextAttributesKey.defaultAttributes.foregroundColor }
.toTypedArray()
.shouldBe(
arrayOf(
roundLevel(0),
roundLevel(0)
)
assertFalse(doHighlighting.isEmpty());
doHighlighting.getBrackets().shouldBe(
arrayOf(
roundLevel(0),
roundLevel(0)
)
)
}
fun testRainbowForIssue53Part2() {
@@ -71,25 +65,20 @@ end
PsiDocumentManager.getInstance(project).commitAllDocuments()
val doHighlighting = myFixture.doHighlighting()
assertFalse(doHighlighting.isEmpty())
doHighlighting
.filter { brackets.contains(it.text.toChar()) }
.filterNot { it?.forcedTextAttributesKey?.defaultAttributes == null }
.map { it.forcedTextAttributesKey.defaultAttributes.foregroundColor }
.toTypedArray()
.shouldBe(
arrayOf(
roundLevel(0),
squigglyLevel(0),
squigglyLevel(1),
squigglyLevel(1),
squigglyLevel(1),
squigglyLevel(1),
squigglyLevel(0),
roundLevel(0),
squigglyLevel(0),
squigglyLevel(0)
)
doHighlighting.getBrackets().shouldBe(
arrayOf(
roundLevel(0),
squigglyLevel(0),
squigglyLevel(1),
squigglyLevel(1),
squigglyLevel(1),
squigglyLevel(1),
squigglyLevel(0),
roundLevel(0),
squigglyLevel(0),
squigglyLevel(0)
)
)
}
fun testRainbowForIssue53Part3() {
@@ -109,19 +98,14 @@ end
PsiDocumentManager.getInstance(project).commitAllDocuments()
val doHighlighting = myFixture.doHighlighting()
assertFalse(doHighlighting.isEmpty())
doHighlighting
.filter { brackets.contains(it.text.toChar()) }
.filterNot { it?.forcedTextAttributesKey?.defaultAttributes == null }
.map { it.forcedTextAttributesKey.defaultAttributes.foregroundColor }
.toTypedArray()
.shouldBe(
arrayOf(
squareLevel(0),
squareLevel(0),
squareLevel(0),
squareLevel(0)
)
doHighlighting.getBrackets().shouldBe(
arrayOf(
squareLevel(0),
squareLevel(0),
squareLevel(0),
squareLevel(0)
)
)
}
fun testRainbowForIssue53Part4() {
@@ -135,20 +119,15 @@ end
PsiDocumentManager.getInstance(project).commitAllDocuments()
val doHighlighting = myFixture.doHighlighting()
assertFalse(doHighlighting.isEmpty())
doHighlighting
.filter { brackets.contains(it.text.toChar()) }
.filterNot { it?.forcedTextAttributesKey?.defaultAttributes == null }
.map { it.forcedTextAttributesKey.defaultAttributes.foregroundColor }
.toTypedArray()
.shouldBe(
arrayOf(
squareLevel(0),
squareLevel(1),
squareLevel(2),
squareLevel(2),
squareLevel(1),
squareLevel(0)
)
doHighlighting.getBrackets().shouldBe(
arrayOf(
squareLevel(0),
squareLevel(1),
squareLevel(2),
squareLevel(2),
squareLevel(1),
squareLevel(0)
)
)
}
}

View File

@@ -6,7 +6,9 @@ import com.intellij.testFramework.fixtures.LightJavaCodeInsightFixtureTestCase
import io.kotest.matchers.shouldBe
import org.intellij.lang.annotations.Language
import org.jetbrains.plugins.scala.ScalaFileType
import org.junit.Ignore
@Ignore("IDEA has broken modularization")
class RainbowScalaTest : LightJavaCodeInsightFixtureTestCase() {
override fun tearDown() {
@@ -36,28 +38,24 @@ import scala.annotation.tailrec
PsiDocumentManager.getInstance(project).commitAllDocuments()
val doHighlighting = myFixture.doHighlighting()
assertFalse(doHighlighting.isEmpty())
doHighlighting.filter { brackets.contains(it.text.toChar()) }
.filter { it?.forcedTextAttributesKey != null }
.map { it.forcedTextAttributesKey.defaultAttributes.foregroundColor }
.toTypedArray()
.shouldBe(
arrayOf(
squareLevel(0),
squareLevel(0),
roundLevel(0),
roundLevel(0),
squigglyLevel(0),
squigglyLevel(1),
squareLevel(0),
squareLevel(0),
roundLevel(0),
roundLevel(0),
squigglyLevel(1),
squigglyLevel(0)
)
doHighlighting.getBrackets().shouldBe(
arrayOf(
squareLevel(0),
squareLevel(0),
roundLevel(0),
roundLevel(0),
squigglyLevel(0),
squigglyLevel(1),
squareLevel(0),
squareLevel(0),
roundLevel(0),
roundLevel(0),
squigglyLevel(1),
squigglyLevel(0)
)
)
}
fun testDisableRainbowSquareBracketsForScala() {
@@ -78,23 +76,19 @@ import scala.annotation.tailrec
PsiDocumentManager.getInstance(project).commitAllDocuments()
val doHighlighting = myFixture.doHighlighting()
assertFalse(doHighlighting.isEmpty())
doHighlighting.filter { brackets.contains(it.text.toChar()) }
.filter { it?.forcedTextAttributesKey != null }
.map { it.forcedTextAttributesKey.defaultAttributes.foregroundColor }
.toTypedArray()
.shouldBe(
arrayOf(
roundLevel(0),
roundLevel(0),
squigglyLevel(0),
squigglyLevel(1),
roundLevel(0),
roundLevel(0),
squigglyLevel(1),
squigglyLevel(0)
)
doHighlighting.getBrackets().shouldBe(
arrayOf(
roundLevel(0),
roundLevel(0),
squigglyLevel(0),
squigglyLevel(1),
roundLevel(0),
roundLevel(0),
squigglyLevel(1),
squigglyLevel(0)
)
)
}
}

View File

@@ -28,59 +28,56 @@ class RainbowXMLTest : LightJavaCodeInsightFixtureTestCase() {
PsiDocumentManager.getInstance(project).commitAllDocuments()
val doHighlighting = myFixture.doHighlighting()
assertFalse(doHighlighting.isEmpty())
doHighlighting
.map { it.forcedTextAttributesKey.defaultAttributes.foregroundColor }
.toTypedArray()
.shouldBe(
arrayOf(
angleLevel(0),
angleLevel(0),
angleLevel(0),
angleLevel(0),
angleLevel(0),
angleLevel(0),//idea-plugin
angleLevel(0),
angleLevel(1),
angleLevel(1),//name
angleLevel(1),
angleLevel(1),
angleLevel(1),//name
angleLevel(1),
angleLevel(1),
angleLevel(1),//description
angleLevel(1),
angleLevel(2),
angleLevel(2),//p
angleLevel(2),
angleLevel(2),
angleLevel(2),//p
angleLevel(2),
angleLevel(2),
angleLevel(2),//p
angleLevel(2),
angleLevel(2),
angleLevel(2),//p
angleLevel(2),
angleLevel(2),
angleLevel(2),//br
angleLevel(2),
angleLevel(1),
angleLevel(1),//description
angleLevel(1),
angleLevel(0),
angleLevel(0),//idea-plugin
angleLevel(0)
)
doHighlighting.getBrackets().shouldBe(
arrayOf(
angleLevel(0),
angleLevel(0),
angleLevel(0),
angleLevel(0),
angleLevel(0),
angleLevel(0),//idea-plugin
angleLevel(0),
angleLevel(1),
angleLevel(1),//name
angleLevel(1),
angleLevel(1),
angleLevel(1),//name
angleLevel(1),
angleLevel(1),
angleLevel(1),//description
angleLevel(1),
angleLevel(2),
angleLevel(2),//p
angleLevel(2),
angleLevel(2),
angleLevel(2),//p
angleLevel(2),
angleLevel(2),
angleLevel(2),//p
angleLevel(2),
angleLevel(2),
angleLevel(2),//p
angleLevel(2),
angleLevel(2),
angleLevel(2),//br
angleLevel(2),
angleLevel(1),
angleLevel(1),//description
angleLevel(1),
angleLevel(0),
angleLevel(0),//idea-plugin
angleLevel(0)
)
)
}
fun testRainbowForXML() {
@@ -103,47 +100,44 @@ class RainbowXMLTest : LightJavaCodeInsightFixtureTestCase() {
PsiDocumentManager.getInstance(project).commitAllDocuments()
val doHighlighting = myFixture.doHighlighting()
assertFalse(doHighlighting.isEmpty())
doHighlighting
.map { it.forcedTextAttributesKey.defaultAttributes.foregroundColor }
.toTypedArray()
.shouldBe(
arrayOf(
angleLevel(0),
angleLevel(0),
angleLevel(0),
angleLevel(0),
angleLevel(0),
angleLevel(0),
angleLevel(1),
angleLevel(1),
angleLevel(1),
angleLevel(1),
angleLevel(1),
angleLevel(1),
angleLevel(2),
angleLevel(2),
angleLevel(2),
angleLevel(2),
angleLevel(2),
angleLevel(2),
angleLevel(2),
angleLevel(2),
angleLevel(2),
angleLevel(2),
angleLevel(1),
angleLevel(1),
angleLevel(0),
angleLevel(0)
)
doHighlighting.getBrackets().shouldBe(
arrayOf(
angleLevel(0),
angleLevel(0),
angleLevel(0),
angleLevel(0),
angleLevel(0),
angleLevel(0),
angleLevel(1),
angleLevel(1),
angleLevel(1),
angleLevel(1),
angleLevel(1),
angleLevel(1),
angleLevel(2),
angleLevel(2),
angleLevel(2),
angleLevel(2),
angleLevel(2),
angleLevel(2),
angleLevel(2),
angleLevel(2),
angleLevel(2),
angleLevel(2),
angleLevel(1),
angleLevel(1),
angleLevel(0),
angleLevel(0)
)
)
}
}

View File

@@ -25,11 +25,7 @@ public class Test<T> {
PsiDocumentManager.getInstance(project).commitAllDocuments()
val doHighlighting = myFixture.doHighlighting()
assertFalse(doHighlighting.isEmpty())
val highlightSize = doHighlighting.filter { brackets.contains(it.text.toChar()) }
.filter { it.forcedTextAttributesKey.defaultAttributes.foregroundColor != null }
.map { it.forcedTextAttributesKey.defaultAttributes.foregroundColor }
.toTypedArray()
.size
val highlightSize = doHighlighting.getBrackets().size
assert(highlightSize == 16)
}

View File

@@ -1,8 +1,15 @@
package com.chylex.intellij.coloredbrackets
val brackets = RainbowHighlighter.getBrackets()
import com.chylex.intellij.coloredbrackets.visitor.RainbowHighlightVisitor
import com.intellij.codeInsight.daemon.impl.HighlightInfo
import java.awt.Color
fun CharSequence.toChar() = elementAt(0)
fun List<HighlightInfo>.getBrackets(): Array<Color> {
return this
.filter { it.toolId?.let { id -> id is Class<*> && RainbowHighlightVisitor::class.java.isAssignableFrom(id) } == true }
.map { it.forcedTextAttributesKey.defaultAttributes.foregroundColor }
.toTypedArray()
}
fun roundLevel(level: Int) = RainbowHighlighter.getRainbowColor(RainbowHighlighter.NAME_ROUND_BRACKETS, level)

View File

@@ -1,7 +1,5 @@
@file:Suppress("ConvertLambdaToReference")
import org.jetbrains.intellij.platform.gradle.TestFrameworkType
plugins {
kotlin("jvm")
id("org.jetbrains.intellij.platform")
@@ -10,7 +8,7 @@ plugins {
group = "com.chylex.intellij.coloredbrackets"
version = "1.3.0"
val ideaVersion = "2023.3"
val ideaVersion = "2025.3"
allprojects {
apply(plugin = "org.jetbrains.kotlin.jvm")
@@ -29,9 +27,13 @@ allprojects {
}
intellijPlatform {
sandboxContainer.set(layout.buildDirectory.map { it.dir("idea-sandbox") })
buildSearchableOptions = false
pluginConfiguration {
ideaVersion {
sinceBuild.set("233")
sinceBuild.set("253")
untilBuild.set(provider { null })
}
}
@@ -48,54 +50,23 @@ allprojects {
}
}
subprojects {
intellijPlatform {
buildSearchableOptions = false
}
}
idea {
module {
excludeDirs.add(file(".kotlin"))
excludeDirs.add(file("build"))
excludeDirs.add(file("gradle"))
}
}
dependencies {
project(":api")
intellijPlatform {
@Suppress("DEPRECATION")
intellijIdeaUltimate(ideaVersion)
bundledPlugin("JavaScript")
bundledPlugin("com.intellij.css")
bundledPlugin("com.intellij.database")
bundledPlugin("com.intellij.java")
bundledPlugin("org.intellij.groovy")
bundledPlugin("org.intellij.plugins.markdown")
bundledPlugin("org.jetbrains.kotlin")
bundledPlugin("org.jetbrains.plugins.yaml")
plugin("Dart", "233.11799.172") // https://plugins.jetbrains.com/plugin/6351-dart/versions/stable
plugin("PythonCore", "233.11799.300") // https://plugins.jetbrains.com/plugin/631-python/versions
plugin("com.jetbrains.php", "233.11799.300") // https://plugins.jetbrains.com/plugin/6610-php/versions
plugin("com.jetbrains.sh", "233.11799.165") // https://plugins.jetbrains.com/plugin/13122-shell-script/versions
plugin("org.intellij.scala", "2023.3.19") // https://plugins.jetbrains.com/plugin/1347-scala/versions
plugin("org.jetbrains.plugins.go-template", "233.11799.172") // https://plugins.jetbrains.com/plugin/10581-go-template/versions
plugin("org.jetbrains.plugins.ruby", "233.11799.300") // https://plugins.jetbrains.com/plugin/1293-ruby/versions
testFramework(TestFrameworkType.Plugin.Java)
pluginComposedModule(implementation(project(":api")))
pluginComposedModule(implementation(project(":base")))
pluginComposedModule(implementation(project(":clion")))
pluginComposedModule(implementation(project(":rider")))
}
testImplementation("junit:junit:4.13.2")
testImplementation("io.kotest:kotest-assertions-core:5.8.0") {
exclude(group = "org.jetbrains.kotlin")
}
}
tasks.test {

View File

@@ -1,12 +1,14 @@
val ideaVersion: String by project
dependencies {
implementation(project(":api"))
implementation(project(":base"))
runtimeOnly(project(":rider")) // Support for CLion Nova.
intellijPlatform {
clion(ideaVersion)
bundledPlugin("com.intellij.clion")
// bundledPlugin("org.jetbrains.plugins.clion.radler") // Only in 2024.1 or newer. Worked around by only including the .xml file, and taking the implementation from Rider.
bundledPlugin("org.jetbrains.plugins.clion.radler")
}
}

Binary file not shown.

View File

@@ -1,7 +1,9 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.3-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-9.5.1-bin.zip
networkTimeout=10000
retries=0
retryBackOffMs=500
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

15
gradlew vendored
View File

@@ -1,7 +1,7 @@
#!/bin/sh
#
# Copyright © 2015-2021 the original authors.
# Copyright © 2015 the original authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -15,6 +15,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0
#
##############################################################################
#
@@ -55,7 +57,7 @@
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# https://github.com/gradle/gradle/blob/3d91ce3b8caaf77ad09f381f43615b715b53f72c/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
@@ -84,7 +86,7 @@ done
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
@@ -112,7 +114,6 @@ case "$( uname )" in #(
NONSTOP* ) nonstop=true ;;
esac
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
# Determine the Java command to use to start the JVM.
@@ -170,7 +171,6 @@ fi
# For Cygwin or MSYS, switch paths to Windows format before running java
if "$cygwin" || "$msys" ; then
APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
JAVACMD=$( cygpath --unix "$JAVACMD" )
@@ -203,15 +203,14 @@ fi
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
# Collect all arguments for the java command:
# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
# and any embedded shellness will be escaped.
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
# treated as '${Hostname}' itself on the command line.
set -- \
"-Dorg.gradle.appname=$APP_BASE_NAME" \
-classpath "$CLASSPATH" \
org.gradle.wrapper.GradleWrapperMain \
-jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \
"$@"
# Stop when "xargs" is not available.

54
gradlew.bat vendored
View File

@@ -13,6 +13,8 @@
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem
@rem SPDX-License-Identifier: Apache-2.0
@rem
@if "%DEBUG%"=="" @echo off
@rem ##########################################################################
@@ -21,8 +23,8 @@
@rem
@rem ##########################################################################
@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal
@rem Set local scope for the variables, and ensure extensions are enabled
setlocal EnableExtensions
set DIRNAME=%~dp0
if "%DIRNAME%"=="" set DIRNAME=.
@@ -43,13 +45,13 @@ set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if %ERRORLEVEL% equ 0 goto execute
echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
echo. 1>&2
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2
goto fail
"%COMSPEC%" /c exit 1
:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
@@ -57,36 +59,24 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto execute
echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
echo. 1>&2
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2
goto fail
"%COMSPEC%" /c exit 1
:execute
@rem Setup the command line
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
@rem endlocal doesn't take effect until after the line is parsed and variables are expanded
@rem which allows us to clear the local environment before executing the java command
endlocal & "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %* & call :exitWithErrorLevel
:end
@rem End local scope for the variables with windows NT shell
if %ERRORLEVEL% equ 0 goto mainEnd
:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
set EXIT_CODE=%ERRORLEVEL%
if %EXIT_CODE% equ 0 set EXIT_CODE=1
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
exit /b %EXIT_CODE%
:mainEnd
if "%OS%"=="Windows_NT" endlocal
:omega
:exitWithErrorLevel
@rem Use "%COMSPEC%" /c exit to allow operators to work properly in scripts
"%COMSPEC%" /c exit %ERRORLEVEL%

View File

@@ -1,11 +1,13 @@
val ideaVersion: String by project
dependencies {
implementation(project(":api"))
implementation(project(":base"))
intellijPlatform {
rider(ideaVersion) {
useInstaller = false
}
bundledModule("intellij.rider.cpp.core.languages")
}
}

View File

@@ -1,10 +0,0 @@
<idea-plugin>
<extensions defaultExtensionNs="com.chylex.coloredbrackets">
<bracePairProvider language="C++"
implementationClass="com.chylex.intellij.coloredbrackets.provider.CppBracePairProvider" />
</extensions>
<extensions defaultExtensionNs="com.intellij">
<highlightVisitor implementation="com.chylex.intellij.coloredbrackets.visitor.CppRainbowVisitor" />
</extensions>
</idea-plugin>

View File

@@ -1,5 +0,0 @@
<idea-plugin>
<extensions defaultExtensionNs="com.intellij">
<annotator language="C#" implementationClass="com.chylex.intellij.coloredbrackets.annotator.RainbowAnnotator" />
</extensions>
</idea-plugin>

View File

@@ -1,10 +1,13 @@
<idea-plugin>
<extensions defaultExtensionNs="com.chylex.coloredbrackets">
<bracePairProvider language="C++"
implementationClass="com.chylex.intellij.coloredbrackets.provider.CppBracePairProvider" />
<bracePairProvider language="C#"
implementationClass="com.chylex.intellij.coloredbrackets.provider.CSharpBracePairProvider" />
</extensions>
<extensions defaultExtensionNs="com.intellij">
<highlightVisitor implementation="com.chylex.intellij.coloredbrackets.visitor.CppRainbowVisitor" />
<highlightVisitor implementation="com.chylex.intellij.coloredbrackets.visitor.CSharpRainbowVisitor" />
</extensions>
</idea-plugin>

View File

@@ -2,11 +2,11 @@ rootProject.name = "ColoredBrackets"
pluginManagement {
plugins {
kotlin("jvm") version "1.9.21"
id("org.jetbrains.intellij.platform") version "2.9.0"
kotlin("jvm") version "2.2.20"
id("org.jetbrains.intellij.platform") version "2.16.0"
}
}
include("api")
include("clion")
include("rider")
include(":base")
include(":clion")
include(":rider")

View File

@@ -1,5 +0,0 @@
<idea-plugin>
<extensions defaultExtensionNs="com.intellij">
<annotator language="Haskell" implementationClass="com.chylex.intellij.coloredbrackets.annotator.RainbowAnnotator" />
</extensions>
</idea-plugin>

View File

@@ -1,247 +0,0 @@
package com.chylex.intellij.coloredbrackets
import com.intellij.ide.plugins.PluginManagerCore
import com.intellij.lang.ecmascript6.JSXHarmonyFileType
import com.intellij.lang.javascript.JavaScriptFileType
import com.intellij.lang.javascript.TypeScriptFileType
import com.intellij.openapi.extensions.PluginId
import com.intellij.psi.PsiDocumentManager
import com.intellij.testFramework.fixtures.LightJavaCodeInsightFixtureTestCase
import io.kotest.matchers.shouldBe
import org.intellij.lang.annotations.Language
class RainbowJavaScriptTest : LightJavaCodeInsightFixtureTestCase() {
fun testJavaScriptPluginEnabled() {
assertTrue(PluginManagerCore.getPlugin(PluginId.getId("JavaScript"))?.isEnabled!!)
}
fun testIssue11() {
@Language("JavaScript") val code = """
"use strict";
const _ = require('lodash') || false
const moment = require('moment')
""".trimIndent()
myFixture.configureByText(JavaScriptFileType.INSTANCE, code)
PsiDocumentManager.getInstance(project).commitAllDocuments()
val doHighlighting = myFixture.doHighlighting()
assertFalse(doHighlighting.isEmpty())
doHighlighting.filter { brackets.contains(it.text.toChar()) }
.map { it.forcedTextAttributesKey.defaultAttributes.foregroundColor }
.toTypedArray()
.shouldBe(
arrayOf(
roundLevel(0),
roundLevel(0),
roundLevel(0),
roundLevel(0)
)
)
}
fun testIssue12() {
@Language("JavaScript") val code = """
"use strict";
console.log(a > b)
console.log(a == b)
""".trimIndent()
myFixture.configureByText(JavaScriptFileType.INSTANCE, code)
PsiDocumentManager.getInstance(project).commitAllDocuments()
val doHighlighting = myFixture.doHighlighting()
assertFalse(doHighlighting.isEmpty())
doHighlighting.filter { brackets.contains(it.text.toChar()) }
.map { it.forcedTextAttributesKey.defaultAttributes.foregroundColor }
.toTypedArray()
.shouldBe(
arrayOf(
roundLevel(0),
roundLevel(0),
roundLevel(0),
roundLevel(0)
)
)
}
fun testIssue21() {
@Language("JavaScript") val code = "open (\$" + "{f})\n" + "open (\$" + "{f} )"
myFixture.configureByText(JavaScriptFileType.INSTANCE, code)
PsiDocumentManager.getInstance(project).commitAllDocuments()
val doHighlighting = myFixture.doHighlighting()
assertFalse(doHighlighting.isEmpty())
doHighlighting.filter { brackets.contains(it.text.toChar()) }
.map { it.forcedTextAttributesKey.defaultAttributes.foregroundColor }
.toTypedArray()
.shouldBe(
arrayOf(
roundLevel(0),
roundLevel(0),
roundLevel(0),
roundLevel(0)
)
)
}
fun testIssue23() {
@Language("JavaScript") val code = """
"use strict";
var a;
if ((a.field_detail && a.is) ||
(a.field_detail && a.is) ||
(a.field_detail && a.is) ||
(a.field_detail && a.is) ||
(a.field_detail && a.is) ||
(a.field_detail && a.is) ||
(a.field_detail && a.is)
) ;
""".trimIndent()
myFixture.configureByText(JavaScriptFileType.INSTANCE, code)
PsiDocumentManager.getInstance(project).commitAllDocuments()
val doHighlighting = myFixture.doHighlighting()
assertFalse(doHighlighting.isEmpty())
doHighlighting.filter { brackets.contains(it.text.toChar()) }
.map { it.forcedTextAttributesKey.defaultAttributes.foregroundColor }
.toTypedArray()
.shouldBe(
arrayOf(
roundLevel(0),
roundLevel(1),
roundLevel(1),
roundLevel(1),
roundLevel(1),
roundLevel(1),
roundLevel(1),
roundLevel(1),
roundLevel(1),
roundLevel(1),
roundLevel(1),
roundLevel(1),
roundLevel(1),
roundLevel(1),
roundLevel(1),
roundLevel(0)
)
)
}
fun testIssue38() {
@Language("JavaScript") val code = """
const element = ( <div> <h1>Hello, world!</h1> </div> );
""".trimIndent()
myFixture.configureByText(JSXHarmonyFileType.INSTANCE, code)
PsiDocumentManager.getInstance(project).commitAllDocuments()
val doHighlighting = myFixture.doHighlighting()
assertFalse(doHighlighting.isEmpty())
doHighlighting.filter { brackets.contains(it.text.toChar()) }
.map { it.forcedTextAttributesKey.defaultAttributes.foregroundColor }
.filterNot { it == null }
.toTypedArray()
.shouldBe(
arrayOf(
roundLevel(0),
angleLevel(0),
angleLevel(0),
angleLevel(1),
angleLevel(1),
angleLevel(1),
angleLevel(1),
angleLevel(0),
angleLevel(0),
roundLevel(0)
)
)
}
fun `for somehow, it just don't work "testIssue39"`() {
@Language("JavaScript") val code = """
const html = '<div><div><div>Hello</div></div></div>'
""".trimIndent()
myFixture.configureByText(JavaScriptFileType.INSTANCE, code)
PsiDocumentManager.getInstance(project).commitAllDocuments()
val doHighlighting = myFixture.doHighlighting()
assertFalse(doHighlighting.isEmpty())
doHighlighting.filter { brackets.contains(it.text.toChar()) }
.map { it.forcedTextAttributesKey.defaultAttributes.foregroundColor }
.filterNot { it == null }
.toTypedArray()
.shouldBe(
arrayOf(
angleLevel(0),
angleLevel(0),
angleLevel(1),
angleLevel(1),
angleLevel(2),
angleLevel(2),
angleLevel(2),
angleLevel(2),
angleLevel(1),
angleLevel(1),
angleLevel(0),
angleLevel(0)
)
)
}
fun testIssue31() {
@Language("JavaScript") val code = """
"use strict";
const f = () => {}
const a = [1,2,3]
const s = `<ololo>`
""".trimIndent()
myFixture.configureByText(TypeScriptFileType.INSTANCE, code)
PsiDocumentManager.getInstance(project).commitAllDocuments()
val doHighlighting = myFixture.doHighlighting()
assertFalse(doHighlighting.isEmpty())
doHighlighting.filter { brackets.contains(it.text.toChar()) }
.map { it.forcedTextAttributesKey.defaultAttributes.foregroundColor }
.filterNot { it == null }
.toTypedArray()
.shouldBe(
arrayOf(
roundLevel(0),
roundLevel(0),
squigglyLevel(0),
squigglyLevel(0),
squareLevel(0),
squareLevel(0)
//, angleLevel(0)
//, angleLevel(0)
)
)
}
fun testIssue427() {
@Language("TypeScript") val code = """let example: Array<Map<string,string>>;""".trimIndent()
myFixture.configureByText(TypeScriptFileType.INSTANCE, code)
PsiDocumentManager.getInstance(project).commitAllDocuments()
val doHighlighting = myFixture.doHighlighting()
assertFalse(doHighlighting.isEmpty())
doHighlighting.filter { brackets.contains(it.text.toChar()) }
.map { it.forcedTextAttributesKey.defaultAttributes.foregroundColor }
.filterNot { it == null }
.toTypedArray()
.shouldBe(
arrayOf(
angleLevel(0),
angleLevel(1),
angleLevel(1),
angleLevel(0)
)
)
}
}

View File

@@ -1,190 +0,0 @@
package com.chylex.intellij.coloredbrackets
import com.intellij.psi.PsiDocumentManager
import com.intellij.testFramework.fixtures.LightJavaCodeInsightFixtureTestCase
import io.kotest.matchers.shouldBe
import org.intellij.lang.annotations.Language
import org.jetbrains.kotlin.idea.KotlinFileType
class RainbowKotlinTest : LightJavaCodeInsightFixtureTestCase() {
fun testRainbowForKotlin() {
@Language("kotlin") val code =
"""
fun <T> filter(l: List<T>, f: (T) -> Boolean): MutableList<T> {
val res = mutableListOf<T>()
l.forEach { if (f(it)) { res += it } }
return res
}
""".trimIndent()
myFixture.configureByText(KotlinFileType.INSTANCE, code)
PsiDocumentManager.getInstance(project).commitAllDocuments()
val doHighlighting = myFixture.doHighlighting()
assertFalse(doHighlighting.isEmpty())
doHighlighting.filter { brackets.contains(it.text.toChar()) }
.map { it.forcedTextAttributesKey.defaultAttributes.foregroundColor }
.toTypedArray()
.shouldBe(
arrayOf(
angleLevel(0),
angleLevel(0),
roundLevel(0),
angleLevel(0),
angleLevel(0),
roundLevel(1),
roundLevel(1),
roundLevel(0),
angleLevel(0),
angleLevel(0),
squigglyLevel(0),
angleLevel(0),
angleLevel(0),
roundLevel(0),
roundLevel(0),
squigglyLevel(1),
roundLevel(0),
roundLevel(1),
roundLevel(1),
roundLevel(0),
squigglyLevel(2),
squigglyLevel(2),
squigglyLevel(1),
squigglyLevel(0)
)
)
}
fun testRainbowArrowForKotlin() {
@Language("kotlin") val code =
"""
val a: (Int) -> Unit = { aa ->
val b: (Int) -> Unit = { bb ->
val c: (Int) -> Unit = { cc ->
val d: (Int) -> Unit = { dd ->
}
}
}
}
""".trimIndent()
myFixture.configureByText(KotlinFileType.INSTANCE, code)
PsiDocumentManager.getInstance(project).commitAllDocuments()
val doHighlighting = myFixture.doHighlighting()
assertFalse(doHighlighting.isEmpty())
doHighlighting
.filter { brackets.contains(it.text.toChar()) || it.text.contains("->") }
.filter { it?.forcedTextAttributesKey?.defaultAttributes != null }
.map { it.forcedTextAttributesKey.defaultAttributes.foregroundColor }
.toTypedArray()
.shouldBe(
arrayOf(
roundLevel(0),
roundLevel(0),
squigglyLevel(0),
squigglyLevel(0),
roundLevel(0),
roundLevel(0),
squigglyLevel(1),
squigglyLevel(1),
roundLevel(0),
roundLevel(0),
squigglyLevel(2),
squigglyLevel(2),
roundLevel(0),
roundLevel(0),
squigglyLevel(3),
squigglyLevel(3),
squigglyLevel(3),
squigglyLevel(2),
squigglyLevel(1),
squigglyLevel(0)
)
)
}
fun `ForSomeHowTheTestNotPassed "testRainbowLabelForKotlin"`() {
@Language("kotlin") val code =
"""
class AA {
fun aa() {
arrayOf(1, 2, 3).forEach {
it.let dd@{
if (it > 0) a@{
return@dd
}
}
return@forEach
}
}
}
""".trimIndent()
myFixture.configureByText(KotlinFileType.INSTANCE, code)
PsiDocumentManager.getInstance(project).commitAllDocuments()
val doHighlighting = myFixture.doHighlighting()
assertFalse(doHighlighting.isEmpty())
doHighlighting
.filter { it.forcedTextAttributes != null && it.text.contains("@") }
.map { it.forcedTextAttributesKey.defaultAttributes.foregroundColor }
.toTypedArray()
.shouldBe(
arrayOf(
squigglyLevel(3),
squigglyLevel(4),
squigglyLevel(3),
squigglyLevel(2)
)
)
}
fun testKotlinFunctionLiteralBracesAndArrow() {
@Language("kotlin") val code =
"""
val a :Int = 1
fun t() {
a?.let {
}
}
""".trimIndent()
myFixture.configureByText(KotlinFileType.INSTANCE, code)
PsiDocumentManager.getInstance(project).commitAllDocuments()
val doHighlighting = myFixture.doHighlighting()
assertFalse(doHighlighting.isEmpty())
doHighlighting
.filter { brackets.contains(it.text.toChar()) }
.filter { it?.forcedTextAttributesKey?.defaultAttributes != null }
.map { it.forcedTextAttributesKey.defaultAttributes.foregroundColor }
.toTypedArray()
.shouldBe(
arrayOf(
roundLevel(0),
roundLevel(0),
squigglyLevel(0),
//squigglyLevel(1),
//squigglyLevel(1),
squigglyLevel(0)
)
)
}
}