-
Notifications
You must be signed in to change notification settings - Fork 212
Semantic Tokens
The symbol highlighting in Emacs is based on treesit, but treesit cannot highlight some semantic symbols, such as macro definitions in C or C++:
Therefore, lsp-bridge
provides lsp-bridge-semantic-tokens-mode
, which instructs Emacs to highlight some special semantic symbols. The image below shows the effect after enabling it:
In the LSP protocol, semantic symbols consist of types and modifiers, such as global variable, which has a type of variable and a modifier of global scope. Some semantic symbols do not have modifiers, such as comment types.
The lsp-bridge-semantic-tokens-mode
provides three variables to control which semantic symbols are highlighted:
-
lsp-bridge-semantic-tokens-type-faces
: faces corresponding to symbol types -
lsp-bridge-semantic-tokens-type-modifier-faces
: faces corresponding to symbol modifiers -
lsp-bridge-semantic-tokens-ignore-modifier-limit-types
: only symbols with defined type faces and modifier faces will be highlighted. Adding types to this variable allows ignoring the check for symbol modifiers.
For example, to highlight global variables, the following settings need to be made before starting lsp-bridge-mode
:
(defface lsp-bridge-semantic-tokens-variable-face
'((t (:inherit font-lock-variable-name-face)))
"Face used for variable name."
:group 'lsp-bridge-semantic-tokens)
(defface lsp-bridge-semantic-tokens-global-scope-face
'((t :weight extra-bold))
"Face used for globalScope token."
:group 'lsp-bridge-semantic-tokens)
(setq-default lsp-bridge-semantic-tokens-type-faces
[("variable" . lsp-bridge-
semantic-tokens-variable-face)])
(setq-default lsp-bridge-semantic-tokens-type-modifier-faces
[("globalScope" . lsp-bridge-semantic-tokens-global-scope-face)])
(setq-default lsp-bridge-semantic-tokens-ignore-modifier-limit-types [])
If you want to highlight all variables, regardless of whether they are global or local variables, you can add the "variable" type to the lsp-bridge-semantic-tokens-ignore-modifier-limit-types
and ignore the check for modifiers:
(setq-default lsp-bridge-semantic-tokens-ignore-modifier-limit-types ["variable"])