1
0
mirror of https://github.com/chylex/IntelliJ-Rainbow-Brackets.git synced 2025-01-10 13:42:44 +01:00

Improve angle bracket support for Groovy

This commit is contained in:
张志豪 2018-05-04 18:20:32 +08:00
parent 4ab4481274
commit fff617e497
5 changed files with 82 additions and 2 deletions
build.gradle
src
main
kotlin/com/github/izhangzhihao/rainbow/brackets/provider
resources/META-INF
test/kotlin/com/github/izhangzhihao/rainbow/brackets

View File

@ -1,7 +1,7 @@
buildscript {
repositories {
mavenLocal()
maven { url "https://plugins.gradle.org/m2/"}
maven { url "https://plugins.gradle.org/m2/" }
maven { url "http://maven.aliyun.com/nexus/content/groups/public/" }
}
@ -39,7 +39,7 @@ intellij {
updateSinceUntilBuild = false
sandboxDirectory project.rootDir.canonicalPath + "/.sandbox"
plugins "org.jetbrains.kotlin:$kotlinVersion-release-IJ2017.2-1", 'org.intellij.scala:2017.2.7', 'JavaScriptLanguage', 'CSS', 'Dart:172.3317.48'
plugins "org.jetbrains.kotlin:$kotlinVersion-release-IJ2017.2-1", 'org.intellij.scala:2017.2.7', 'JavaScriptLanguage', 'CSS', 'Dart:172.3317.48', 'Groovy', 'properties'
}
publishPlugin {

View File

@ -0,0 +1,14 @@
package com.github.izhangzhihao.rainbow.brackets.provider
import com.intellij.lang.BracePair
import org.jetbrains.plugins.groovy.lang.lexer.GroovyTokenTypes.mGT
import org.jetbrains.plugins.groovy.lang.lexer.GroovyTokenTypes.mLT
class GroovyAngleBracketProvider : PairedBraceProvider {
override val pairs: List<BracePair> = PAIRS
companion object {
private val PAIRS: List<BracePair> = listOf(BracePair(mLT, mGT, false))
}
}

View File

@ -0,0 +1,6 @@
<idea-plugin>
<extensions defaultExtensionNs="izhangzhihao.rainbow.brackets">
<pairedBraceProvider language="Groovy"
implementationClass="com.github.izhangzhihao.rainbow.brackets.provider.GroovyAngleBracketProvider"/>
</extensions>
</idea-plugin>

View File

@ -179,6 +179,7 @@
<depends optional="true" config-file="kotlin-brackets.xml">org.jetbrains.kotlin</depends>
<depends optional="true" config-file="JSX.xml">JavaScript</depends>
<depends optional="true" config-file="dart-brackets.xml">Dart</depends>
<depends optional="true" config-file="groovy-brackets.xml">org.intellij.groovy</depends>
<extensionPoints>
<extensionPoint name="pairedBraceProvider" beanClass="com.intellij.lang.LanguageExtensionPoint">

View File

@ -0,0 +1,59 @@
package com.github.izhangzhihao.rainbow.brackets
import com.intellij.psi.PsiDocumentManager
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase
import io.kotlintest.matchers.shouldBe
import org.jetbrains.plugins.groovy.GroovyFileType
class RainbowGroovyTest : LightCodeInsightFixtureTestCase() {
fun testRainbowForGroovy() {
val code =
"""
Map<String, Map<String, String>> convertObjectsToMapProperties(Map<String, Object> body) {
return body.collectEntries {
Map.Entry<String, Object> entry ->
[entry.key: entry.value]
} as Map<String, Map<String, String>>
}
""".trimIndent()
myFixture.configureByText(GroovyFileType.GROOVY_FILE_TYPE, code)
PsiDocumentManager.getInstance(project).commitAllDocuments()
val doHighlighting = myFixture.doHighlighting()
assertFalse(doHighlighting.isEmpty())
doHighlighting.filter { brackets.contains(it.text.toChar()) }
.map { it.forcedTextAttributes.foregroundColor }
.toTypedArray()
.shouldBe(
arrayOf(
angleLevel(0),
angleLevel(1),
angleLevel(1),
angleLevel(0),
roundLevel(0),
angleLevel(0),
angleLevel(0),
roundLevel(0),
squigglyLevel(0),
squigglyLevel(1),
angleLevel(0),
angleLevel(0),
squareLevel(0),
squareLevel(0),
squigglyLevel(1),
angleLevel(0),
angleLevel(1),
angleLevel(1),
angleLevel(0),
squigglyLevel(0)
)
)
}
}