-
Hi, I'm trying to figure out how to remove highlighting for variables. For context, In the go language, I just want to have the variable declarations highlighted. Anytime a variable is used though I want it to not be highlighted. In the current highlighting code it highlights all variables (identifiers). Is there a way to remove the highlighting on identifiers? I've figured out how to isolate just declarations as follows:
but I don't know what capture name (if any) to use for just the |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 2 replies
-
We don't have a mechanism to selectively remove a specific highlighting pattern yet. There are 2 things you can do at the moment:
(define-advice tree-sitter-langs--hl-query-path (:before-until (lang-symbol) override-default-patterns)
(pcase lang-symbol
('go "/path/to/your/modified/highlights.scm"))) Not highlighting all identifiers as
;; tree-sitter-hl.el doesn't have this face, but it probably should.
(defface tree-sitter-hl-face:nil
'((default :inherit default))
""
:group 'tree-sitter-hl-faces)
(tree-sitter-hl-add-patterns 'go
[(short_var_declaration left: (expression_list (identifier) @variable))
(var_declaration (var_spec name: (identifier) @variable))
;; This is prioritized over the default from highlights.scm.
(identifier) @nil]) |
Beta Was this translation helpful? Give feedback.
-
@ubolonton thanks for the response! Is there something that documents |
Beta Was this translation helpful? Give feedback.
-
There is no documentation on that yet. The rule of thumb is following the docstrings of the faces defined in tree-sitter-hl.el. Some notable conventions are:
Note that the package |
Beta Was this translation helpful? Give feedback.
We don't have a mechanism to selectively remove a specific highlighting pattern yet.
There are 2 things you can do at the moment:
(tree-sitter-langs--hl-query-path 'go)
. Modify it to suit your need. Then advise the functiontree-sitter-langs--hl-query-path
to return that file instead. For example:Not highlighting all identifiers as
@variable
is actually consistent withtree-sitter-langs
's styles. The Go patterns should be modified to do so. A pull request is welcome.