1
0
mirror of https://github.com/chylex/IntelliJ-Rainbow-Brackets.git synced 2025-01-31 07:46:00 +01:00

Compare commits

..

No commits in common. "74ac5273b95f3a73808f0441d90fb7096f92e04f" and "48c8cc73b0383fdc9013049d4290d03eede04865" have entirely different histories.

5 changed files with 70 additions and 55 deletions

View File

@ -9,7 +9,7 @@ plugins {
} }
group = "com.chylex.intellij.coloredbrackets" group = "com.chylex.intellij.coloredbrackets"
version = "1.2.0" version = "1.1.0"
allprojects { allprojects {
apply(plugin = "org.jetbrains.kotlin.jvm") apply(plugin = "org.jetbrains.kotlin.jvm")

View File

@ -9,27 +9,21 @@ import com.intellij.icons.AllIcons
import com.intellij.ide.actions.ShowSettingsUtilImpl import com.intellij.ide.actions.ShowSettingsUtilImpl
import com.intellij.openapi.fileEditor.FileEditor import com.intellij.openapi.fileEditor.FileEditor
import com.intellij.openapi.project.Project import com.intellij.openapi.project.Project
import com.intellij.openapi.util.Key
import com.intellij.openapi.util.Ref import com.intellij.openapi.util.Ref
import com.intellij.openapi.vfs.VirtualFile import com.intellij.openapi.vfs.VirtualFile
import com.intellij.ui.EditorNotificationPanel import com.intellij.ui.EditorNotificationPanel
import com.intellij.ui.EditorNotificationProvider
import com.intellij.ui.EditorNotifications import com.intellij.ui.EditorNotifications
import com.intellij.ui.HyperlinkLabel import com.intellij.ui.HyperlinkLabel
import java.util.function.Function
import javax.swing.JComponent
class RainbowifyBanner : EditorNotificationProvider { class RainbowifyBanner : EditorNotifications.Provider<EditorNotificationPanel>() {
override fun collectNotificationData(project: Project, file: VirtualFile): Function<in FileEditor, out JComponent?> { override fun getKey(): Key<EditorNotificationPanel> = KEY
return Function { createNotificationPanel(project, file) }
}
private fun createNotificationPanel(project: Project, file: VirtualFile): EditorNotificationPanel? { override fun createNotificationPanel(file: VirtualFile, fileEditor: FileEditor, project: Project): EditorNotificationPanel? {
val settings = RainbowSettings.instance val settings = RainbowSettings.instance
if (!settings.isRainbowEnabled) { if (!settings.isRainbowEnabled) {
if (settings.suppressDisabledCheck) { if (settings.suppressDisabledCheck) return null
return null
}
return EditorNotificationPanel().apply { return EditorNotificationPanel().apply {
text("Colored Brackets is now disabled") text("Colored Brackets is now disabled")
icon(AllIcons.General.GearPlain) icon(AllIcons.General.GearPlain)
@ -47,9 +41,7 @@ class RainbowifyBanner : EditorNotificationProvider {
val psiFile = file.toPsiFile(project) val psiFile = file.toPsiFile(project)
if (psiFile != null && !checkForBigFile(psiFile)) { if (psiFile != null && !checkForBigFile(psiFile)) {
if (settings.suppressBigFileCheck) { if (settings.suppressBigFileCheck) return null
return null
}
return EditorNotificationPanel().apply { return EditorNotificationPanel().apply {
text("Rainbowify is disabled for files > " + settings.bigFilesLinesThreshold + " lines") text("Rainbowify is disabled for files > " + settings.bigFilesLinesThreshold + " lines")
icon(AllIcons.General.InspectionsEye) icon(AllIcons.General.InspectionsEye)
@ -69,9 +61,7 @@ class RainbowifyBanner : EditorNotificationProvider {
settings.languageBlacklist.contains(file.fileType.name) || settings.languageBlacklist.contains(file.fileType.name) ||
settings.languageBlacklist.contains(memoizedFileExtension(file.name)) settings.languageBlacklist.contains(memoizedFileExtension(file.name))
) { ) {
if (settings.suppressBlackListCheck) { if (settings.suppressBlackListCheck) return null
return null
}
return EditorNotificationPanel().apply { return EditorNotificationPanel().apply {
text("Rainbowify is disabled because the language/file extension is in the black list") text("Rainbowify is disabled because the language/file extension is in the black list")
icon(AllIcons.General.InspectionsEye) icon(AllIcons.General.InspectionsEye)
@ -91,10 +81,14 @@ class RainbowifyBanner : EditorNotificationProvider {
return null return null
} }
private fun EditorNotificationPanel.createComponentActionLabel(labelText: String, callback: (HyperlinkLabel) -> Unit) { companion object {
private val KEY = Key.create<EditorNotificationPanel>("RainbowifyBanner")
fun EditorNotificationPanel.createComponentActionLabel(labelText: String, callback: (HyperlinkLabel) -> Unit) {
val label: Ref<HyperlinkLabel> = Ref.create() val label: Ref<HyperlinkLabel> = Ref.create()
label.set(createActionLabel(labelText) { label.set(createActionLabel(labelText) {
callback(label.get()) callback(label.get())
}) })
} }
}
} }

View File

@ -8,6 +8,7 @@ import com.intellij.ide.actions.ToggleZenModeAction
import com.intellij.lang.LanguageParserDefinitions import com.intellij.lang.LanguageParserDefinitions
import com.intellij.openapi.editor.Editor import com.intellij.openapi.editor.Editor
import com.intellij.openapi.editor.IndentGuideDescriptor import com.intellij.openapi.editor.IndentGuideDescriptor
import com.intellij.openapi.editor.ex.EditorEx
import com.intellij.openapi.editor.ex.util.EditorUtil import com.intellij.openapi.editor.ex.util.EditorUtil
import com.intellij.openapi.editor.markup.HighlighterTargetArea import com.intellij.openapi.editor.markup.HighlighterTargetArea
import com.intellij.openapi.editor.markup.MarkupModel import com.intellij.openapi.editor.markup.MarkupModel
@ -22,8 +23,8 @@ import com.intellij.openapi.util.TextRange
import com.intellij.psi.PsiFile import com.intellij.psi.PsiFile
import com.intellij.psi.tree.TokenSet import com.intellij.psi.tree.TokenSet
import com.intellij.util.DocumentUtil import com.intellij.util.DocumentUtil
import com.intellij.util.containers.IntStack
import com.intellij.util.text.CharArrayUtil import com.intellij.util.text.CharArrayUtil
import it.unimi.dsi.fastutil.ints.IntArrayList
import java.lang.StrictMath.abs import java.lang.StrictMath.abs
import java.lang.StrictMath.min import java.lang.StrictMath.min
import java.util.Collections import java.util.Collections
@ -34,9 +35,11 @@ import java.util.Collections
* */ * */
class RainbowIndentsPass internal constructor( class RainbowIndentsPass internal constructor(
project: Project, project: Project,
private val myEditor: Editor, editor: Editor,
private val myFile: PsiFile, private val myFile: PsiFile,
) : TextEditorHighlightingPass(project, myEditor.document, false), DumbAware { ) : TextEditorHighlightingPass(project, editor.document, false), DumbAware {
private val myEditor: EditorEx = editor as EditorEx
@Volatile @Volatile
private var myRanges = emptyList<TextRange>() private var myRanges = emptyList<TextRange>()
@ -148,8 +151,8 @@ class RainbowIndentsPass internal constructor(
calculator.calculate() calculator.calculate()
val lineIndents = calculator.lineIndents val lineIndents = calculator.lineIndents
val lines = IntArrayList() val lines = IntStack()
val indents = IntArrayList() val indents = IntStack()
lines.push(0) lines.push(0)
indents.push(0) indents.push(0)
@ -158,10 +161,10 @@ class RainbowIndentsPass internal constructor(
ProgressManager.checkCanceled() ProgressManager.checkCanceled()
val curIndent = abs(lineIndents[line]) val curIndent = abs(lineIndents[line])
while (!indents.isEmpty && curIndent <= indents.peekInt(0)) { while (!indents.empty() && curIndent <= indents.peek()) {
ProgressManager.checkCanceled() ProgressManager.checkCanceled()
val level = indents.popInt() val level = indents.pop()
val startLine = lines.popInt() val startLine = lines.pop()
if (level > 0) { if (level > 0) {
for (i in startLine until line) { for (i in startLine until line) {
if (level != abs(lineIndents[i])) { if (level != abs(lineIndents[i])) {
@ -181,10 +184,10 @@ class RainbowIndentsPass internal constructor(
} }
} }
while (!indents.isEmpty) { while (!indents.empty()) {
ProgressManager.checkCanceled() ProgressManager.checkCanceled()
val level = indents.popInt() val level = indents.pop()
val startLine = lines.popInt() val startLine = lines.pop()
if (level > 0) { if (level > 0) {
descriptors.add(createDescriptor(level, startLine, document.lineCount, lineIndents)) descriptors.add(createDescriptor(level, startLine, document.lineCount, lineIndents))
} }
@ -204,12 +207,38 @@ class RainbowIndentsPass internal constructor(
return IndentGuideDescriptor(level, sLine, endLine) return IndentGuideDescriptor(level, sLine, endLine)
} }
/*
private fun findCodeConstructStart(startLine: Int): Int? {
val document = myEditor.document
val text = document.immutableCharSequence
val lineStartOffset = document.getLineStartOffset(startLine)
val firstNonWsOffset = CharArrayUtil.shiftForward(text, lineStartOffset, " \t")
val type = PsiUtilBase.getPsiFileAtOffset(myFile, firstNonWsOffset).fileType
val language = PsiUtilCore.getLanguageAtOffset(myFile, firstNonWsOffset)
val braceMatcher = BraceMatchingUtil.getBraceMatcher(type, language)
val iterator = myEditor.highlighter.createIterator(firstNonWsOffset)
return if (braceMatcher.isLBraceToken(iterator, text, type)) {
braceMatcher.getCodeConstructStart(myFile, firstNonWsOffset)
} else null
}
private fun findCodeConstructStartLine(startLine: Int): Int {
val codeConstructStart = findCodeConstructStart(startLine)
return if (codeConstructStart != null) myEditor.document.getLineNumber(codeConstructStart) else startLine
}
*/
private inner class IndentsCalculator { private inner class IndentsCalculator {
val myComments: MutableMap<String, TokenSet> = HashMap() val myComments: MutableMap<String, TokenSet> = HashMap()
val lineIndents = IntArray(document.lineCount) // negative value means the line is empty (or contains a comment) and indent val lineIndents = IntArray(document.lineCount) // negative value means the line is empty (or contains a comment) and indent
// (denoted by absolute value) was deduced from enclosing non-empty lines // (denoted by absolute value) was deduced from enclosing non-empty lines
val myChars = document.charsSequence val myChars: CharSequence
init {
myChars = document.charsSequence
}
/** /**
* Calculates line indents for the [target document][.myDocument]. * Calculates line indents for the [target document][.myDocument].

View File

@ -1,22 +1,19 @@
package com.chylex.intellij.coloredbrackets.indents package com.chylex.intellij.coloredbrackets.indents
import com.intellij.codeHighlighting.Pass import com.intellij.codeHighlighting.Pass
import com.intellij.codeHighlighting.TextEditorHighlightingPass
import com.intellij.codeHighlighting.TextEditorHighlightingPassFactory import com.intellij.codeHighlighting.TextEditorHighlightingPassFactory
import com.intellij.codeHighlighting.TextEditorHighlightingPassFactoryRegistrar import com.intellij.codeHighlighting.TextEditorHighlightingPassFactoryRegistrar
import com.intellij.codeHighlighting.TextEditorHighlightingPassRegistrar import com.intellij.codeHighlighting.TextEditorHighlightingPassRegistrar
import com.intellij.openapi.editor.Editor import com.intellij.openapi.editor.Editor
import com.intellij.openapi.editor.impl.ImaginaryEditor
import com.intellij.openapi.project.Project import com.intellij.openapi.project.Project
import com.intellij.psi.PsiFile import com.intellij.psi.PsiFile
class RainbowIndentsPassFactory : class RainbowIndentsPassFactory :
TextEditorHighlightingPassFactoryRegistrar, TextEditorHighlightingPassFactory { TextEditorHighlightingPassFactoryRegistrar, TextEditorHighlightingPassFactory {
override fun createHighlightingPass(file: PsiFile, editor: Editor): RainbowIndentsPass? { override fun createHighlightingPass(file: PsiFile, editor: Editor): TextEditorHighlightingPass {
return when (editor) { return RainbowIndentsPass(file.project, editor, file)
is ImaginaryEditor -> null
else -> RainbowIndentsPass(file.project, editor, file)
}
} }
override fun registerHighlightingPassFactory(registrar: TextEditorHighlightingPassRegistrar, project: Project) { override fun registerHighlightingPassFactory(registrar: TextEditorHighlightingPassRegistrar, project: Project) {

View File

@ -18,23 +18,18 @@
]]></description> ]]></description>
<change-notes><![CDATA[ <change-notes><![CDATA[
<b>Version 1.2.0</b> <b>1.1.0</b>
<ul> <ul>
<li>Fixed not re-highlighting open files after changing settings.</li> <li>Added support for C++ in Rider and CLion Nova</li>
<li>Fixed exception when opening certain diff editors.</li> <li>Fixed broken option to not color parentheses without content in C#</li>
<li>Improved highlighting performance</li>
<li>Increased default setting for maximum line count from 1K to 100K</li>
</ul> </ul>
<b>Version 1.1.0</b> <b>1.0.0</b>
<ul> <ul>
<li>Added support for C++ in Rider and CLion Nova.</li> <li>Restored support for CLion and Rider</li>
<li>Fixed broken option to not color parentheses without content in C#.</li> <li>Added support for Settings Sync</li>
<li>Improved highlighting performance.</li> <li>Fixed service initialization warnings reported by IJ 2024.2+</li>
<li>Increased default setting for maximum line count from 1K to 100K.</li>
</ul>
<b>Version 1.0.0</b>
<ul>
<li>Restored support for CLion and Rider.</li>
<li>Added support for Settings Sync.</li>
<li>Fixed service initialization warnings reported by IJ 2024.2.</li>
</ul> </ul>
]]></change-notes> ]]></change-notes>