Skip to content

Commit 5cdf3c3

Browse files
committed
fix(intellij): reenable semantic highlightning, because something has changed in the new LSP4IJ API
1 parent e94c96b commit 5cdf3c3

File tree

11 files changed

+147
-10
lines changed

11 files changed

+147
-10
lines changed

intellij-client/gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ platformVersion = 2025.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
20-
#platformPlugins = com.redhat.devtools.lsp4ij:0.13.0-20250501-072621@nightly
20+
#platformPlugins = com.redhat.devtools.lsp4ij:0.13.0-20250502-121924@nightly
2121
platformPlugins = com.redhat.devtools.lsp4ij:0.12.0
2222

2323

intellij-client/gradle/libs.versions.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
[versions]
22
# libraries
33
annotations = "26.0.2"
4-
kotlinxSerialization = "1.8.1"
4+
kotlinxSerialization = "1.7.3"
55
junit = "4.13.2"
66
lsp4j = "0.21.1"
77

88
# plugins
99
changelog = "2.2.1"
1010
intelliJPlatForm = "2.5.0"
11-
kotlin = "2.1.0"
11+
kotlin = "2.1.10"
1212
kover = "0.9.1"
1313

1414
[libraries.lsp4j]

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ class RobotCodeSyntaxHighlighter : SyntaxHighlighterBase() {
9292
)
9393
}
9494

95-
9695
private val myLexer = RobotCodeLexer()
9796

9897
override fun getHighlightingLexer(): Lexer {

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ private val mapping by lazy {
2828
"nameCall" to Colors.NAME_CALL,
2929
"argument" to Colors.ARGUMENT,
3030
"embeddedArgument" to Colors.EMBEDDED_ARGUMENT,
31+
"argument,embedded" to Colors.EMBEDDED_ARGUMENT,
3132
"namedArgument" to Colors.NAMED_ARGUMENT,
3233
"variable" to Colors.VARIABLE,
3334
"variableExpression" to Colors.VARIABLE_EXPRESSION,
@@ -44,10 +45,14 @@ class RobotCodeSemanticTokensColorsProvider : DefaultSemanticTokensColorsProvide
4445
override fun getTextAttributesKey(
4546
tokenType: String, tokenModifiers: MutableList<String>, file: PsiFile
4647
): TextAttributesKey? {
47-
val result = mapping[tokenType] ?: super.getTextAttributesKey(tokenType, tokenModifiers, file)
48+
var tokenTypeAndModifiers = tokenType
49+
if (tokenModifiers.isNotEmpty()) {
50+
tokenTypeAndModifiers += ",${tokenModifiers.joinToString(",")}"
51+
}
52+
val result = mapping[tokenTypeAndModifiers] ?: mapping[tokenType] ?: super.getTextAttributesKey(tokenType, tokenModifiers, file)
4853

4954
return result ?: run {
50-
thisLogger().warn("Unknown token type: $tokenType")
55+
thisLogger().warn("Unknown token type: $tokenType and modifiers: $tokenModifiers")
5156
null
5257
}
5358
}
Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,35 @@
11
package dev.robotcode.robotcode4ij.lsp
22

3+
import com.intellij.lang.Language
4+
import com.intellij.openapi.vfs.VirtualFile
5+
import com.intellij.psi.FileViewProvider
36
import com.intellij.psi.FileViewProviderFactory
7+
import com.intellij.psi.PsiManager
8+
import com.redhat.devtools.lsp4ij.features.semanticTokens.viewProvider.LSPSemanticTokensFileViewProvider
9+
import com.redhat.devtools.lsp4ij.features.semanticTokens.viewProvider.LSPSemanticTokensSingleRootFileViewProvider
10+
import dev.robotcode.robotcode4ij.RobotFrameworkLanguage
411

5-
class RobotCodeTokensFileViewProviderFactory : FileViewProviderFactory
12+
class RobotCodeTokensFileViewProviderFactory : FileViewProviderFactory {
13+
override fun createFileViewProvider(
14+
file: VirtualFile,
15+
language: Language?,
16+
manager: PsiManager,
17+
eventSystemEnabled: Boolean
18+
): FileViewProvider {
19+
if (language == RobotFrameworkLanguage) {
20+
return RobotCodeTokensFileViewProvider(manager, file, eventSystemEnabled, language)
21+
}
22+
throw UnsupportedOperationException("Unsupported language: $language or file: $file")
23+
}
24+
}
25+
26+
class RobotCodeTokensFileViewProvider(
27+
manager: PsiManager,
28+
file: VirtualFile,
29+
eventSystemEnabled: Boolean,
30+
language: Language
31+
) : LSPSemanticTokensSingleRootFileViewProvider(manager, file, eventSystemEnabled, language),
32+
LSPSemanticTokensFileViewProvider {
33+
34+
35+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package dev.robotcode.robotcode4ij.lsp
2+
3+
import com.intellij.codeInsight.daemon.impl.HighlightVisitor
4+
import com.intellij.codeInsight.daemon.impl.analysis.HighlightInfoHolder
5+
import com.intellij.openapi.diagnostic.thisLogger
6+
import com.intellij.psi.PsiElement
7+
import com.intellij.psi.PsiFile
8+
import com.redhat.devtools.lsp4ij.LSPFileSupport
9+
import com.redhat.devtools.lsp4ij.LSPIJUtils
10+
import com.redhat.devtools.lsp4ij.features.semanticTokens.LazyHighlightInfo
11+
import com.redhat.devtools.lsp4ij.internal.PsiFileChangedException
12+
import dev.robotcode.robotcode4ij.RobotFrameworkLanguage
13+
import kotlinx.coroutines.future.await
14+
import kotlinx.coroutines.runBlocking
15+
import org.eclipse.lsp4j.SemanticTokensParams
16+
import java.util.concurrent.ExecutionException
17+
18+
class RobotSemanticTokensHighlightVisitor : HighlightVisitor {
19+
override fun suitableForFile(file: PsiFile): Boolean {
20+
return file.language == RobotFrameworkLanguage
21+
}
22+
23+
override fun visit(element: PsiElement) {
24+
// No-op
25+
}
26+
27+
override fun analyze(
28+
file: PsiFile,
29+
updateWholeFile: Boolean,
30+
holder: HighlightInfoHolder,
31+
action: Runnable
32+
): Boolean {
33+
action.run()
34+
runBlocking {
35+
highlight(file, holder)
36+
}
37+
return true
38+
}
39+
40+
suspend fun highlight(file: PsiFile, holder: HighlightInfoHolder) {
41+
val semanticTokensSupport = LSPFileSupport.getSupport(file).getSemanticTokensSupport()
42+
val params = SemanticTokensParams(LSPIJUtils.toTextDocumentIdentifier(file.virtualFile))
43+
44+
val semanticTokens = try {
45+
semanticTokensSupport.getSemanticTokens(params).await()
46+
} catch (_: PsiFileChangedException) {
47+
semanticTokensSupport.cancel()
48+
return
49+
} catch (e: ExecutionException) {
50+
thisLogger().error("Error while consuming LSP 'textDocument/semanticTokens/full' request", e)
51+
return
52+
}
53+
54+
val document = LSPIJUtils.getDocument(file.virtualFile) ?: return
55+
56+
semanticTokens.highlight(file, document) { start, end, colorKey ->
57+
holder.add(LazyHighlightInfo.resolve(start, end, colorKey))
58+
}
59+
}
60+
61+
override fun clone(): HighlightVisitor {
62+
return RobotSemanticTokensHighlightVisitor()
63+
}
64+
}

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,13 @@ class RobotCodeParserDefinition : ParserDefinition {
3434
}
3535

3636
override fun getStringLiteralElements(): TokenSet {
37-
// return STRING_TOKENS
38-
return TokenSet.EMPTY
37+
return STRING_TOKENS
3938
}
4039

4140
override fun createElement(node: ASTNode): PsiElement {
4241
return when (node.elementType) {
43-
is IRobotFrameworkElementType -> SimpleASTWrapperPsiElement(node)
4442
is RobotTextMateElementType -> ASTWrapperPsiElement(node)
43+
is IRobotFrameworkElementType -> SimpleASTWrapperPsiElement(node)
4544

4645
else -> throw IllegalArgumentException("Unknown element type: ${node.elementType}")
4746
}

intellij-client/src/main/resources/META-INF/plugin.xml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
<depends>com.intellij.modules.python</depends>
1010
<depends>com.redhat.devtools.lsp4ij</depends>
1111
<depends>org.jetbrains.plugins.textmate</depends>
12+
1213
<incompatible-with>robocorp.lsp.intellij</incompatible-with>
1314
<incompatible-with>com.github.jnhyperion.hyperrobotframeworkplugin</incompatible-with>
1415
<incompatible-with>com.millennialmedia.intellibot</incompatible-with>
@@ -50,6 +51,27 @@
5051
language="robotframework"
5152
implementationClass="com.redhat.devtools.lsp4ij.features.documentSymbol.LSPDocumentSymbolStructureViewFactory"/>
5253

54+
<callHierarchyProvider
55+
language="robotframework"
56+
implementationClass="com.redhat.devtools.lsp4ij.features.callHierarchy.LSPCallHierarchyProvider"/>
57+
58+
<codeBlockProvider
59+
language="robotframework"
60+
implementationClass="com.redhat.devtools.lsp4ij.features.codeBlockProvider.LSPCodeBlockProvider"
61+
order="first"/>
62+
63+
<highlightVisitor
64+
id="robotframework"
65+
implementation="dev.robotcode.robotcode4ij.lsp.RobotSemanticTokensHighlightVisitor"
66+
order="first"/>
67+
68+
<typeHierarchyProvider language="robotframework"
69+
implementationClass="com.redhat.devtools.lsp4ij.features.typeHierarchy.LSPTypeHierarchyProvider"/>
70+
71+
<lang.fileViewProviderFactory
72+
language="robotframework"
73+
implementationClass="dev.robotcode.robotcode4ij.lsp.RobotCodeTokensFileViewProviderFactory"/>
74+
5375
<postStartupActivity implementation="dev.robotcode.robotcode4ij.RobotCodePostStartupActivity"/>
5476

5577
<projectConfigurable parentId="language"

intellij-client/src/main/resources/colorSchemes/RobotDarculaColorScheme.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,10 @@
2020
<option name="FONT_TYPE" value="1"/>
2121
</value>
2222
</option>
23+
<option name="ROBOTFRAMEWORK_EMBEDDED_ARGUMENT">
24+
<value>
25+
<option name="FOREGROUND" value="6A8759" />
26+
<option name="FONT_TYPE" value="2" />
27+
</value>
28+
</option>
2329
</list>

intellij-client/src/main/resources/colorSchemes/RobotDarkColorScheme.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,10 @@
1717
<option name="FONT_TYPE" value="1"/>
1818
</value>
1919
</option>
20+
<option name="ROBOTFRAMEWORK_EMBEDDED_ARGUMENT">
21+
<value>
22+
<option name="FOREGROUND" value="6AAB73" />
23+
<option name="FONT_TYPE" value="2" />
24+
</value>
25+
</option>
2026
</list>

intellij-client/src/main/resources/colorSchemes/RobotLightColorScheme.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,10 @@
1717
<option name="FONT_TYPE" value="1"/>
1818
</value>
1919
</option>
20+
<option name="ROBOTFRAMEWORK_EMBEDDED_ARGUMENT">
21+
<value>
22+
<option name="FOREGROUND" value="067D17" />
23+
<option name="FONT_TYPE" value="2" />
24+
</value>
25+
</option>
2026
</list>

0 commit comments

Comments
 (0)