-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add tree-sitter-comment #1170
Add tree-sitter-comment #1170
Conversation
((tag ((name) @warning)) | ||
(#any-of? @warning "TODO" "HACK" "WARNING")) | ||
|
||
("text" @warning | ||
(#any-of? @warning "TODO" "HACK" "WARNING")) | ||
|
||
((tag ((name) @error)) | ||
(#any-of? @error "FIXME" "XXX" "BUG")) | ||
|
||
("text" @error | ||
(#any-of? @error "FIXME" "XXX" "BUG")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
any-of?
isn't actually supported by us: #887 (comment)
Should be possible to implement though
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you should be able to replace any #any-of?
with an equivalent (but kinda ugly) #match?
like here:
helix/runtime/queries/elixir/highlights.scm
Lines 181 to 184 in 6e62c3d
( | |
(identifier) @constant.builtin | |
(#match? @constant.builtin "^(__MODULE__|__DIR__|__ENV__|__CALLER__|__STACKTRACE__)$") | |
) |
it might be nice to add #any-of?
eventually, I think I've seen it in a bunch of different languages' queries
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think #any-of?
is the issue. I tried removing everything in the comment highlight file but still it didn't get comment highlight as fallback color.
testing out & debugging queries is not super easy with tree-sitter the way I tend to do it is by starting up a |
Ok sorry for the delay, I had some time to investigate and it looks like there might be two problems at play. The first is a precedence rule thing that happens when migrating queries from neovim and then other I think might be a bug in injections but I'm not sure yet. The precedence problem is that neovim will give preference to the last matching stanza in (tag (name) @ui.text (user)? @constant) on line 8 which is coloring tags as text and seems to be a kind of "default" rule for tags is matching all tags, and so the subsequent stanzas for tag don't ever match. Setting up a fake [[language]]
name = "comment"
scope = "scope.comment"
roots = []
file-types = ["comment"] I get a good-looking highlight on my where I've touched up the queries so that the default tag rule goes to the bottom (as well as other misc changes to line up the queries with how helix expects them): [
"("
")"
] @punctuation.bracket
":" @punctuation.delimiter
((tag (name) @warning)
(#match? @warning "^(TODO|HACK|WARNING)$"))
("text" @warning
(#match? @warning "^(TODO|HACK|WARNING)$"))
((tag (name) @error)
(match? @error "^(FIXME|XXX|BUG)$"))
("text" @error
(match? @error "^(FIXME|XXX|BUG)$"))
(tag
(name) @ui.text
(user)? @constant)
; Issue number (#123)
("text" @constant.numeric
(#match? @constant.numeric "^#[0-9]+$"))
; User mention (@user)
("text" @tag
(#match? @tag "^[@][a-zA-Z0-9_-]+$")) This is viewing a file just using the comment tree-sitter and highlights though, and those same highlights seem to change dramatically when using injection, including the problem where each first word on a comment line gets highlighted. I'll have to dig a little deeper to figure out how the injection stuff works to give a perspective on that |
ah actually the injection appears to work well with a languages.toml entry like so: [[language]]
name = "comment"
scope = "scope.comment"
roots = []
file-types = ["comment"]
injection-regex = "comment" we need the |
Great work! I also noticed we need to fix some of the injection definitions that use
|
Thanks @the-mikedavis for helping out on this, I guess I will close this for now since the new PR is out. |
* Add tree-sitter-comment Fix #1164 * fix precedence in tree-sitter-comment highlights connects #1170 * set injection-regex for comment language * remove comment filetype * fix comment injections for neovim-style injections tags * add comment injections for elixir * remove f.comment * fix spacing in .gitmodules * run 'cargo xtask docgen' Co-authored-by: Ivan Tham <[email protected]>
Fix #1164
Not working yet.
cc @the-mikedavis can you please help me out? Not sure why it highlights the first word differently. I am also not sure how to debug tree-sitter.