Skip to content

Commit 97081a5

Browse files
committed
feat(intellij): finalize syntax coloring and sematic highlightning part 2
1 parent faa905d commit 97081a5

File tree

14 files changed

+172
-216
lines changed

14 files changed

+172
-216
lines changed

hatch.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ install-packages = "python ./scripts/install_packages.py"
4545

4646
[envs.rfbeta]
4747
python = "3.13"
48-
extra-dependencies = ["robotframework==7.2b1"]
48+
extra-dependencies = ["robotframework==7.2rc1"]
4949

5050
[envs.rfmaster313]
5151
python = "3.13"
@@ -99,7 +99,7 @@ matrix.rf.dependencies = [
9999
"rf71",
100100
] },
101101
{ value = "robotframework>=7.2, <7.3", if = [
102-
"rf72b1",
102+
"rf72rc1",
103103
] },
104104
]
105105

@@ -131,7 +131,7 @@ matrix.rf.dependencies = [
131131
"rf71",
132132
] },
133133
{ value = "robotframework>=7.2, <7.3", if = [
134-
"rf72b1",
134+
"rf72rc1",
135135
] },
136136
]
137137

intellij-client/gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ pluginUntilBuild = 243.*
1313

1414
# IntelliJ Platform Properties -> https://plugins.jetbrains.com/docs/intellij/tools-gradle-intellij-plugin.html#configuration-intellij-extension
1515
platformType = PC
16-
platformVersion = 2024.3
16+
platformVersion = 2024.3.1
1717

1818
# Plugin Dependencies -> https://plugins.jetbrains.com/docs/intellij/plugin-dependencies.html
1919
# Example: platformPlugins = com.jetbrains.php:203.4449.22, org.intellij.scala:2023.3.27@EAP

intellij-client/src/main/kotlin/dev/robotcode/robotcode4ij/execution/RobotCodeRunConfigurationProducer.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
package dev.robotcode.robotcode4ij.execution
22

33
import com.intellij.execution.actions.ConfigurationContext
4-
import com.intellij.execution.actions.ConfigurationFromContext
54
import com.intellij.execution.actions.LazyRunConfigurationProducer
65
import com.intellij.execution.configurations.ConfigurationFactory
76
import com.intellij.execution.configurations.runConfigurationType
87
import com.intellij.openapi.util.Ref
98
import com.intellij.psi.PsiElement
9+
import com.intellij.psi.util.elementType
1010
import dev.robotcode.robotcode4ij.psi.FILE
11-
import dev.robotcode.robotcode4ij.psi.RobotFile
11+
import dev.robotcode.robotcode4ij.psi.RobotSuiteFile
1212
import dev.robotcode.robotcode4ij.psi.TESTCASE_NAME
13-
import org.toml.lang.psi.ext.elementType
13+
1414

1515
class RobotCodeRunConfigurationProducer : LazyRunConfigurationProducer<RobotCodeRunConfiguration>() {
1616
override fun getConfigurationFactory(): ConfigurationFactory {
@@ -24,7 +24,7 @@ class RobotCodeRunConfigurationProducer : LazyRunConfigurationProducer<RobotCode
2424
): Boolean {
2525
// TODO
2626
val psiElement = sourceElement.get()
27-
val psiFile = psiElement.containingFile as? RobotFile ?: return false
27+
val psiFile = psiElement.containingFile as? RobotSuiteFile ?: return false
2828
val virtualFile = psiFile.virtualFile ?: return false
2929

3030
when (psiElement.elementType) {
@@ -50,7 +50,7 @@ class RobotCodeRunConfigurationProducer : LazyRunConfigurationProducer<RobotCode
5050
context: ConfigurationContext
5151
): Boolean {
5252
val psiElement = context.psiLocation
53-
val psiFile = psiElement?.containingFile as? RobotFile ?: return false
53+
val psiFile = psiElement?.containingFile as? RobotSuiteFile ?: return false
5454
val virtualFile = psiFile.virtualFile ?: return false
5555

5656
return when (psiElement.elementType) {

intellij-client/src/main/kotlin/dev/robotcode/robotcode4ij/execution/RobotCodeRunLineMarkerContributor.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import com.intellij.icons.AllIcons
55
import com.intellij.psi.PsiElement
66
import dev.robotcode.robotcode4ij.psi.FILE
77
import dev.robotcode.robotcode4ij.psi.TESTCASE_NAME
8-
import org.toml.lang.psi.ext.elementType
8+
import com.intellij.psi.util.elementType
99

1010
class RobotCodeRunLineMarkerContributor : RunLineMarkerContributor() {
1111
override fun getInfo(element: PsiElement): Info? {

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

Lines changed: 24 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,21 @@ import com.intellij.openapi.fileTypes.SyntaxHighlighterFactory
1212
import com.intellij.openapi.project.Project
1313
import com.intellij.openapi.vfs.VirtualFile
1414
import com.intellij.psi.tree.IElementType
15+
import dev.robotcode.robotcode4ij.psi.ARGUMENT
16+
import dev.robotcode.robotcode4ij.psi.COMMENT_BLOCK
17+
import dev.robotcode.robotcode4ij.psi.COMMENT_LINE
18+
import dev.robotcode.robotcode4ij.psi.CONTINUATION
19+
import dev.robotcode.robotcode4ij.psi.CONTROL_FLOW
1520
import dev.robotcode.robotcode4ij.psi.ENVIRONMENT_VARIABLE_BEGIN
1621
import dev.robotcode.robotcode4ij.psi.ENVIRONMENT_VARIABLE_END
22+
import dev.robotcode.robotcode4ij.psi.HEADER
23+
import dev.robotcode.robotcode4ij.psi.KEYWORD_CALL
24+
import dev.robotcode.robotcode4ij.psi.KEYWORD_NAME
25+
import dev.robotcode.robotcode4ij.psi.OPERATOR
1726
import dev.robotcode.robotcode4ij.psi.RobotTextMateElementType
27+
import dev.robotcode.robotcode4ij.psi.SETTING
28+
import dev.robotcode.robotcode4ij.psi.TESTCASE_NAME
29+
import dev.robotcode.robotcode4ij.psi.VARIABLE
1830
import dev.robotcode.robotcode4ij.psi.VARIABLE_BEGIN
1931
import dev.robotcode.robotcode4ij.psi.VARIABLE_END
2032
import org.jetbrains.plugins.textmate.language.syntax.highlighting.TextMateHighlighter
@@ -31,49 +43,27 @@ class RobotCodeHighlighterProvider : EditorHighlighterProvider {
3143

3244
class RobotCodeHighlighter : TextMateHighlighter(RobotTextMateHighlightingLexer()) {
3345
companion object {
34-
val elementMap = mapOf(
35-
"comment.line.robotframework" to arrayOf(RobotColors.LINE_COMMENT),
36-
"comment.line.rest.robotframework" to arrayOf(RobotColors.LINE_COMMENT),
37-
"comment.block.robotframework" to arrayOf(RobotColors.BLOCK_COMMENT),
38-
"keyword.other.header.robotframework" to arrayOf(RobotColors.HEADER),
39-
"keyword.other.header.settings.robotframework" to arrayOf(RobotColors.HEADER),
40-
"keyword.other.header.variable.robotframework" to arrayOf(RobotColors.HEADER),
41-
"keyword.other.header.testcase.robotframework" to arrayOf(RobotColors.HEADER),
42-
"keyword.other.header.task.robotframework" to arrayOf(RobotColors.HEADER),
43-
"keyword.other.header.keyword.robotframework" to arrayOf(RobotColors.HEADER),
44-
"keyword.other.header.comment.robotframework" to arrayOf(RobotColors.HEADER),
45-
46-
"keyword.control.settings.robotframework" to arrayOf(RobotColors.SETTING),
47-
"keyword.control.settings.documentation.robotframework" to arrayOf(RobotColors.SETTING),
48-
49-
"entity.name.function.testcase.name.robotframework" to arrayOf(RobotColors.TESTCASE_NAME),
50-
"entity.name.function.keyword.name.robotframework" to arrayOf(RobotColors.KEYWORD_NAME),
51-
"entity.name.function.keyword-call.robotframework" to arrayOf(RobotColors.KEYWORD_CALL),
52-
"keyword.control.flow.robotframework" to arrayOf(RobotColors.CONTROL_FLOW),
53-
"keyword.other.robotframework" to arrayOf(RobotColors.SETTING),
54-
"punctuation.definition.variable.begin.robotframework" to arrayOf(RobotColors.VARIABLE_BEGIN),
55-
"punctuation.definition.variable.end.robotframework" to arrayOf(RobotColors.VARIABLE_END),
56-
"variable.name.readwrite.robotframework" to arrayOf(RobotColors.VARIABLE),
57-
"punctuation.definition.envvar.begin.robotframework" to arrayOf(RobotColors.VARIABLE_BEGIN),
58-
"punctuation.definition.envvar.end.robotframework" to arrayOf(RobotColors.VARIABLE_END),
59-
"keyword.operator.robotframework" to arrayOf(RobotColors.OPERATOR),
60-
"constant.character.robotframework" to arrayOf(RobotColors.ARGUMENT),
61-
"string.unquoted.argument.robotframework" to arrayOf(RobotColors.ARGUMENT),
62-
"keyword.operator.continue.robotframework" to arrayOf(RobotColors.CONTINUATION),
63-
)
6446
val elementTypeMap = mapOf(
47+
COMMENT_LINE to arrayOf(RobotColors.LINE_COMMENT),
48+
COMMENT_BLOCK to arrayOf(RobotColors.BLOCK_COMMENT),
6549
VARIABLE_BEGIN to arrayOf(RobotColors.VARIABLE_BEGIN),
6650
VARIABLE_END to arrayOf(RobotColors.VARIABLE_END),
6751
ENVIRONMENT_VARIABLE_BEGIN to arrayOf(RobotColors.VARIABLE_BEGIN),
6852
ENVIRONMENT_VARIABLE_END to arrayOf(RobotColors.VARIABLE_END),
53+
TESTCASE_NAME to arrayOf(RobotColors.TESTCASE_NAME),
54+
KEYWORD_NAME to arrayOf(RobotColors.KEYWORD_NAME),
55+
HEADER to arrayOf(RobotColors.HEADER),
56+
SETTING to arrayOf(RobotColors.SETTING),
57+
KEYWORD_CALL to arrayOf(RobotColors.KEYWORD_CALL),
58+
CONTROL_FLOW to arrayOf(RobotColors.CONTROL_FLOW),
59+
VARIABLE to arrayOf(RobotColors.VARIABLE),
60+
OPERATOR to arrayOf(RobotColors.OPERATOR),
61+
ARGUMENT to arrayOf(RobotColors.ARGUMENT),
62+
CONTINUATION to arrayOf(RobotColors.CONTINUATION),
6963
)
7064
}
7165

7266
override fun getTokenHighlights(tokenType: IElementType?): Array<TextAttributesKey> {
73-
if (tokenType is RobotTextMateElementType) {
74-
val result = elementMap[tokenType.element.scope.scopeName]
75-
if (result != null) return result
76-
}
7767
if (tokenType in elementTypeMap) {
7868
val result = elementTypeMap[tokenType]
7969
if (result != null) return result

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

Lines changed: 50 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,39 +3,72 @@ package dev.robotcode.robotcode4ij.highlighting
33
import com.intellij.openapi.util.registry.Registry
44
import com.intellij.psi.tree.IElementType
55
import dev.robotcode.robotcode4ij.TextMateBundleHolder
6+
import dev.robotcode.robotcode4ij.psi.ARGUMENT
7+
import dev.robotcode.robotcode4ij.psi.COMMENT_BLOCK
8+
import dev.robotcode.robotcode4ij.psi.COMMENT_LINE
9+
import dev.robotcode.robotcode4ij.psi.CONTINUATION
10+
import dev.robotcode.robotcode4ij.psi.CONTROL_FLOW
611
import dev.robotcode.robotcode4ij.psi.ENVIRONMENT_VARIABLE_BEGIN
712
import dev.robotcode.robotcode4ij.psi.ENVIRONMENT_VARIABLE_END
13+
import dev.robotcode.robotcode4ij.psi.HEADER
14+
import dev.robotcode.robotcode4ij.psi.KEYWORD_CALL
15+
import dev.robotcode.robotcode4ij.psi.KEYWORD_NAME
16+
import dev.robotcode.robotcode4ij.psi.OPERATOR
817
import dev.robotcode.robotcode4ij.psi.RobotTextMateElementType
18+
import dev.robotcode.robotcode4ij.psi.SETTING
19+
import dev.robotcode.robotcode4ij.psi.TESTCASE_NAME
20+
import dev.robotcode.robotcode4ij.psi.VARIABLE
921
import dev.robotcode.robotcode4ij.psi.VARIABLE_BEGIN
1022
import dev.robotcode.robotcode4ij.psi.VARIABLE_END
1123
import org.jetbrains.plugins.textmate.language.syntax.lexer.TextMateElementType
1224
import org.jetbrains.plugins.textmate.language.syntax.lexer.TextMateHighlightingLexer
1325

1426
class RobotTextMateHighlightingLexer : TextMateHighlightingLexer(
15-
TextMateBundleHolder.descriptor,
16-
Registry.get("textmate.line.highlighting.limit").asInteger()
27+
TextMateBundleHolder.descriptor, Registry.get("textmate.line.highlighting.limit").asInteger()
1728
) {
1829
companion object {
19-
val BRACES_START = setOf(
20-
"punctuation.definition.variable.begin.robotframework",
21-
"punctuation.definition.envvar.begin.robotframework"
22-
)
23-
val BRACES_END = setOf(
24-
"punctuation.definition.variable.end.robotframework",
25-
"punctuation.definition.envvar.end.robotframework"
26-
)
30+
val mapping = mapOf(
31+
"comment.line.robotframework" to COMMENT_LINE,
32+
"comment.line.rest.robotframework" to COMMENT_LINE,
33+
"comment.block.robotframework" to COMMENT_BLOCK,
34+
"punctuation.definition.variable.begin.robotframework" to VARIABLE_BEGIN,
35+
"punctuation.definition.variable.end.robotframework" to VARIABLE_END,
36+
"punctuation.definition.envvar.begin.robotframework" to ENVIRONMENT_VARIABLE_BEGIN,
37+
"punctuation.definition.envvar.end.robotframework" to ENVIRONMENT_VARIABLE_END,
38+
39+
"entity.name.function.testcase.name.robotframework" to TESTCASE_NAME,
40+
"entity.name.function.keyword.name.robotframework" to KEYWORD_NAME,
41+
42+
"keyword.other.header.robotframework" to HEADER,
43+
"keyword.other.header.settings.robotframework" to HEADER,
44+
"keyword.other.header.variable.robotframework" to HEADER,
45+
"keyword.other.header.testcase.robotframework" to HEADER,
46+
"keyword.other.header.task.robotframework" to HEADER,
47+
"keyword.other.header.keyword.robotframework" to HEADER,
48+
"keyword.other.header.comment.robotframework" to HEADER,
49+
50+
"keyword.control.settings.robotframework" to SETTING,
51+
"keyword.control.settings.documentation.robotframework" to SETTING,
52+
53+
"entity.name.function.keyword-call.robotframework" to KEYWORD_CALL,
54+
"keyword.control.flow.robotframework" to CONTROL_FLOW,
55+
56+
"keyword.other.robotframework" to SETTING,
57+
58+
"variable.name.readwrite.robotframework" to VARIABLE,
59+
"keyword.operator.robotframework" to OPERATOR,
60+
61+
"constant.character.robotframework" to ARGUMENT,
62+
"string.unquoted.argument.robotframework" to ARGUMENT,
63+
64+
"keyword.operator.continue.robotframework" to CONTINUATION,
65+
)
2766
}
2867

2968
override fun getTokenType(): IElementType? {
3069
val result = super.getTokenType() ?: return null
3170
if (result is TextMateElementType) {
32-
return when (result.scope.scopeName) {
33-
"punctuation.definition.variable.begin.robotframework" -> VARIABLE_BEGIN
34-
"punctuation.definition.variable.end.robotframework" -> VARIABLE_END
35-
"punctuation.definition.envvar.begin.robotframework" -> ENVIRONMENT_VARIABLE_BEGIN
36-
"punctuation.definition.envvar.end.robotframework" -> ENVIRONMENT_VARIABLE_END
37-
else -> RobotTextMateElementType(result)
38-
}
71+
return mapping[result.scope.scopeName] ?: RobotTextMateElementType(result)
3972
}
4073
return result
4174
}

intellij-client/src/main/kotlin/dev/robotcode/robotcode4ij/lsp/RobotCodeSemanticTokensColorsProvider.kt

Lines changed: 33 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -5,56 +5,43 @@ import com.intellij.psi.PsiFile
55
import com.redhat.devtools.lsp4ij.features.semanticTokens.SemanticTokensColorsProvider
66
import dev.robotcode.robotcode4ij.highlighting.RobotColors
77

8+
private val mapping by lazy {
9+
mapOf(
10+
"header" to RobotColors.HEADER,
11+
"headerKeyword" to RobotColors.HEADER,
12+
"headerComment" to RobotColors.HEADER,
13+
"headerSettings" to RobotColors.HEADER,
14+
"headerVariable" to RobotColors.HEADER,
15+
"headerTestcase" to RobotColors.HEADER,
16+
"headerTask" to RobotColors.HEADER,
17+
18+
"setting" to RobotColors.SETTING,
19+
"settingImport" to RobotColors.SETTING_IMPORT,
20+
"controlFlow" to RobotColors.CONTROL_FLOW,
21+
22+
"testcaseName" to RobotColors.TESTCASE_NAME,
23+
"keywordName" to RobotColors.KEYWORD_NAME,
24+
"keywordCall" to RobotColors.KEYWORD_CALL,
25+
26+
"argument" to RobotColors.ARGUMENT,
27+
"embeddedArgument" to RobotColors.EMBEDDED_ARGUMENT,
28+
29+
"variable" to RobotColors.VARIABLE,
30+
"variableExpression" to RobotColors.VARIABLE_EXPRESSION,
31+
"variableBegin" to RobotColors.VARIABLE_BEGIN,
32+
"variableEnd" to RobotColors.VARIABLE_END,
33+
34+
"namespace" to RobotColors.NAMESPACE,
35+
"bddPrefix" to RobotColors.BDD_PREFIX,
36+
"continuation" to RobotColors.CONTINUATION
37+
)
38+
}
839

940
class RobotCodeSemanticTokensColorsProvider : SemanticTokensColorsProvider {
10-
11-
1241
override fun getTextAttributesKey(
1342
tokenType: String, tokenModifiers: MutableList<String>, file: PsiFile
14-
): TextAttributesKey? { // TODO implement RobotCodeSemanticTokensColorsProvider
15-
return when (tokenType) {
16-
"header",
17-
"headerKeyword",
18-
"headerComment",
19-
"headerSettings",
20-
"headerVariable",
21-
"headerTestcase",
22-
"headerTask",
23-
-> RobotColors.HEADER
24-
25-
"setting" -> RobotColors.SETTING
26-
"settingImport" -> RobotColors.SETTING_IMPORT
27-
"controlFlow" -> RobotColors.CONTROL_FLOW
28-
29-
"testcaseName" -> RobotColors.TESTCASE_NAME
30-
"keywordName" -> RobotColors.KEYWORD_NAME
31-
"keywordCall" -> RobotColors.KEYWORD_CALL
32-
33-
"argument" -> RobotColors.ARGUMENT
34-
"embeddedArgument" -> RobotColors.EMBEDDED_ARGUMENT
35-
36-
"variable" -> RobotColors.VARIABLE
37-
"variableExpression" -> RobotColors.VARIABLE_EXPRESSION
38-
"variableBegin" -> RobotColors.VARIABLE_BEGIN
39-
"variableEnd" -> RobotColors.VARIABLE_END
40-
41-
"namespace" -> RobotColors.NAMESPACE
42-
"bddPrefix" -> RobotColors.BDD_PREFIX
43-
"continuation" -> RobotColors.CONTINUATION
44-
else -> null
45-
}
46-
47-
// return when (tokenType) {
48-
// "headerTestcase" -> {
49-
// val myAttrs = DefaultLanguageHighlighterColors.KEYWORD.defaultAttributes.clone();
50-
//
51-
// myAttrs.effectType = EffectType.LINE_UNDERSCORE;
52-
// myAttrs.effectColor = myAttrs.foregroundColor;
53-
// myAttrs.fontType = Font.ITALIC;
54-
// return TextAttributesKey.createTextAttributesKey(
55-
// "tokenType", myAttrs
56-
// )
57-
// }
43+
): TextAttributesKey? {
44+
return mapping[tokenType]
5845
}
5946
}
6047

0 commit comments

Comments
 (0)