Skip to content

Commit 74644f0

Browse files
committed
feat(intellij): refactored textmate highlightning to use the new intellij textmate infrastructure
1 parent 5b7c4b1 commit 74644f0

File tree

5 files changed

+128
-86
lines changed

5 files changed

+128
-86
lines changed
Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,33 @@
11
package dev.robotcode.robotcode4ij
22

3-
import com.intellij.util.containers.Interner
43
import org.jetbrains.plugins.textmate.TextMateService
4+
import org.jetbrains.plugins.textmate.language.TextMateConcurrentMapInterner
55
import org.jetbrains.plugins.textmate.language.TextMateLanguageDescriptor
6-
import org.jetbrains.plugins.textmate.language.syntax.TextMateSyntaxTable
6+
import org.jetbrains.plugins.textmate.language.syntax.TextMateSyntaxTableBuilder
77

88

99
object TextMateBundleHolder {
10-
private val interner = Interner.createWeakInterner<CharSequence>()
11-
10+
private val interner = TextMateConcurrentMapInterner()
11+
1212
val descriptor: TextMateLanguageDescriptor by lazy {
13-
13+
1414
val reader = TextMateService.getInstance().readBundle(RobotCodeHelpers.basePath)
1515
?: throw IllegalStateException("Failed to read robotcode textmate bundle")
16-
17-
val syntaxTable = TextMateSyntaxTable()
18-
16+
17+
val builder = TextMateSyntaxTableBuilder(interner)
18+
1919
val grammarIterator = reader.readGrammars().iterator()
2020
while (grammarIterator.hasNext()) {
2121
val grammar = grammarIterator.next()
22-
val rootScopeName = syntaxTable.loadSyntax(grammar.plist.value, interner) ?: continue
22+
23+
val rootScopeName = builder.addSyntax(grammar.plist.value) ?: continue
2324
if (rootScopeName == "source.robotframework") {
24-
val syntax = syntaxTable.getSyntax(rootScopeName)
25-
return@lazy TextMateLanguageDescriptor(rootScopeName, syntax)
25+
val syntax = builder.build()
26+
return@lazy TextMateLanguageDescriptor(rootScopeName, syntax.getSyntax(rootScopeName))
2627
}
2728
}
28-
29+
2930
throw IllegalStateException("Failed to find robotcode textmate in bundle")
3031
}
31-
32+
3233
}

intellij-client/src/main/kotlin/dev/robotcode/robotcode4ij/configuration/RobotCodeColorSettingsPage.kt

Lines changed: 42 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import dev.robotcode.robotcode4ij.highlighting.RobotCodeSyntaxHighlighter
1111
import javax.swing.Icon
1212

1313
class RobotCodeColorSettingsPage : ColorSettingsPage {
14-
14+
1515
private val descriptors: Array<AttributesDescriptor> = arrayOf(
1616
AttributesDescriptor("Header", Colors.HEADER),
1717
AttributesDescriptor("Test case name", Colors.TESTCASE_NAME),
@@ -22,86 +22,109 @@ class RobotCodeColorSettingsPage : ColorSettingsPage {
2222
AttributesDescriptor("Setting", Colors.SETTING),
2323
AttributesDescriptor("Setting import", Colors.SETTING_IMPORT),
2424
AttributesDescriptor("Control flow", Colors.CONTROL_FLOW),
25+
AttributesDescriptor("Var statement", Colors.VAR),
2526
AttributesDescriptor("Argument", Colors.ARGUMENT),
2627
AttributesDescriptor("Embedded argument", Colors.EMBEDDED_ARGUMENT),
2728
AttributesDescriptor("Named argument", Colors.NAMED_ARGUMENT),
2829
AttributesDescriptor("Variable", Colors.VARIABLE),
2930
AttributesDescriptor("Variable expression", Colors.VARIABLE_EXPRESSION),
3031
AttributesDescriptor("Variable begin", Colors.VARIABLE_BEGIN),
3132
AttributesDescriptor("Variable end", Colors.VARIABLE_END),
32-
33+
3334
AttributesDescriptor("Line comment", Colors.LINE_COMMENT),
3435
AttributesDescriptor("Block comment", Colors.BLOCK_COMMENT),
35-
36+
3637
AttributesDescriptor("Operator", Colors.OPERATOR),
3738
AttributesDescriptor("Namespace", Colors.NAMESPACE),
3839
AttributesDescriptor("BDD prefix", Colors.BDD_PREFIX),
39-
40+
4041
AttributesDescriptor("Continuation", Colors.CONTINUATION),
4142
)
42-
43+
4344
override fun getAttributeDescriptors(): Array<AttributesDescriptor> {
4445
return descriptors
4546
}
46-
47+
4748
override fun getColorDescriptors(): Array<ColorDescriptor> {
4849
return ColorDescriptor.EMPTY_ARRAY
4950
}
50-
51+
5152
override fun getDisplayName(): String {
5253
return "Robot Framework"
5354
}
54-
55+
5556
override fun getIcon(): Icon? {
5657
return RobotIcons.RobotCode
5758
}
58-
59+
5960
override fun getHighlighter(): SyntaxHighlighter {
6061
return RobotCodeSyntaxHighlighter()
6162
}
62-
63+
6364
override fun getDemoText(): String {
6465
return """
6566
*** Settings ***
6667
Library SeleniumLibrary
67-
68+
6869
*** Variables ***
6970
${'$'}{URL} http://example.com # a comment
70-
71+
7172
*** Test Cases ***
7273
Example Test
7374
Open Application ${'$'}{URL}
7475
Log %{APP_DATA=unknown}
76+
Do Something with argument1 argument2
77+
... argument3
78+
# This is a comment
79+
... argument4
7580
Close Application
76-
81+
7782
BDD Example Test
7883
Given application is ppen
7984
When I enter something into the Search Field
8085
Then Something Should Happen
81-
86+
8287
Another Test
8388
[Documentation] This is a test
8489
... with multiple lines
8590
[Arguments]
8691
... ${'$'}{arg1}
8792
... ${'$'}{arg2}
88-
93+
[Tags] example
94+
[Setup] Open Application with arguments
95+
8996
Log ${'$'}{arg1} ${'$'}{arg2}
90-
97+
Log To Console Hello World
98+
9199
*** Keywords ***
92100
Open Application
93101
[Arguments] ${'$'}{url}
94102
Open Browser ${'$'}{url}
95-
103+
96104
Close Application
97105
Close Browser
98-
106+
107+
108+
Do Something Different
109+
[Arguments] ${'$'}{arg1} ${'$'}{arg2}
110+
IF ${'$'}arg1=="value"
111+
Log ${'$'}{arg1}
112+
ELSE
113+
Log ${'$'}{arg2}
114+
END
115+
116+
IF ${'$'}arg2==1234
117+
Log ${'$'}{arg1}
118+
ELSE IF ${'$'}arg2==789
119+
Log ${'$'}{arg2}
120+
END
121+
99122
*** Comments ***
100123
this is a comment block
101124
with multiple lines
102125
""".trimIndent()
103126
}
104-
127+
105128
override fun getAdditionalHighlightingTagToDescriptorMap(): MutableMap<String, TextAttributesKey>? {
106129
return null
107130
}

intellij-client/src/main/kotlin/dev/robotcode/robotcode4ij/highlighting/Colors.kt

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ import com.intellij.openapi.editor.colors.TextAttributesKey
55
import com.intellij.openapi.editor.colors.TextAttributesKey.createTextAttributesKey
66

77
object Colors {
8-
8+
99
val HEADER: TextAttributesKey =
1010
createTextAttributesKey("ROBOTFRAMEWORK_HEADER", DefaultLanguageHighlighterColors.KEYWORD)
11-
11+
1212
val TESTCASE_NAME: TextAttributesKey =
1313
createTextAttributesKey("ROBOTFRAMEWORK_TESTCASE_NAME", DefaultLanguageHighlighterColors.FUNCTION_DECLARATION)
14-
14+
1515
val KEYWORD_NAME: TextAttributesKey =
1616
createTextAttributesKey("ROBOTFRAMEWORK_KEYWORD_NAME", DefaultLanguageHighlighterColors.FUNCTION_DECLARATION)
1717
val KEYWORD_CALL: TextAttributesKey =
@@ -20,47 +20,49 @@ object Colors {
2020
createTextAttributesKey("ROBOTFRAMEWORK_KEYWORD_CALL_INNER", DefaultLanguageHighlighterColors.FUNCTION_CALL)
2121
val NAME_CALL: TextAttributesKey =
2222
createTextAttributesKey("ROBOTFRAMEWORK_NAME_CALL", DefaultLanguageHighlighterColors.FUNCTION_CALL)
23-
23+
2424
val SETTING: TextAttributesKey =
2525
createTextAttributesKey("ROBOTFRAMEWORK_SETTING", DefaultLanguageHighlighterColors.KEYWORD)
2626
val SETTING_IMPORT: TextAttributesKey =
2727
createTextAttributesKey("ROBOTFRAMEWORK_SETTING_IMPORT", DefaultLanguageHighlighterColors.KEYWORD)
2828
val CONTROL_FLOW: TextAttributesKey =
2929
createTextAttributesKey("ROBOTFRAMEWORK_CONTROL_FLOW", DefaultLanguageHighlighterColors.KEYWORD)
30-
30+
31+
val VAR: TextAttributesKey =
32+
createTextAttributesKey("ROBOTFRAMEWORK_VAR", DefaultLanguageHighlighterColors.KEYWORD)
33+
3134
val VARIABLE: TextAttributesKey =
3235
createTextAttributesKey("ROBOTFRAMEWORK_VARIABLE", DefaultLanguageHighlighterColors.GLOBAL_VARIABLE)
3336
val VARIABLE_EXPRESSION: TextAttributesKey =
3437
createTextAttributesKey("ROBOTFRAMEWORK_VARIABLE_EXPRESSION", DefaultLanguageHighlighterColors.GLOBAL_VARIABLE)
35-
38+
3639
val VARIABLE_BEGIN: TextAttributesKey =
3740
createTextAttributesKey("ROBOTFRAMEWORK_VARIABLE_BEGIN", DefaultLanguageHighlighterColors.BRACES)
3841
val VARIABLE_END: TextAttributesKey =
3942
createTextAttributesKey("ROBOTFRAMEWORK_VARIABLE_END", DefaultLanguageHighlighterColors.BRACES)
40-
43+
4144
val NAMESPACE: TextAttributesKey =
4245
createTextAttributesKey("ROBOTFRAMEWORK_NAMESPACE", DefaultLanguageHighlighterColors.CLASS_REFERENCE)
43-
46+
4447
val ARGUMENT: TextAttributesKey =
4548
createTextAttributesKey("ROBOTFRAMEWORK_ARGUMENT", DefaultLanguageHighlighterColors.STRING)
4649
val EMBEDDED_ARGUMENT: TextAttributesKey =
4750
createTextAttributesKey("ROBOTFRAMEWORK_EMBEDDED_ARGUMENT", DefaultLanguageHighlighterColors.STRING)
4851
val NAMED_ARGUMENT: TextAttributesKey =
4952
createTextAttributesKey("ROBOTFRAMEWORK_NAMED_ARGUMENT", DefaultLanguageHighlighterColors.PARAMETER)
50-
53+
5154
val LINE_COMMENT: TextAttributesKey =
5255
createTextAttributesKey("ROBOTFRAMEWORK_LINE_COMMENT", DefaultLanguageHighlighterColors.LINE_COMMENT)
53-
56+
5457
val BLOCK_COMMENT: TextAttributesKey =
5558
createTextAttributesKey("ROBOTFRAMEWORK_BLOCK_COMMENT", DefaultLanguageHighlighterColors.BLOCK_COMMENT)
56-
59+
5760
val OPERATOR: TextAttributesKey =
5861
createTextAttributesKey("ROBOTFRAMEWORK_OPERATOR", DefaultLanguageHighlighterColors.OPERATION_SIGN)
59-
62+
6063
val BDD_PREFIX: TextAttributesKey =
6164
createTextAttributesKey("ROBOTFRAMEWORK_BDD_PREFIX", DefaultLanguageHighlighterColors.METADATA)
62-
65+
6366
val CONTINUATION: TextAttributesKey =
6467
createTextAttributesKey("ROBOTFRAMEWORK_CONTINUATION", DefaultLanguageHighlighterColors.DOT)
6568
}
66-

0 commit comments

Comments
 (0)