ccls 的一个feature branch (Support LSP semantic tokens by MaskRay · Pull Request #972 · MaskRay/ccls · GitHub) 支持 LSP semantic tokens。我打算废弃掉现有的 emacs-ccls/ccls-semantic-highlight.el ,得用 semantic tokens 模拟 rainbow semantic highlighting。
ccls and LSP Semantic Tokens | MaskRay 提到了一个解决方案,但我现在不怎么用Emacs了没有力气找到正确的loop + defface 方式:
(setq lsp-semantic-tokens-enable t)
(defface lsp-face-semhl-namespace-scope '((t :weight bold)) "highlight for namespace scope symbols" :group 'lsp-semantic-tokens)
(custom-set-faces
'(lsp-face-semhl-definition ((t :inherit font-lock-function-name-face)))
'(lsp-face-semhl-static ((t :weight bold)))
'(lsp-face-semhl-member ((t :slant italic)))
)
(defface lsp-face-semhl-id0 '((t :foreground "#429921")) "" :group 'lsp-semantic-tokens)
(defface lsp-face-semhl-id1 '((t :foreground "#58c1a4")) "" :group 'lsp-semantic-tokens)
(defface lsp-face-semhl-id2 '((t :foreground "#98c1a4")) "" :group 'lsp-semantic-tokens)
(defface lsp-face-semhl-id3 '((t :foreground "#6851a4")) "" :group 'lsp-semantic-tokens)
(defface lsp-face-semhl-id4 '((t :foreground "#3b51c4")) "" :group 'lsp-semantic-tokens)
... needs 10 IDs
(setq lsp-semantic-token-modifier-faces
'(("declaration" . lsp-face-semhl-interface)
("definition" . lsp-face-semhl-definition)
("implementation" . lsp-face-semhl-implementation)
("readonly" . lsp-face-semhl-constant)
("static" . lsp-face-semhl-static)
("deprecated" . lsp-face-semhl-deprecated)
("abstract" . lsp-face-semhl-keyword)
("async" . lsp-face-semhl-macro)
("modification" . lsp-face-semhl-operator)
("documentation" . lsp-face-semhl-comment)
("defaultLibrary" . lsp-face-semhl-default-library)
("classScope" . lsp-face-semhl-member)
("namespaceScope" . lsp-face-semhl-namespace-scope)
("id0" . lsp-face-semhl-id0)
("id1" . lsp-face-semhl-id1)
("id2" . lsp-face-semhl-id2)
("id3" . lsp-face-semhl-id3)
("id4" . lsp-face-semhl-id4)
.... needs 10 IDs
))