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

Compare commits

1 Commits

Author SHA1 Message Date
2d111782c2 Fix deprecations and compiler warnings 2026-05-23 12:26:20 +02:00
9 changed files with 46 additions and 66 deletions

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

@@ -13,7 +13,7 @@ import org.intellij.lang.annotations.Language
class RainbowJavaScriptTest : LightJavaCodeInsightFixtureTestCase() {
fun testJavaScriptPluginEnabled() {
assertTrue(PluginManagerCore.getPlugin(PluginId.getId("JavaScript"))?.isEnabled!!)
assertTrue(PluginManagerCore.isLoaded(PluginId("JavaScript")))
}
fun testIssue11() {
@@ -146,7 +146,7 @@ const element = ( <div> <h1>Hello, world!</h1> </div> );
)
}
fun `for somehow, it just don't work "testIssue39"`() {
fun testIssue39() {
@Language("JavaScript") val code = """
const html = '<div><div><div>Hello</div></div></div>'
""".trimIndent()

View File

@@ -105,37 +105,6 @@ val a: (Int) -> Unit = { aa ->
)
}
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.getBrackets().shouldBe(
arrayOf(
squigglyLevel(3),
squigglyLevel(4),
squigglyLevel(3),
squigglyLevel(2)
)
)
}
fun testKotlinFunctionLiteralBracesAndArrow() {
@Language("kotlin") val code =
"""

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() {