|
| 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))) |
0 commit comments