Skip to content

Commit d6d9263

Browse files
committed
improve semantic tokens
1 parent abba58c commit d6d9263

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
(ns com.github.clojure-lsp.intellij.extension.semantic-token-provider
2+
(:gen-class
3+
:name com.github.clojure_lsp.intellij.extension.ClojureSemanticTokensColorsProvider
4+
:implements [com.redhat.devtools.lsp4ij.features.semanticTokens.SemanticTokensColorsProvider])
5+
(:import
6+
[com.intellij.openapi.editor.colors TextAttributesKey]
7+
[com.intellij.psi PsiFile]
8+
[com.redhat.devtools.lsp4ij.features.semanticTokens DefaultSemanticTokensColorsProvider SemanticTokensHighlightingColors]
9+
[java.awt Font]
10+
[java.util List]
11+
[org.eclipse.lsp4j SemanticTokenModifiers SemanticTokenTypes]))
12+
13+
(def ^:private default-provider (DefaultSemanticTokensColorsProvider.))
14+
15+
(defn ^:private modifier? [modifier token-modifiers]
16+
(some #(= modifier %) token-modifiers))
17+
18+
(defn make-bold [^TextAttributesKey text-attribute-key]
19+
(TextAttributesKey/createTextAttributesKey
20+
(str (.getExternalName text-attribute-key) "_BOLD")
21+
(doto (.clone (.getDefaultAttributes text-attribute-key))
22+
(.setFontType Font/BOLD))))
23+
24+
(def ^:private bold-function-declaration
25+
(make-bold SemanticTokensHighlightingColors/FUNCTION_DECLARATION))
26+
27+
(defn -getTextAttributesKey [_ ^String token-type ^List token-modifiers ^PsiFile psi-file]
28+
(condp = token-type
29+
SemanticTokenTypes/Namespace SemanticTokensHighlightingColors/STATIC_PROPERTY
30+
SemanticTokenTypes/Function (if (modifier? SemanticTokenModifiers/Definition token-modifiers)
31+
bold-function-declaration
32+
SemanticTokensHighlightingColors/MACRO)
33+
SemanticTokenTypes/Type SemanticTokensHighlightingColors/STATIC_PROPERTY
34+
SemanticTokenTypes/Variable SemanticTokensHighlightingColors/READONLY_VARIABLE
35+
SemanticTokenTypes/Keyword SemanticTokensHighlightingColors/NUMBER
36+
(.getTextAttributesKey default-provider token-type token-modifiers psi-file)))

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@
1717
]]>
1818
</description>
1919
</server>
20-
2120
<languageMapping language="clojure" serverId="clojure-lsp"/>
21+
<semanticTokensColorsProvider
22+
serverId="clojure-lsp"
23+
class="com.github.clojure_lsp.intellij.extension.ClojureSemanticTokensColorsProvider" />
2224
</extensions>
2325

2426
<extensions defaultExtensionNs="com.intellij">

0 commit comments

Comments
 (0)