Skip to content

Commit dcb20f7

Browse files
committed
feat(intellij): implemented correct coloring of most elements and started implementing some settings dialogs for colors, codestyle and project settings
1 parent f1982c3 commit dcb20f7

27 files changed

+563
-247
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ class BundledHelpers {
99
val bundledPath: Path = basePath.resolve("bundled")
1010
val toolPath: Path = bundledPath.resolve("tool")
1111
val robotCodePath: Path = toolPath.resolve("robotcode")
12-
val checkRobotVersion: Path= toolPath.resolve("utils").resolve("check_robot_version.py")
12+
val checkRobotVersion: Path = toolPath.resolve("utils").resolve("check_robot_version.py")
1313
}
1414
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ import org.jetbrains.annotations.PropertyKey
88
private const val BUNDLE = "messages.RobotCode"
99

1010
object RobotCodeBundle : DynamicBundle(BUNDLE) {
11-
11+
1212
@JvmStatic
1313
fun message(@PropertyKey(resourceBundle = BUNDLE) key: String, vararg params: Any) =
1414
getMessage(key, *params)
15-
15+
1616
@Suppress("unused")
1717
@JvmStatic
1818
fun messagePointer(@PropertyKey(resourceBundle = BUNDLE) key: String, vararg params: Any) =
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package dev.robotcode.robotcode4ij
2+
3+
import com.intellij.psi.codeStyle.CodeStyleSettings
4+
import com.intellij.psi.codeStyle.CustomCodeStyleSettings
5+
6+
class RobotCodeCodeStyleSettings(settings: CodeStyleSettings) :
7+
CustomCodeStyleSettings("GdCodeStyleSettings", settings) {
8+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package dev.robotcode.robotcode4ij
2+
3+
import com.intellij.application.options.CodeStyleAbstractConfigurable
4+
import com.intellij.application.options.CodeStyleAbstractPanel
5+
import com.intellij.application.options.TabbedLanguageCodeStylePanel
6+
import com.intellij.psi.codeStyle.CodeStyleConfigurable
7+
import com.intellij.psi.codeStyle.CodeStyleSettings
8+
import com.intellij.psi.codeStyle.CodeStyleSettingsProvider
9+
import com.intellij.psi.codeStyle.CustomCodeStyleSettings
10+
11+
class RobotCodeCodeStyleSettingsProvider : CodeStyleSettingsProvider() {
12+
override fun getConfigurableDisplayName() = "Robot Framework"
13+
14+
override fun createCustomSettings(settings: CodeStyleSettings): CustomCodeStyleSettings {
15+
return RobotCodeCodeStyleSettings(settings)
16+
}
17+
18+
override fun createConfigurable(
19+
settings: CodeStyleSettings,
20+
modelSettings: CodeStyleSettings
21+
): CodeStyleConfigurable {
22+
return object : CodeStyleAbstractConfigurable(settings, modelSettings, this.configurableDisplayName) {
23+
override fun createPanel(settings: CodeStyleSettings): CodeStyleAbstractPanel {
24+
return GdCodeStyleMainPanel(currentSettings, settings)
25+
}
26+
}
27+
}
28+
29+
private class GdCodeStyleMainPanel(currentSettings: CodeStyleSettings, settings: CodeStyleSettings) :
30+
TabbedLanguageCodeStylePanel(RobotFrameworkLanguage, currentSettings, settings)
31+
32+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package dev.robotcode.robotcode4ij
2+
3+
import com.intellij.application.options.IndentOptionsEditor
4+
import com.intellij.application.options.SmartIndentOptionsEditor
5+
import com.intellij.lang.Language
6+
import com.intellij.psi.codeStyle.CodeStyleSettings
7+
import com.intellij.psi.codeStyle.CodeStyleSettingsCustomizable
8+
import com.intellij.psi.codeStyle.CustomCodeStyleSettings
9+
import com.intellij.psi.codeStyle.LanguageCodeStyleSettingsProvider
10+
11+
class RobotCodeLangCodeStyleSettingsProvider : LanguageCodeStyleSettingsProvider() {
12+
override fun getLanguage(): Language {
13+
return RobotFrameworkLanguage
14+
}
15+
16+
override fun getIndentOptionsEditor(): IndentOptionsEditor {
17+
return SmartIndentOptionsEditor()
18+
}
19+
20+
override fun createCustomSettings(settings: CodeStyleSettings): CustomCodeStyleSettings {
21+
return RobotCodeCodeStyleSettings(settings)
22+
}
23+
24+
override fun customizeSettings(consumer: CodeStyleSettingsCustomizable, settingsType: SettingsType) {
25+
when (settingsType) {
26+
SettingsType.INDENT_SETTINGS -> {
27+
consumer.showAllStandardOptions()
28+
}
29+
30+
SettingsType.BLANK_LINES_SETTINGS -> {
31+
// TODO
32+
}
33+
34+
SettingsType.SPACING_SETTINGS -> {
35+
// TODO
36+
}
37+
38+
SettingsType.WRAPPING_AND_BRACES_SETTINGS -> {
39+
// TODO
40+
}
41+
42+
SettingsType.COMMENTER_SETTINGS -> {
43+
// TODO
44+
}
45+
46+
SettingsType.LANGUAGE_SPECIFIC -> {
47+
// TODO
48+
}
49+
}
50+
}
51+
52+
override fun getCodeSample(settingsType: SettingsType): String? {
53+
return "*** Settings ***\n" +
54+
"Library SeleniumLibrary\n" +
55+
"\n" +
56+
"*** Variables ***\n" +
57+
"${'$'}{BROWSER} Chrome\n" +
58+
"\n" +
59+
"*** Test Cases ***\n" +
60+
"Open Browser\n" +
61+
" Open Browser https://www.google.com \${BROWSER}\n" +
62+
" Close Browser\n"
63+
}
64+
}
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
package dev.robotcode.robotcode4ij
2+
3+
import com.intellij.extapi.psi.PsiFileBase
4+
import com.intellij.lang.ASTNode
5+
import com.intellij.lang.ParserDefinition
6+
import com.intellij.lang.PsiBuilder
7+
import com.intellij.lang.PsiParser
8+
import com.intellij.lexer.EmptyLexer
9+
import com.intellij.lexer.Lexer
10+
import com.intellij.openapi.fileTypes.FileType
11+
import com.intellij.openapi.project.Project
12+
import com.intellij.openapi.util.registry.Registry
13+
import com.intellij.psi.FileViewProvider
14+
import com.intellij.psi.PsiElement
15+
import com.intellij.psi.PsiFile
16+
import com.intellij.psi.impl.source.tree.CompositePsiElement
17+
import com.intellij.psi.stubs.PsiFileStub
18+
import com.intellij.psi.tree.IElementType
19+
import com.intellij.psi.tree.IFileElementType
20+
import com.intellij.psi.tree.IStubFileElementType
21+
import com.intellij.psi.tree.TokenSet
22+
import org.jetbrains.plugins.textmate.TextMateService
23+
import org.jetbrains.plugins.textmate.language.syntax.lexer.TextMateHighlightingLexer
24+
25+
val FILE = IStubFileElementType<PsiFileStub<RobotFile>>("RobotSuiteFile", RobotFrameworkLanguage);
26+
27+
class RobotCodeParserDefinition : ParserDefinition {
28+
29+
override fun createLexer(project: Project?): Lexer {
30+
val descriptor = TextMateService.getInstance().getLanguageDescriptorByExtension("robot")
31+
if (descriptor != null) {
32+
33+
return TextMateHighlightingLexer(
34+
descriptor,
35+
Registry.get("textmate.line.highlighting.limit").asInteger()
36+
)
37+
}
38+
return EmptyLexer()
39+
}
40+
41+
override fun createParser(project: Project?): PsiParser {
42+
return RobotPsiParser()
43+
}
44+
45+
override fun getFileNodeType(): IFileElementType {
46+
return FILE
47+
}
48+
49+
override fun getCommentTokens(): TokenSet {
50+
return TokenSet.EMPTY
51+
}
52+
53+
override fun getStringLiteralElements(): TokenSet {
54+
return TokenSet.EMPTY
55+
}
56+
57+
override fun createElement(node: ASTNode): PsiElement {
58+
return RobotPsiElement(node.elementType)
59+
}
60+
61+
override fun createFile(viewProvider: FileViewProvider): PsiFile {
62+
return RobotFile(viewProvider)
63+
}
64+
}
65+
66+
class RobotFile(viewProvider: FileViewProvider) : PsiFileBase(viewProvider, RobotFrameworkLanguage) {
67+
override fun getFileType(): FileType {
68+
return RobotSuiteFileType
69+
}
70+
}
71+
72+
class RobotPsiParser : PsiParser {
73+
override fun parse(root: IElementType, builder: PsiBuilder): ASTNode {
74+
val mark = builder.mark()
75+
while (!builder.eof()) {
76+
builder.advanceLexer()
77+
}
78+
mark.done(root)
79+
80+
return builder.treeBuilt
81+
}
82+
}
83+
84+
class RobotPsiElement(type: IElementType) : CompositePsiElement(type) {
85+
86+
}

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,5 @@ class RobotCodePostStartupActivity : ProjectActivity {
2424
}.collect()
2525
}
2626

27-
2827
}
2928

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

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,35 +3,41 @@ package dev.robotcode.robotcode4ij
33
import com.intellij.openapi.editor.DefaultLanguageHighlighterColors
44
import com.intellij.openapi.editor.colors.TextAttributesKey
55
import com.intellij.openapi.editor.colors.TextAttributesKey.createTextAttributesKey
6-
import com.intellij.openapi.editor.markup.EffectType
7-
import com.intellij.openapi.editor.markup.TextAttributes
86

97
object RobotColors {
8+
109
val HEADER: TextAttributesKey =
11-
createTextAttributesKey(
12-
"ROBOTFRAMEWORK_HEADER", TextAttributes(
13-
null, null,
14-
DefaultLanguageHighlighterColors.KEYWORD
15-
.defaultAttributes.foregroundColor,
16-
EffectType
17-
.LINE_UNDERSCORE, 1
18-
)
19-
)
10+
createTextAttributesKey("ROBOTFRAMEWORK_HEADER", DefaultLanguageHighlighterColors.KEYWORD)
2011

2112
val TESTCASE_NAME: TextAttributesKey =
22-
createTextAttributesKey(
23-
"ROBOTFRAMEWORK_TESTCASE_NAME", TextAttributes(
24-
null, null, null,
25-
null, 1
26-
)
27-
)
13+
createTextAttributesKey("ROBOTFRAMEWORK_TESTCASE_NAME", DefaultLanguageHighlighterColors.FUNCTION_DECLARATION)
2814

2915
val KEYWORD_NAME: TextAttributesKey =
30-
createTextAttributesKey(
31-
"ROBOTFRAMEWORK_TESTCASE_NAME", TextAttributes(
32-
null, null, null,
33-
null, 1
34-
)
35-
)
16+
createTextAttributesKey("ROBOTFRAMEWORK_KEYWORD_NAME", DefaultLanguageHighlighterColors.FUNCTION_DECLARATION)
17+
val KEYWORD_CALL: TextAttributesKey =
18+
createTextAttributesKey("ROBOTFRAMEWORK_KEYWORD_CALL", DefaultLanguageHighlighterColors.FUNCTION_CALL)
19+
20+
val SETTING: TextAttributesKey =
21+
createTextAttributesKey("ROBOTFRAMEWORK_SETTING", DefaultLanguageHighlighterColors.KEYWORD)
22+
val SETTING_IMPORT: TextAttributesKey =
23+
createTextAttributesKey("ROBOTFRAMEWORK_SETTING_IMPORT", DefaultLanguageHighlighterColors.KEYWORD)
24+
val CONTROL_FLOW: TextAttributesKey =
25+
createTextAttributesKey("ROBOTFRAMEWORK_CONTROL_FLOW", DefaultLanguageHighlighterColors.KEYWORD)
26+
27+
val EMBEDDED_ARGUMENT: TextAttributesKey =
28+
createTextAttributesKey("ROBOTFRAMEWORK_EMBEDDED_ARGUMENT", DefaultLanguageHighlighterColors.STRING)
29+
30+
val VARIABLE: TextAttributesKey =
31+
createTextAttributesKey("ROBOTFRAMEWORK_VARIABLE", DefaultLanguageHighlighterColors.GLOBAL_VARIABLE)
32+
val VARIABLE_EXPRESSION: TextAttributesKey =
33+
createTextAttributesKey("ROBOTFRAMEWORK_VARIABLE_EXPRESSION", DefaultLanguageHighlighterColors.GLOBAL_VARIABLE)
34+
val VARIABLE_BEGIN: TextAttributesKey =
35+
createTextAttributesKey("ROBOTFRAMEWORK_VARIABLE_BEGIN", DefaultLanguageHighlighterColors.BRACES)
36+
val VARIABLE_END: TextAttributesKey =
37+
createTextAttributesKey("ROBOTFRAMEWORK_VARIABLE_BEGIN", DefaultLanguageHighlighterColors.BRACES)
38+
39+
val NAMESPACE: TextAttributesKey =
40+
createTextAttributesKey("ROBOTFRAMEWORK_NAMESPACE", DefaultLanguageHighlighterColors.CLASS_REFERENCE)
41+
3642
}
3743

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@ package dev.robotcode.robotcode4ij
22

33
import com.intellij.lang.Language
44

5-
class RobotFrameworkLanguage : Language("robotframework") {
6-
companion object {
7-
val INSTANCE = RobotFrameworkLanguage();
8-
}
9-
5+
object RobotFrameworkLanguage : Language("robotframework") {
6+
private fun readResolve(): Any = RobotFrameworkLanguage
107
override fun getDisplayName() = "Robot Framework"
11-
}
8+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@ public class RobotIcons {
99
val Suite: Icon? = IconLoader.findIcon("/images/robot.svg", RobotIcons.Companion::class.java);
1010
val RobotCode: Icon? = IconLoader.findIcon("/images/robotcode.svg", RobotIcons.Companion::class.java);
1111
}
12-
12+
1313
}

0 commit comments

Comments
 (0)