7 Commits
90 changed files with 896 additions and 1180 deletions
+2
View File
@@ -1,6 +1,8 @@
/.idea/* /.idea/*
!/.idea/dictionaries
!/.idea/runConfigurations !/.idea/runConfigurations
/.gradle/ /.gradle/
/.kotlin/
/.intellijPlatform/ /.intellijPlatform/
/build/ /build/
+7
View File
@@ -0,0 +1,7 @@
<component name="ProjectDictionaryState">
<dictionary name="project">
<words>
<w>Rainbowify</w>
</words>
</dictionary>
</component>
+3
View File
@@ -17,8 +17,11 @@
</ExternalSystemSettings> </ExternalSystemSettings>
<ExternalSystemDebugServerProcess>true</ExternalSystemDebugServerProcess> <ExternalSystemDebugServerProcess>true</ExternalSystemDebugServerProcess>
<ExternalSystemReattachDebugProcess>true</ExternalSystemReattachDebugProcess> <ExternalSystemReattachDebugProcess>true</ExternalSystemReattachDebugProcess>
<ExternalSystemDebugDisabled>false</ExternalSystemDebugDisabled>
<DebugAllEnabled>false</DebugAllEnabled> <DebugAllEnabled>false</DebugAllEnabled>
<RunAsTest>false</RunAsTest> <RunAsTest>false</RunAsTest>
<GradleProfilingDisabled>false</GradleProfilingDisabled>
<GradleCoverageDisabled>false</GradleCoverageDisabled>
<method v="2" /> <method v="2" />
</configuration> </configuration>
</component> </component>
+4 -1
View File
@@ -10,15 +10,18 @@
</option> </option>
<option name="taskNames"> <option name="taskNames">
<list> <list>
<option value=":runIde" /> <option value=":base:runIde" />
</list> </list>
</option> </option>
<option name="vmOptions" /> <option name="vmOptions" />
</ExternalSystemSettings> </ExternalSystemSettings>
<ExternalSystemDebugServerProcess>true</ExternalSystemDebugServerProcess> <ExternalSystemDebugServerProcess>true</ExternalSystemDebugServerProcess>
<ExternalSystemReattachDebugProcess>true</ExternalSystemReattachDebugProcess> <ExternalSystemReattachDebugProcess>true</ExternalSystemReattachDebugProcess>
<ExternalSystemDebugDisabled>false</ExternalSystemDebugDisabled>
<DebugAllEnabled>false</DebugAllEnabled> <DebugAllEnabled>false</DebugAllEnabled>
<RunAsTest>false</RunAsTest> <RunAsTest>false</RunAsTest>
<GradleProfilingDisabled>false</GradleProfilingDisabled>
<GradleCoverageDisabled>false</GradleCoverageDisabled>
<method v="2" /> <method v="2" />
</configuration> </configuration>
</component> </component>
+3
View File
@@ -17,8 +17,11 @@
</ExternalSystemSettings> </ExternalSystemSettings>
<ExternalSystemDebugServerProcess>true</ExternalSystemDebugServerProcess> <ExternalSystemDebugServerProcess>true</ExternalSystemDebugServerProcess>
<ExternalSystemReattachDebugProcess>true</ExternalSystemReattachDebugProcess> <ExternalSystemReattachDebugProcess>true</ExternalSystemReattachDebugProcess>
<ExternalSystemDebugDisabled>false</ExternalSystemDebugDisabled>
<DebugAllEnabled>false</DebugAllEnabled> <DebugAllEnabled>false</DebugAllEnabled>
<RunAsTest>false</RunAsTest> <RunAsTest>false</RunAsTest>
<GradleProfilingDisabled>false</GradleProfilingDisabled>
<GradleCoverageDisabled>false</GradleCoverageDisabled>
<method v="2" /> <method v="2" />
</configuration> </configuration>
</component> </component>
-8
View File
@@ -1,8 +0,0 @@
val ideaVersion: String by project
dependencies {
intellijPlatform {
@Suppress("DEPRECATION")
intellijIdeaUltimate(ideaVersion)
}
}
+41
View File
@@ -0,0 +1,41 @@
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()
}
}
@@ -57,8 +57,7 @@ object BracePairs {
true true
} }
} }
?.map { listOf(Pair(it.leftBraceType.toString(), it), Pair(it.rightBraceType.toString(), it)) } ?.flatMap { listOf(Pair(it.leftBraceType.toString(), it), Pair(it.rightBraceType.toString(), it)) }
?.flatten()
?.forEach { ?.forEach {
val bracePairs = braceMap[it.first] val bracePairs = braceMap[it.first]
if (bracePairs == null) { if (bracePairs == null) {
@@ -74,7 +73,7 @@ object BracePairs {
.toMap() .toMap()
} }
private fun getBraceTypeSetOf(language: Language): Set<IElementType> = language.bracePairs?.values?.flatten()?.map { listOf(it.leftBraceType, it.rightBraceType) }?.flatten()?.toSet() ?: emptySet() private fun getBraceTypeSetOf(language: Language): Set<IElementType> = language.bracePairs?.values?.flatten()?.flatMap { listOf(it.leftBraceType, it.rightBraceType) }?.toSet() ?: emptySet()
val braceTypeSet: (Language) -> Set<IElementType> = { language: Language -> getBraceTypeSetOf(language) }.memoize() val braceTypeSet: (Language) -> Set<IElementType> = { language: Language -> getBraceTypeSetOf(language) }.memoize()
@@ -1,6 +1,7 @@
package com.chylex.intellij.coloredbrackets package com.chylex.intellij.coloredbrackets
import com.chylex.intellij.coloredbrackets.settings.RainbowSettings 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.create
import com.chylex.intellij.coloredbrackets.util.memoize import com.chylex.intellij.coloredbrackets.util.memoize
import com.intellij.codeInsight.daemon.impl.HighlightInfo import com.intellij.codeInsight.daemon.impl.HighlightInfo
@@ -56,6 +57,9 @@ object RainbowHighlighter {
createRainbowAttributesKeys(KEY_ANGLE_BRACKETS, settings.numberOfColors) 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 private val rainbowElement: HighlightInfoType = HighlightInfoType
.HighlightInfoTypeImpl(HighlightSeverity.INFORMATION, DefaultLanguageHighlighterColors.CONSTANT) .HighlightInfoTypeImpl(HighlightSeverity.INFORMATION, DefaultLanguageHighlighterColors.CONSTANT)
@@ -226,4 +230,23 @@ object RainbowHighlighter {
private fun EditorColorsScheme.setInherited(key: TextAttributesKey, inherited: Boolean) { private fun EditorColorsScheme.setInherited(key: TextAttributesKey, inherited: Boolean) {
setAttributes(key, if (inherited) AbstractColorsScheme.INHERITED_ATTRS_MARKER else TextAttributes()) 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
}
} }
@@ -35,7 +35,7 @@ abstract class AbstractScopeHighlightingAction : AnAction() {
val offset = editor.caretModel.offset val offset = editor.caretModel.offset
val rainbowInfo = psiFile.findRainbowInfoAt(offset) ?: return val rainbowInfo = psiFile.findRainbowInfoAt(offset) ?: return
val highlightManager = HighlightManager.getInstance(project) val highlightManager = HighlightManager.getInstance(project)
val highlighters = editor.addHighlighter(highlightManager, rainbowInfo) val highlighters = editor.addHighlighter(editor, highlightManager, rainbowInfo)
editor.highlightingDisposer?.dispose() editor.highlightingDisposer?.dispose()
if (highlighters.isNotEmpty()) { if (highlighters.isNotEmpty()) {
@@ -47,6 +47,7 @@ abstract class AbstractScopeHighlightingAction : AnAction() {
} }
protected abstract fun Editor.addHighlighter( protected abstract fun Editor.addHighlighter(
editor: Editor,
highlightManager: HighlightManager, highlightManager: HighlightManager,
rainbowInfo: RainbowInfo, rainbowInfo: RainbowInfo,
): Collection<RangeHighlighter> ): Collection<RangeHighlighter>
@@ -1,38 +1,33 @@
package com.chylex.intellij.coloredbrackets.action package com.chylex.intellij.coloredbrackets.action
import com.chylex.intellij.coloredbrackets.RainbowHighlighter
import com.chylex.intellij.coloredbrackets.RainbowInfo import com.chylex.intellij.coloredbrackets.RainbowInfo
import com.chylex.intellij.coloredbrackets.settings.RainbowSettings import com.chylex.intellij.coloredbrackets.settings.RainbowSettings
import com.chylex.intellij.coloredbrackets.util.alphaBlend
import com.intellij.codeInsight.highlighting.HighlightManager import com.intellij.codeInsight.highlighting.HighlightManager
import com.intellij.openapi.editor.Editor 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.RangeHighlighter
import com.intellij.openapi.editor.markup.TextAttributes
import java.awt.Font
import java.util.LinkedList import java.util.LinkedList
class ScopeHighlightingAction : AbstractScopeHighlightingAction() { class ScopeHighlightingAction : AbstractScopeHighlightingAction() {
override fun Editor.addHighlighter( override fun Editor.addHighlighter(
editor: Editor,
highlightManager: HighlightManager, highlightManager: HighlightManager,
rainbowInfo: RainbowInfo, rainbowInfo: RainbowInfo,
): Collection<RangeHighlighter> { ): Collection<RangeHighlighter> {
val defaultBackground = EditorColorsManager.getInstance().globalScheme.defaultBackground val attributesKey = RainbowHighlighter.updateScopeHighlightingAttributes(editor.colorsScheme, rainbowInfo)
val background = rainbowInfo.color.alphaBlend(defaultBackground, 0.2f)
val attributes = TextAttributes(null, background, rainbowInfo.color, EffectType.BOXED, Font.PLAIN)
val highlighters = LinkedList<RangeHighlighter>() val highlighters = LinkedList<RangeHighlighter>()
highlightManager.addRangeHighlight( highlightManager.addRangeHighlight(
this, this,
rainbowInfo.startOffset, rainbowInfo.startOffset,
rainbowInfo.endOffset, rainbowInfo.endOffset,
attributes, //create("ScopeHighlightingAction", attributes), attributesKey,
false, //hideByTextChange false,
RainbowSettings.instance.pressAnyKeyToRemoveTheHighlightingEffects, //hideByAnyKey RainbowSettings.instance.pressAnyKeyToRemoveTheHighlightingEffects,
highlighters highlighters
) )
return highlighters return highlighters
} }
} }
@@ -1,28 +1,21 @@
package com.chylex.intellij.coloredbrackets.action package com.chylex.intellij.coloredbrackets.action
import com.chylex.intellij.coloredbrackets.RainbowHighlighter
import com.chylex.intellij.coloredbrackets.RainbowInfo import com.chylex.intellij.coloredbrackets.RainbowInfo
import com.chylex.intellij.coloredbrackets.settings.RainbowSettings import com.chylex.intellij.coloredbrackets.settings.RainbowSettings
import com.chylex.intellij.coloredbrackets.util.alphaBlend
import com.intellij.codeInsight.highlighting.HighlightManager import com.intellij.codeInsight.highlighting.HighlightManager
import com.intellij.openapi.editor.Editor 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.RangeHighlighter
import com.intellij.openapi.editor.markup.TextAttributes
import java.awt.Color
import java.awt.Font
import java.util.LinkedList import java.util.LinkedList
class ScopeOutsideHighlightingRestrainAction : AbstractScopeHighlightingAction() { class ScopeOutsideHighlightingRestrainAction : AbstractScopeHighlightingAction() {
override fun Editor.addHighlighter( override fun Editor.addHighlighter(
editor: Editor,
highlightManager: HighlightManager, highlightManager: HighlightManager,
rainbowInfo: RainbowInfo, rainbowInfo: RainbowInfo,
): Collection<RangeHighlighter> { ): Collection<RangeHighlighter> {
val defaultBackground = EditorColorsManager.getInstance().globalScheme.defaultBackground val attributesKey = RainbowHighlighter.updateScopeOutsideHighlightingAttributes(editor.colorsScheme)
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 highlighters = LinkedList<RangeHighlighter>() val highlighters = LinkedList<RangeHighlighter>()
val startOffset = rainbowInfo.startOffset val startOffset = rainbowInfo.startOffset
@@ -33,9 +26,9 @@ class ScopeOutsideHighlightingRestrainAction : AbstractScopeHighlightingAction()
this, this,
0, 0,
startOffset, startOffset,
attributes, //create("ScopeOutsideHighlightingRestrainAction", attributes), attributesKey,
false, //hideByTextChange false,
hideByAnyKey, //hideByAnyKey hideByAnyKey,
highlighters highlighters
) )
} }
@@ -47,14 +40,13 @@ class ScopeOutsideHighlightingRestrainAction : AbstractScopeHighlightingAction()
this, this,
endOffset, endOffset,
lastOffset, lastOffset,
attributes, //create("ScopeOutsideHighlightingRestrainAction", attributes), attributesKey,
false, //hideByTextChange false,
hideByAnyKey, //hideByAnyKey hideByAnyKey,
highlighters highlighters
) )
} }
return highlighters return highlighters
} }
} }
@@ -134,13 +134,14 @@ private fun matchColor(hueValue: Int, hue: Hue): Color {
hueVal -= 360 hueVal -= 360
} }
for (color in Color.values()) { for (color in Color.entries) {
if (hueVal in color.hueRange.first..color.hueRange.second) { if (hueVal in color.hueRange.first..color.hueRange.second) {
return color return color
} }
} }
// Returning Monochrome if we can't find a value, but this should never happen // Returning Monochrome if we can't find a value, but this should never happen
return Color.monochrome Color.monochrome
} }
} }
} }
@@ -18,8 +18,8 @@ import com.intellij.openapi.editor.impl.view.VisualLinesIterator
import com.intellij.openapi.editor.markup.CustomHighlighterRenderer import com.intellij.openapi.editor.markup.CustomHighlighterRenderer
import com.intellij.openapi.editor.markup.RangeHighlighter import com.intellij.openapi.editor.markup.RangeHighlighter
import com.intellij.openapi.util.Condition import com.intellij.openapi.util.Condition
import com.intellij.psi.PsiDocumentManager
import com.intellij.psi.PsiElement import com.intellij.psi.PsiElement
import com.intellij.psi.PsiManager
import com.intellij.psi.util.PsiTreeUtil import com.intellij.psi.util.PsiTreeUtil
import com.intellij.psi.xml.XmlFile import com.intellij.psi.xml.XmlFile
import com.intellij.psi.xml.XmlTag import com.intellij.psi.xml.XmlTag
@@ -36,13 +36,15 @@ import kotlin.math.max
* */ * */
class RainbowIndentGuideRenderer : CustomHighlighterRenderer { class RainbowIndentGuideRenderer : CustomHighlighterRenderer {
override fun paint(editor: Editor, highlighter: RangeHighlighter, g: Graphics) { override fun paint(editor: Editor, highlighter: RangeHighlighter, g: Graphics) {
if (editor !is EditorEx) return if (editor !is EditorEx) {
return
val rainbowInfo = getRainbowInfo(editor, highlighter) ?: return }
val startOffset = highlighter.startOffset val startOffset = highlighter.startOffset
val doc = highlighter.document val doc = highlighter.document
if (startOffset >= doc.textLength) return if (startOffset >= doc.textLength) {
return
}
val endOffset = highlighter.endOffset val endOffset = highlighter.endOffset
@@ -60,15 +62,21 @@ class RainbowIndentGuideRenderer : CustomHighlighterRenderer {
val startPosition = editor.offsetToVisualPosition(off) val startPosition = editor.offsetToVisualPosition(off)
val indentColumn = startPosition.column val indentColumn = startPosition.column
if (indentColumn <= 0) return if (indentColumn <= 0) {
return
}
val foldingModel = editor.foldingModel val foldingModel = editor.foldingModel
if (foldingModel.isOffsetCollapsed(off)) return if (foldingModel.isOffsetCollapsed(off)) {
return
}
val headerRegion = foldingModel.getCollapsedRegionAtOffset(doc.getLineEndOffset(doc.getLineNumber(off))) val headerRegion = foldingModel.getCollapsedRegionAtOffset(doc.getLineEndOffset(doc.getLineNumber(off)))
val tailRegion = foldingModel.getCollapsedRegionAtOffset(doc.getLineStartOffset(doc.getLineNumber(endOffset))) val tailRegion = foldingModel.getCollapsedRegionAtOffset(doc.getLineStartOffset(doc.getLineNumber(endOffset)))
if (tailRegion != null && tailRegion === headerRegion) return if (tailRegion != null && tailRegion === headerRegion) {
return
}
val guide = editor.indentsModel.caretIndentGuide val guide = editor.indentsModel.caretIndentGuide
val selected = if (guide != null) { val selected = if (guide != null) {
@@ -78,7 +86,7 @@ class RainbowIndentGuideRenderer : CustomHighlighterRenderer {
} }
else false else false
val lineHeight = editor.getLineHeight() val lineHeight = editor.lineHeight
val start = editor.visualPositionToXY(startPosition) val start = editor.visualPositionToXY(startPosition)
start.y += lineHeight start.y += lineHeight
val endPosition = editor.offsetToVisualPosition(endOffset) val endPosition = editor.offsetToVisualPosition(endOffset)
@@ -95,7 +103,11 @@ class RainbowIndentGuideRenderer : CustomHighlighterRenderer {
} }
maxY = StrictMath.min(maxY, clip.y + clip.height) maxY = StrictMath.min(maxY, clip.y + clip.height)
} }
if (start.y >= maxY) return if (start.y >= maxY) {
return
}
val rainbowInfo = getRainbowInfo(editor, highlighter) ?: return
val targetX = max(0, start.x + EditorPainter.getIndentGuideShift(editor)).toDouble() val targetX = max(0, start.x + EditorPainter.getIndentGuideShift(editor)).toDouble()
g.color = if (selected) { g.color = if (selected) {
rainbowInfo.color rainbowInfo.color
@@ -163,12 +175,11 @@ class RainbowIndentGuideRenderer : CustomHighlighterRenderer {
} }
private fun getRainbowInfo(editor: EditorEx, highlighter: RangeHighlighter): RainbowInfo? { private fun getRainbowInfo(editor: EditorEx, highlighter: RangeHighlighter): RainbowInfo? {
val virtualFile = editor.virtualFile?.takeIf { it.isValid } ?: return null
val document = editor.document
val project = editor.project ?: return null val project = editor.project ?: return null
val document = editor.document
return ReadAction.compute<RainbowInfo, Throwable> { return ReadAction.compute<RainbowInfo, Throwable> {
val psiFile = PsiManager.getInstance(project).findFile(virtualFile) ?: return@compute null val psiFile = PsiDocumentManager.getInstance(project).getPsiFile(document) ?: return@compute null
var element = try { var element = try {
psiFile.findElementAt(highlighter.endOffset)?.parent ?: return@compute null psiFile.findElementAt(highlighter.endOffset)?.parent ?: return@compute null
} catch (_: Throwable) { } catch (_: Throwable) {
@@ -269,6 +280,5 @@ class RainbowIndentGuideRenderer : CustomHighlighterRenderer {
private fun XmlTag.getEndTagStartLineNumber(document: Document): Int? = private fun XmlTag.getEndTagStartLineNumber(document: Document): Int? =
lastChild?.findPrevSibling(XML_END_TAG_START_CONDITION)?.let { document.lineNumber(it.startOffset) } lastChild?.findPrevSibling(XML_END_TAG_START_CONDITION)?.let { document.lineNumber(it.startOffset) }
} }
} }
@@ -46,7 +46,9 @@ class RainbowIndentsPass internal constructor(
override fun doCollectInformation(progress: ProgressIndicator) { override fun doCollectInformation(progress: ProgressIndicator) {
val stamp = myEditor.getUserData(LAST_TIME_INDENTS_BUILT) val stamp = myEditor.getUserData(LAST_TIME_INDENTS_BUILT)
if (stamp != null && stamp.toLong() == nowStamp()) return if (stamp != null && stamp == nowStamp()) {
return
}
myDescriptors = buildDescriptors() myDescriptors = buildDescriptors()
@@ -72,7 +74,9 @@ class RainbowIndentsPass internal constructor(
val stamp = myEditor.getUserData(LAST_TIME_INDENTS_BUILT) val stamp = myEditor.getUserData(LAST_TIME_INDENTS_BUILT)
val nowStamp = nowStamp() val nowStamp = nowStamp()
if (stamp == nowStamp) return if (stamp == nowStamp) {
return
}
myEditor.putUserData(LAST_TIME_INDENTS_BUILT, nowStamp) myEditor.putUserData(LAST_TIME_INDENTS_BUILT, nowStamp)
@@ -142,7 +146,9 @@ class RainbowIndentsPass internal constructor(
} }
private fun buildDescriptors(): List<IndentGuideDescriptor> { private fun buildDescriptors(): List<IndentGuideDescriptor> {
if (!isRainbowIndentGuidesShown(this.myProject)) return emptyList() if (!isRainbowIndentGuidesShown(this.myProject)) {
return emptyList()
}
val calculator = IndentsCalculator() val calculator = IndentsCalculator()
calculator.calculate() calculator.calculate()
@@ -17,7 +17,7 @@ class RainbowConfigurable : SearchableConfigurable {
} }
override fun isModified(): Boolean { override fun isModified(): Boolean {
return settingsForm?.isModified ?: return false return settingsForm?.isModified ?: false
} }
@Throws(ConfigurationException::class) @Throws(ConfigurationException::class)
@@ -49,7 +49,7 @@ class RainbowConfigurable : SearchableConfigurable {
settings.rainbowifyPythonKeywords = settingsForm?.rainbowifyPythonKeywords() ?: false settings.rainbowifyPythonKeywords = settingsForm?.rainbowifyPythonKeywords() ?: false
ProjectManager.getInstanceIfCreated()?.openProjects?.forEach { ProjectManager.getInstanceIfCreated()?.openProjects?.forEach {
DaemonCodeAnalyzer.getInstance(it).restart() DaemonCodeAnalyzer.getInstance(it).restart(this)
} }
} }
@@ -39,7 +39,7 @@ class RainbowOptionsPanel(
private lateinit var colorLabel4: JLabel private lateinit var colorLabel4: JLabel
private lateinit var colorLabel5: JLabel private lateinit var colorLabel5: JLabel
private val colorLabels: Array<JLabel> private val colorLabels = arrayOf(colorLabel1, colorLabel2, colorLabel3, colorLabel4, colorLabel5)
private lateinit var color1: ColorPanel private lateinit var color1: ColorPanel
private lateinit var color2: ColorPanel private lateinit var color2: ColorPanel
@@ -47,7 +47,7 @@ class RainbowOptionsPanel(
private lateinit var color4: ColorPanel private lateinit var color4: ColorPanel
private lateinit var color5: ColorPanel private lateinit var color5: ColorPanel
private val colors: Array<ColorPanel> private val colors = arrayOf(color1, color2, color3, color4, color5)
private lateinit var gradientLabel: JLabel private lateinit var gradientLabel: JLabel
@@ -56,9 +56,6 @@ class RainbowOptionsPanel(
EventDispatcher.create(ColorAndFontSettingsListener::class.java) EventDispatcher.create(ColorAndFontSettingsListener::class.java)
init { init {
colors = arrayOf(color1, color2, color3, color4, color5)
colorLabels = arrayOf(colorLabel1, colorLabel2, colorLabel3, colorLabel4, colorLabel5)
val actionListener = ActionListener { val actionListener = ActionListener {
eventDispatcher.multicaster.settingsChanged() eventDispatcher.multicaster.settingsChanged()
options.stateChanged() options.stateChanged()
@@ -70,7 +67,9 @@ class RainbowOptionsPanel(
options.addListener(object : ColorAndFontSettingsListener.Abstract() { options.addListener(object : ColorAndFontSettingsListener.Abstract() {
override fun settingsChanged() { override fun settingsChanged() {
if (!schemesProvider.areSchemesLoaded()) return if (!schemesProvider.areSchemesLoaded()) {
return
}
if (optionsTree.selectedValue != null) { if (optionsTree.selectedValue != null) {
// update options after global state change // update options after global state change
processListValueChanged() processListValueChanged()
@@ -236,7 +235,9 @@ class RainbowOptionsPanel(
} }
val pathInChild = findOption(childObject, matcher) val pathInChild = findOption(childObject, matcher)
if (pathInChild != null) return pathInChild if (pathInChild != null) {
return pathInChild
}
} }
return null return null
@@ -18,6 +18,11 @@
]]></description> ]]></description>
<change-notes><![CDATA[ <change-notes><![CDATA[
<b>Version 1.4.0</b>
<ul>
<li>Updated to IntelliJ Platform 2025.3.</li>
<li>Removed support for the Haskell plugin, since it is no longer available.</li>
</ul>
<b>Version 1.3.0</b> <b>Version 1.3.0</b>
<ul> <ul>
<li>Fixed assertion error caused by missing read lock in indent guide renderer.</li> <li>Fixed assertion error caused by missing read lock in indent guide renderer.</li>
@@ -38,7 +43,7 @@
<ul> <ul>
<li>Restored support for CLion and Rider.</li> <li>Restored support for CLion and Rider.</li>
<li>Added support for Settings Sync.</li> <li>Added support for Settings Sync.</li>
<li>Fixed service initialization warnings reported by IJ 2024.2.</li> <li>Fixed service initialization warnings reported by IntelliJ Platform 2024.2.</li>
</ul> </ul>
]]></change-notes> ]]></change-notes>
@@ -22,10 +22,7 @@ void main() {
PsiDocumentManager.getInstance(project).commitAllDocuments() PsiDocumentManager.getInstance(project).commitAllDocuments()
val doHighlighting = myFixture.doHighlighting() val doHighlighting = myFixture.doHighlighting()
assertFalse(doHighlighting.isEmpty()) assertFalse(doHighlighting.isEmpty())
doHighlighting doHighlighting.getBrackets().shouldBe(
.map { it.forcedTextAttributesKey.defaultAttributes.foregroundColor }
.toTypedArray()
.shouldBe(
arrayOf( arrayOf(
roundLevel(0), roundLevel(0),
angleLevel(0), angleLevel(0),
@@ -22,10 +22,7 @@ Map<String, Map<String, String>> convertObjectsToMapProperties(Map<String, Objec
PsiDocumentManager.getInstance(project).commitAllDocuments() PsiDocumentManager.getInstance(project).commitAllDocuments()
val doHighlighting = myFixture.doHighlighting() val doHighlighting = myFixture.doHighlighting()
assertFalse(doHighlighting.isEmpty()) assertFalse(doHighlighting.isEmpty())
doHighlighting.filter { brackets.contains(it.text.toChar()) } doHighlighting.getBrackets().shouldBe(
.map { it.forcedTextAttributesKey.defaultAttributes.foregroundColor }
.toTypedArray()
.shouldBe(
arrayOf( arrayOf(
angleLevel(0), angleLevel(0),
angleLevel(1), angleLevel(1),
@@ -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})\nopen (${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)
)
)
}
}
@@ -35,10 +35,7 @@ public class Test<T> {
PsiDocumentManager.getInstance(project).commitAllDocuments() PsiDocumentManager.getInstance(project).commitAllDocuments()
val doHighlighting = myFixture.doHighlighting() val doHighlighting = myFixture.doHighlighting()
assertFalse(doHighlighting.isEmpty()) assertFalse(doHighlighting.isEmpty())
doHighlighting.filter { brackets.contains(it.text.toChar()) } doHighlighting.getBrackets().shouldBe(
.map { it.forcedTextAttributesKey.defaultAttributes.foregroundColor }
.toTypedArray()
.shouldBe(
arrayOf( arrayOf(
angleLevel(0), angleLevel(0),
angleLevel(0), angleLevel(0),
@@ -75,10 +72,7 @@ public class Test<T> {
PsiDocumentManager.getInstance(project).commitAllDocuments() PsiDocumentManager.getInstance(project).commitAllDocuments()
val doHighlighting = myFixture.doHighlighting() val doHighlighting = myFixture.doHighlighting()
assertFalse(doHighlighting.isEmpty()) assertFalse(doHighlighting.isEmpty())
doHighlighting.filter { brackets.contains(it.text.toChar()) } doHighlighting.getBrackets().shouldBe(
.map { it.forcedTextAttributesKey.defaultAttributes.foregroundColor }
.toTypedArray()
.shouldBe(
arrayOf() arrayOf()
) )
} }
@@ -98,10 +92,7 @@ public class Test<T> {
PsiDocumentManager.getInstance(project).commitAllDocuments() PsiDocumentManager.getInstance(project).commitAllDocuments()
val doHighlighting = myFixture.doHighlighting() val doHighlighting = myFixture.doHighlighting()
assertFalse(doHighlighting.isEmpty()) assertFalse(doHighlighting.isEmpty())
doHighlighting.filter { brackets.contains(it.text.toChar()) } doHighlighting.getBrackets().shouldBe(
.map { it.forcedTextAttributesKey.defaultAttributes.foregroundColor }
.toTypedArray()
.shouldBe(
arrayOf( arrayOf(
squigglyLevel(0), squigglyLevel(0),
roundLevel(0), roundLevel(0),
@@ -136,10 +127,7 @@ public class Test<T> {
PsiDocumentManager.getInstance(project).commitAllDocuments() PsiDocumentManager.getInstance(project).commitAllDocuments()
val doHighlighting = myFixture.doHighlighting() val doHighlighting = myFixture.doHighlighting()
assertFalse(doHighlighting.isEmpty()) assertFalse(doHighlighting.isEmpty())
doHighlighting.filter { brackets.contains(it.text.toChar()) } doHighlighting.getBrackets().shouldBe(
.map { it.forcedTextAttributesKey.defaultAttributes.foregroundColor }
.toTypedArray()
.shouldBe(
arrayOf( arrayOf(
angleLevel(0), angleLevel(0),
angleLevel(0), angleLevel(0),
@@ -166,10 +154,7 @@ public class Test<T> {
PsiDocumentManager.getInstance(project).commitAllDocuments() PsiDocumentManager.getInstance(project).commitAllDocuments()
val doHighlighting = myFixture.doHighlighting() val doHighlighting = myFixture.doHighlighting()
assertFalse(doHighlighting.isEmpty()) assertFalse(doHighlighting.isEmpty())
doHighlighting.filter { brackets.contains(it.text.toChar()) } doHighlighting.getBrackets().shouldBe(
.map { it.forcedTextAttributesKey.defaultAttributes.foregroundColor }
.toTypedArray()
.shouldBe(
arrayOf( arrayOf(
angleLevel(0), angleLevel(0),
angleLevel(0), angleLevel(0),
@@ -202,10 +187,7 @@ public class Test<T> {
PsiDocumentManager.getInstance(project).commitAllDocuments() PsiDocumentManager.getInstance(project).commitAllDocuments()
val doHighlighting = myFixture.doHighlighting() val doHighlighting = myFixture.doHighlighting()
assertFalse(doHighlighting.isEmpty()) assertFalse(doHighlighting.isEmpty())
doHighlighting.filter { brackets.contains(it.text.toChar()) } doHighlighting.getBrackets().shouldBe(
.map { it.forcedTextAttributesKey.defaultAttributes.foregroundColor }
.toTypedArray()
.shouldBe(
arrayOf( arrayOf(
angleLevel(0), angleLevel(0),
angleLevel(0), angleLevel(0),
@@ -239,11 +221,7 @@ public class Test<T> {
PsiDocumentManager.getInstance(project).commitAllDocuments() PsiDocumentManager.getInstance(project).commitAllDocuments()
val doHighlighting = myFixture.doHighlighting() val doHighlighting = myFixture.doHighlighting()
assertFalse(doHighlighting.isEmpty()) assertFalse(doHighlighting.isEmpty())
doHighlighting.filter { brackets.contains(it.text.toChar()) } doHighlighting.getBrackets().size.shouldBe(0)
.map { it.forcedTextAttributesKey.defaultAttributes.foregroundColor }
.toTypedArray()
.size
.shouldBe(0)
} }
fun testIssue391() { fun testIssue391() {
@@ -262,10 +240,7 @@ public class Test {
PsiDocumentManager.getInstance(project).commitAllDocuments() PsiDocumentManager.getInstance(project).commitAllDocuments()
val doHighlighting = myFixture.doHighlighting() val doHighlighting = myFixture.doHighlighting()
assertFalse(doHighlighting.isEmpty()) assertFalse(doHighlighting.isEmpty())
doHighlighting.filter { brackets.contains(it.text.toChar()) } doHighlighting.getBrackets().shouldBe(
.map { it.forcedTextAttributesKey.defaultAttributes.foregroundColor }
.toTypedArray()
.shouldBe(
arrayOf( arrayOf(
roundLevel(0),//{ roundLevel(0),//{
@@ -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)
)
)
}
}
@@ -1,6 +1,5 @@
package com.chylex.intellij.coloredbrackets package com.chylex.intellij.coloredbrackets
import com.intellij.codeInsight.daemon.impl.HighlightInfoType
import com.intellij.psi.PsiDocumentManager import com.intellij.psi.PsiDocumentManager
import com.intellij.testFramework.fixtures.LightJavaCodeInsightFixtureTestCase import com.intellij.testFramework.fixtures.LightJavaCodeInsightFixtureTestCase
import com.jetbrains.php.lang.PhpFileType import com.jetbrains.php.lang.PhpFileType
@@ -28,10 +27,7 @@ function padZero(string data): string
PsiDocumentManager.getInstance(project).commitAllDocuments() PsiDocumentManager.getInstance(project).commitAllDocuments()
val doHighlighting = myFixture.doHighlighting() val doHighlighting = myFixture.doHighlighting()
assertFalse(doHighlighting.isEmpty()) assertFalse(doHighlighting.isEmpty())
doHighlighting.filter { brackets.contains(it.text.toChar()) && it.severity != HighlightInfoType.INJECTED_FRAGMENT_SEVERITY } doHighlighting.getBrackets().shouldBe(
.map { it.forcedTextAttributesKey.defaultAttributes.foregroundColor }
.toTypedArray()
.shouldBe(
arrayOf( arrayOf(
roundLevel(0), roundLevel(0),
roundLevel(0), roundLevel(0),
@@ -10,7 +10,7 @@ import org.jetbrains.plugins.ruby.ruby.lang.RubyFileType
class RainbowRubyTest : LightJavaCodeInsightFixtureTestCase() { class RainbowRubyTest : LightJavaCodeInsightFixtureTestCase() {
fun testRubyPluginEnabled() { fun testRubyPluginEnabled() {
assertTrue(PluginManagerCore.getPlugin(PluginId.getId("org.jetbrains.plugins.ruby"))?.isEnabled!!) assertTrue(PluginManagerCore.isLoaded(PluginId("org.jetbrains.plugins.ruby")))
} }
fun testRainbowForIssue53Part0() { fun testRainbowForIssue53Part0() {
@@ -24,10 +24,7 @@ end
PsiDocumentManager.getInstance(project).commitAllDocuments() PsiDocumentManager.getInstance(project).commitAllDocuments()
val doHighlighting = myFixture.doHighlighting() val doHighlighting = myFixture.doHighlighting()
assertFalse(doHighlighting.isEmpty()) assertFalse(doHighlighting.isEmpty())
doHighlighting.filter { brackets.contains(it.text.toChar()) } doHighlighting.getBrackets().shouldBe(
.map { it.forcedTextAttributesKey.defaultAttributes.foregroundColor }
.toTypedArray()
.shouldBe(
arrayOf( arrayOf(
roundLevel(0), roundLevel(0),
roundLevel(1), roundLevel(1),
@@ -46,10 +43,7 @@ foobar(p1: "", p2: false, p3: 1)
PsiDocumentManager.getInstance(project).commitAllDocuments() PsiDocumentManager.getInstance(project).commitAllDocuments()
val doHighlighting = myFixture.doHighlighting() val doHighlighting = myFixture.doHighlighting()
assertFalse(doHighlighting.isEmpty()) assertFalse(doHighlighting.isEmpty())
doHighlighting.filter { brackets.contains(it.text.toChar()) } doHighlighting.getBrackets().shouldBe(
.map { it.forcedTextAttributesKey.defaultAttributes.foregroundColor }
.toTypedArray()
.shouldBe(
arrayOf( arrayOf(
roundLevel(0), roundLevel(0),
roundLevel(0) roundLevel(0)
@@ -71,12 +65,7 @@ end
PsiDocumentManager.getInstance(project).commitAllDocuments() PsiDocumentManager.getInstance(project).commitAllDocuments()
val doHighlighting = myFixture.doHighlighting() val doHighlighting = myFixture.doHighlighting()
assertFalse(doHighlighting.isEmpty()) assertFalse(doHighlighting.isEmpty())
doHighlighting doHighlighting.getBrackets().shouldBe(
.filter { brackets.contains(it.text.toChar()) }
.filterNot { it?.forcedTextAttributesKey?.defaultAttributes == null }
.map { it.forcedTextAttributesKey.defaultAttributes.foregroundColor }
.toTypedArray()
.shouldBe(
arrayOf( arrayOf(
roundLevel(0), roundLevel(0),
squigglyLevel(0), squigglyLevel(0),
@@ -109,12 +98,7 @@ end
PsiDocumentManager.getInstance(project).commitAllDocuments() PsiDocumentManager.getInstance(project).commitAllDocuments()
val doHighlighting = myFixture.doHighlighting() val doHighlighting = myFixture.doHighlighting()
assertFalse(doHighlighting.isEmpty()) assertFalse(doHighlighting.isEmpty())
doHighlighting doHighlighting.getBrackets().shouldBe(
.filter { brackets.contains(it.text.toChar()) }
.filterNot { it?.forcedTextAttributesKey?.defaultAttributes == null }
.map { it.forcedTextAttributesKey.defaultAttributes.foregroundColor }
.toTypedArray()
.shouldBe(
arrayOf( arrayOf(
squareLevel(0), squareLevel(0),
squareLevel(0), squareLevel(0),
@@ -135,12 +119,7 @@ end
PsiDocumentManager.getInstance(project).commitAllDocuments() PsiDocumentManager.getInstance(project).commitAllDocuments()
val doHighlighting = myFixture.doHighlighting() val doHighlighting = myFixture.doHighlighting()
assertFalse(doHighlighting.isEmpty()) assertFalse(doHighlighting.isEmpty())
doHighlighting doHighlighting.getBrackets().shouldBe(
.filter { brackets.contains(it.text.toChar()) }
.filterNot { it?.forcedTextAttributesKey?.defaultAttributes == null }
.map { it.forcedTextAttributesKey.defaultAttributes.foregroundColor }
.toTypedArray()
.shouldBe(
arrayOf( arrayOf(
squareLevel(0), squareLevel(0),
squareLevel(1), squareLevel(1),
@@ -6,7 +6,9 @@ import com.intellij.testFramework.fixtures.LightJavaCodeInsightFixtureTestCase
import io.kotest.matchers.shouldBe import io.kotest.matchers.shouldBe
import org.intellij.lang.annotations.Language import org.intellij.lang.annotations.Language
import org.jetbrains.plugins.scala.ScalaFileType import org.jetbrains.plugins.scala.ScalaFileType
import org.junit.Ignore
@Ignore("IDEA has broken modularization")
class RainbowScalaTest : LightJavaCodeInsightFixtureTestCase() { class RainbowScalaTest : LightJavaCodeInsightFixtureTestCase() {
override fun tearDown() { override fun tearDown() {
@@ -36,11 +38,7 @@ import scala.annotation.tailrec
PsiDocumentManager.getInstance(project).commitAllDocuments() PsiDocumentManager.getInstance(project).commitAllDocuments()
val doHighlighting = myFixture.doHighlighting() val doHighlighting = myFixture.doHighlighting()
assertFalse(doHighlighting.isEmpty()) assertFalse(doHighlighting.isEmpty())
doHighlighting.filter { brackets.contains(it.text.toChar()) } doHighlighting.getBrackets().shouldBe(
.filter { it?.forcedTextAttributesKey != null }
.map { it.forcedTextAttributesKey.defaultAttributes.foregroundColor }
.toTypedArray()
.shouldBe(
arrayOf( arrayOf(
squareLevel(0), squareLevel(0),
squareLevel(0), squareLevel(0),
@@ -78,11 +76,7 @@ import scala.annotation.tailrec
PsiDocumentManager.getInstance(project).commitAllDocuments() PsiDocumentManager.getInstance(project).commitAllDocuments()
val doHighlighting = myFixture.doHighlighting() val doHighlighting = myFixture.doHighlighting()
assertFalse(doHighlighting.isEmpty()) assertFalse(doHighlighting.isEmpty())
doHighlighting.filter { brackets.contains(it.text.toChar()) } doHighlighting.getBrackets().shouldBe(
.filter { it?.forcedTextAttributesKey != null }
.map { it.forcedTextAttributesKey.defaultAttributes.foregroundColor }
.toTypedArray()
.shouldBe(
arrayOf( arrayOf(
roundLevel(0), roundLevel(0),
@@ -0,0 +1,71 @@
package com.chylex.intellij.coloredbrackets
import com.chylex.intellij.coloredbrackets.settings.RainbowSettings
import com.intellij.ide.highlighter.XmlFileType
import com.intellij.psi.PsiDocumentManager
import com.intellij.testFramework.fixtures.LightJavaCodeInsightFixtureTestCase
import io.kotest.matchers.shouldBe
import org.intellij.lang.annotations.Language
class RainbowXMLTest : LightJavaCodeInsightFixtureTestCase() {
fun testRainbowForXML() {
@Language("XML") val code =
"""
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE note SYSTEM>
<idea-plugin>
<name>Rainbow Brackets</name>
<description>
<p>Supported languages:</p>
<p>Java, Scala, Clojure, Kotlin, Python, Haskell, Agda, Rust, JavaScript, TypeScript, Erlang, Go, Groovy, Ruby, Elixir, ObjectiveC, PHP, C#, HTML, XML, SQL, Apex language ...</p>
<br/>
</description>
</idea-plugin>
""".trimIndent()
val rainbowSettings = RainbowSettings.instance
rainbowSettings.rainbowifyTagNameInXML = false
myFixture.configureByText(XmlFileType.INSTANCE, code)
PsiDocumentManager.getInstance(project).commitAllDocuments()
val doHighlighting = myFixture.doHighlighting()
assertFalse(doHighlighting.isEmpty())
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)
)
)
}
}
@@ -25,11 +25,7 @@ public class Test<T> {
PsiDocumentManager.getInstance(project).commitAllDocuments() PsiDocumentManager.getInstance(project).commitAllDocuments()
val doHighlighting = myFixture.doHighlighting() val doHighlighting = myFixture.doHighlighting()
assertFalse(doHighlighting.isEmpty()) assertFalse(doHighlighting.isEmpty())
val highlightSize = doHighlighting.filter { brackets.contains(it.text.toChar()) } val highlightSize = doHighlighting.getBrackets().size
.filter { it.forcedTextAttributesKey.defaultAttributes.foregroundColor != null }
.map { it.forcedTextAttributesKey.defaultAttributes.foregroundColor }
.toTypedArray()
.size
assert(highlightSize == 16) assert(highlightSize == 16)
} }
@@ -1,8 +1,15 @@
package com.chylex.intellij.coloredbrackets 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) fun roundLevel(level: Int) = RainbowHighlighter.getRainbowColor(RainbowHighlighter.NAME_ROUND_BRACKETS, level)
+12 -31
View File
@@ -1,16 +1,14 @@
@file:Suppress("ConvertLambdaToReference") @file:Suppress("ConvertLambdaToReference")
import org.jetbrains.intellij.platform.gradle.TestFrameworkType
plugins { plugins {
kotlin("jvm") kotlin("jvm")
id("org.jetbrains.intellij.platform") id("org.jetbrains.intellij.platform")
} }
group = "com.chylex.intellij.coloredbrackets" group = "com.chylex.intellij.coloredbrackets"
version = "1.3.0" version = "1.4.0"
val ideaVersion = "2023.3" val ideaVersion = "2025.3"
allprojects { allprojects {
apply(plugin = "org.jetbrains.kotlin.jvm") apply(plugin = "org.jetbrains.kotlin.jvm")
@@ -29,9 +27,11 @@ allprojects {
} }
intellijPlatform { intellijPlatform {
sandboxContainer.set(layout.buildDirectory.map { it.dir("idea-sandbox") })
pluginConfiguration { pluginConfiguration {
ideaVersion { ideaVersion {
sinceBuild.set("233") sinceBuild.set("253")
untilBuild.set(provider { null }) untilBuild.set(provider { null })
} }
} }
@@ -49,6 +49,8 @@ allprojects {
} }
subprojects { subprojects {
version = rootProject.version
intellijPlatform { intellijPlatform {
buildSearchableOptions = false buildSearchableOptions = false
} }
@@ -56,46 +58,25 @@ subprojects {
idea { idea {
module { module {
excludeDirs.add(file(".kotlin"))
excludeDirs.add(file("build")) excludeDirs.add(file("build"))
excludeDirs.add(file("gradle")) excludeDirs.add(file("gradle"))
} }
} }
dependencies { dependencies {
project(":api")
intellijPlatform { intellijPlatform {
@Suppress("DEPRECATION") @Suppress("DEPRECATION")
intellijIdeaUltimate(ideaVersion) intellijIdeaUltimate(ideaVersion)
bundledPlugin("JavaScript") pluginComposedModule(implementation(project(":base")))
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(":clion"))) pluginComposedModule(implementation(project(":clion")))
pluginComposedModule(implementation(project(":rider"))) pluginComposedModule(implementation(project(":rider")))
} }
}
testImplementation("junit:junit:4.13.2") intellijPlatform {
testImplementation("io.kotest:kotest-assertions-core:5.8.0") { buildSearchableOptions.set(true)
exclude(group = "org.jetbrains.kotlin")
}
} }
tasks.test { tasks.test {
+4 -2
View File
@@ -1,12 +1,14 @@
val ideaVersion: String by project val ideaVersion: String by project
dependencies { dependencies {
implementation(project(":api")) implementation(project(":base"))
runtimeOnly(project(":rider")) // Support for CLion Nova.
intellijPlatform { intellijPlatform {
clion(ideaVersion) clion(ideaVersion)
bundledPlugin("com.intellij.clion") 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.
+3 -1
View File
@@ -1,7 +1,9 @@
distributionBase=GRADLE_USER_HOME distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists 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 networkTimeout=10000
retries=0
retryBackOffMs=500
validateDistributionUrl=true validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists zipStorePath=wrapper/dists
Vendored
+7 -8
View File
@@ -1,7 +1,7 @@
#!/bin/sh #!/bin/sh
# #
# Copyright © 2015-2021 the original authors. # Copyright © 2015 the original authors.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with 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 # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
# #
# SPDX-License-Identifier: Apache-2.0
#
############################################################################## ##############################################################################
# #
@@ -55,7 +57,7 @@
# Darwin, MinGW, and NonStop. # Darwin, MinGW, and NonStop.
# #
# (3) This script is generated from the Groovy template # (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. # within the Gradle project.
# #
# You can find Gradle at https://github.com/gradle/gradle/. # You can find Gradle at https://github.com/gradle/gradle/.
@@ -84,7 +86,7 @@ done
# shellcheck disable=SC2034 # shellcheck disable=SC2034
APP_BASE_NAME=${0##*/} APP_BASE_NAME=${0##*/}
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) # 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. # Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum MAX_FD=maximum
@@ -112,7 +114,6 @@ case "$( uname )" in #(
NONSTOP* ) nonstop=true ;; NONSTOP* ) nonstop=true ;;
esac esac
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
# Determine the Java command to use to start the JVM. # 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 # For Cygwin or MSYS, switch paths to Windows format before running java
if "$cygwin" || "$msys" ; then if "$cygwin" || "$msys" ; then
APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
JAVACMD=$( cygpath --unix "$JAVACMD" ) JAVACMD=$( cygpath --unix "$JAVACMD" )
@@ -203,15 +203,14 @@ fi
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
# Collect all arguments for the java command: # 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. # 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 # * 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. # treated as '${Hostname}' itself on the command line.
set -- \ set -- \
"-Dorg.gradle.appname=$APP_BASE_NAME" \ "-Dorg.gradle.appname=$APP_BASE_NAME" \
-classpath "$CLASSPATH" \ -jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \
org.gradle.wrapper.GradleWrapperMain \
"$@" "$@"
# Stop when "xargs" is not available. # Stop when "xargs" is not available.
Vendored
+22 -32
View File
@@ -13,6 +13,8 @@
@rem See the License for the specific language governing permissions and @rem See the License for the specific language governing permissions and
@rem limitations under the License. @rem limitations under the License.
@rem @rem
@rem SPDX-License-Identifier: Apache-2.0
@rem
@if "%DEBUG%"=="" @echo off @if "%DEBUG%"=="" @echo off
@rem ########################################################################## @rem ##########################################################################
@@ -21,8 +23,8 @@
@rem @rem
@rem ########################################################################## @rem ##########################################################################
@rem Set local scope for the variables with windows NT shell @rem Set local scope for the variables, and ensure extensions are enabled
if "%OS%"=="Windows_NT" setlocal setlocal EnableExtensions
set DIRNAME=%~dp0 set DIRNAME=%~dp0
if "%DIRNAME%"=="" set DIRNAME=. if "%DIRNAME%"=="" set DIRNAME=.
@@ -43,13 +45,13 @@ set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1 %JAVA_EXE% -version >NUL 2>&1
if %ERRORLEVEL% equ 0 goto execute if %ERRORLEVEL% equ 0 goto execute
echo. echo. 1>&2
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
echo. echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. echo location of your Java installation. 1>&2
goto fail "%COMSPEC%" /c exit 1
:findJavaFromJavaHome :findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=% set JAVA_HOME=%JAVA_HOME:"=%
@@ -57,36 +59,24 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto execute if exist "%JAVA_EXE%" goto execute
echo. echo. 1>&2
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
echo. echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. echo location of your Java installation. 1>&2
goto fail "%COMSPEC%" /c exit 1
:execute :execute
@rem Setup the command line @rem Setup the command line
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
@rem Execute Gradle @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 :exitWithErrorLevel
@rem End local scope for the variables with windows NT shell @rem Use "%COMSPEC%" /c exit to allow operators to work properly in scripts
if %ERRORLEVEL% equ 0 goto mainEnd "%COMSPEC%" /c exit %ERRORLEVEL%
: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
+3 -1
View File
@@ -1,11 +1,13 @@
val ideaVersion: String by project val ideaVersion: String by project
dependencies { dependencies {
implementation(project(":api")) implementation(project(":base"))
intellijPlatform { intellijPlatform {
rider(ideaVersion) { rider(ideaVersion) {
useInstaller = false useInstaller = false
} }
bundledModule("intellij.rider.cpp.core.languages")
} }
} }
+5 -5
View File
@@ -2,11 +2,11 @@ rootProject.name = "ColoredBrackets"
pluginManagement { pluginManagement {
plugins { plugins {
kotlin("jvm") version "1.9.21" kotlin("jvm") version "2.2.20"
id("org.jetbrains.intellij.platform") version "2.9.0" id("org.jetbrains.intellij.platform") version "2.18.1"
} }
} }
include("api") include(":base")
include("clion") include(":clion")
include("rider") include(":rider")
@@ -1,123 +0,0 @@
package com.chylex.intellij.coloredbrackets.annotator
import com.chylex.intellij.coloredbrackets.RainbowHighlighter.NAME_ANGLE_BRACKETS
import com.chylex.intellij.coloredbrackets.RainbowHighlighter.NAME_ROUND_BRACKETS
import com.chylex.intellij.coloredbrackets.RainbowHighlighter.NAME_SQUARE_BRACKETS
import com.chylex.intellij.coloredbrackets.RainbowHighlighter.NAME_SQUIGGLY_BRACKETS
import com.chylex.intellij.coloredbrackets.RainbowHighlighter.getRainbowColorByLevel
import com.chylex.intellij.coloredbrackets.annotator.RainbowUtils.annotateUtil
import com.chylex.intellij.coloredbrackets.annotator.RainbowUtils.settings
import com.chylex.intellij.coloredbrackets.settings.RainbowSettings
import com.intellij.lang.annotation.AnnotationHolder
import com.intellij.lang.annotation.Annotator
import com.intellij.lang.annotation.HighlightSeverity
import com.intellij.openapi.editor.colors.EditorColorsManager
import com.intellij.psi.PsiElement
import com.intellij.psi.PsiFile
import com.intellij.psi.impl.source.tree.LeafPsiElement
class RainbowAnnotator : Annotator {
override fun annotate(element: PsiElement, holder: AnnotationHolder) {
val settings = settings
if (settings.isRainbowEnabled && element is LeafPsiElement) {
if (!settings.applyColorsOfRoundForAllBrackets) {
if (settings.isEnableRainbowRoundBrackets) annotateUtil(element, holder, "(", ")", NAME_ROUND_BRACKETS)
if (settings.isEnableRainbowSquareBrackets) annotateUtil(element, holder, "[", "]", NAME_SQUARE_BRACKETS)
if (settings.isEnableRainbowSquigglyBrackets) annotateUtil(element, holder, "{", "}", NAME_SQUIGGLY_BRACKETS)
if (settings.isEnableRainbowAngleBrackets) annotateUtil(element, holder, "<", ">", NAME_ANGLE_BRACKETS)
}
else {
if (settings.isEnableRainbowRoundBrackets) annotateUtil(element, holder, "(", ")", NAME_ROUND_BRACKETS)
if (settings.isEnableRainbowSquareBrackets) annotateUtil(element, holder, "[", "]", NAME_ROUND_BRACKETS)
if (settings.isEnableRainbowSquigglyBrackets) annotateUtil(element, holder, "{", "}", NAME_ROUND_BRACKETS)
if (settings.isEnableRainbowAngleBrackets) annotateUtil(element, holder, "<", ">", NAME_ROUND_BRACKETS)
}
}
}
}
object RainbowUtils {
private val leftBracketsSet = setOf("(", "[", "{", "<")
private val rightBracketsSet = setOf(")", "]", "}", ">")
val settings
get() = RainbowSettings.instance
private tailrec fun iterateChildren(
LEFT: String,
RIGHT: String,
currentNode: PsiElement,
currentLevel: Int,
currentChild: PsiElement,
): Int {
val calculatedLevel = if (currentChild is LeafPsiElement) {
//Using `currentChild.elementType.toString()` if we didn't want add more dependencies.
if (!settings.cycleCountOnAllBrackets) {
when (currentChild.text) {
LEFT -> currentLevel + 1
RIGHT -> currentLevel - 1
else -> currentLevel
}
}
else {
when {
leftBracketsSet.contains(currentChild.text) -> currentLevel + 1
rightBracketsSet.contains(currentChild.text) -> currentLevel - 1
else -> currentLevel
}
}
}
else currentLevel
return if ((currentChild != currentNode) && (currentChild != currentNode.parent.lastChild))
iterateChildren(LEFT, RIGHT, currentNode, calculatedLevel, currentChild.nextSibling)
else
calculatedLevel
}
private tailrec fun iterateParents(
LEFT: String,
RIGHT: String,
currentNode: PsiElement,
currentLevel: Int,
): Int = if (currentNode.parent !is PsiFile) {
val calculatedLevel = iterateChildren(LEFT, RIGHT, currentNode, currentLevel, currentNode.parent.firstChild)
iterateParents(LEFT, RIGHT, currentNode.parent, calculatedLevel)
}
else currentLevel
private fun getBracketLevel(element: LeafPsiElement, LEFT: String, RIGHT: String): Int {
//Using `element.elementType.toString()` if we didn't want add more dependencies.
val startLevel = if (element.text == RIGHT) 0 else -1
return iterateParents(LEFT, RIGHT, element, startLevel)
}
fun annotateUtil(
element: LeafPsiElement, holder: AnnotationHolder,
LEFT: String, RIGHT: String, rainbowName: String,
) {
//Using `element.elementType.toString()` if we didn't want add more dependencies.
val level = when (element.text) {
LEFT, RIGHT -> getBracketLevel(element, LEFT, RIGHT)
else -> -1
}
val scheme = EditorColorsManager.getInstance().globalScheme
if (RainbowSettings.instance.isDoNOTRainbowifyTheFirstLevel) {
if (level >= 1) {
holder.newSilentAnnotation(HighlightSeverity.INFORMATION)
.range(element.psi)
.textAttributes(getRainbowColorByLevel(scheme, rainbowName, level))
.create()
}
}
else {
if (level >= 0) {
holder.newSilentAnnotation(HighlightSeverity.INFORMATION)
.range(element.psi)
.textAttributes(getRainbowColorByLevel(scheme, rainbowName, level))
.create()
}
}
}
}
@@ -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)
)
)
}
}
@@ -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)
)
)
}
}
@@ -1,149 +0,0 @@
package com.chylex.intellij.coloredbrackets
import com.chylex.intellij.coloredbrackets.settings.RainbowSettings
import com.intellij.ide.highlighter.XmlFileType
import com.intellij.psi.PsiDocumentManager
import com.intellij.testFramework.fixtures.LightJavaCodeInsightFixtureTestCase
import io.kotest.matchers.shouldBe
import org.intellij.lang.annotations.Language
class RainbowXMLTest : LightJavaCodeInsightFixtureTestCase() {
fun `disabled for non-determinist results of testRainbowTagNameForXML`() {
@Language("XML") val code =
"""
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE note SYSTEM>
<idea-plugin>
<name>Rainbow Brackets</name>
<description>
<p>Supported languages:</p>
<p>Java, Scala, Clojure, Kotlin, Python, Haskell, Agda, Rust, JavaScript, TypeScript, Erlang, Go, Groovy, Ruby, Elixir, ObjectiveC, PHP, C#, HTML, XML, SQL, Apex language ...</p>
<br/>
</description>
</idea-plugin>
""".trimIndent()
val rainbowSettings = RainbowSettings.instance
rainbowSettings.rainbowifyTagNameInXML = true
myFixture.configureByText(XmlFileType.INSTANCE, code)
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)
)
)
}
fun testRainbowForXML() {
@Language("XML") val code =
"""
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE note SYSTEM>
<idea-plugin>
<name>Rainbow Brackets</name>
<description>
<p>Supported languages:</p>
<p>Java, Scala, Clojure, Kotlin, Python, Haskell, Agda, Rust, JavaScript, TypeScript, Erlang, Go, Groovy, Ruby, Elixir, ObjectiveC, PHP, C#, HTML, XML, SQL, Apex language ...</p>
<br/>
</description>
</idea-plugin>
""".trimIndent()
val rainbowSettings = RainbowSettings.instance
rainbowSettings.rainbowifyTagNameInXML = false
myFixture.configureByText(XmlFileType.INSTANCE, code)
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)
)
)
}
}