-
Notifications
You must be signed in to change notification settings - Fork 112
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
Divide capture groups more precisely, for better control over highlighting. #177
Comments
Right now, it is possible for user to create custom groups themselves : nvim-treesitter/nvim-treesitter#167 Example: Custom group for variable declarations
Although, It would better if they were more specific by default. |
Hey all! This seems like a popular request (so many thumbs-up!). This isn't my expertise as we don't use the tree-sitter parsers for this at all. I'll defer to @maxbrunsfeld and to the GitHub folks who know about these choices. Meanwhile: Different constructs are given the same name via the |
I did some groups overriding as per above method & here are the results. Things are easier to distinguish & are made more logical. READ comments for elements which are changed. export keyword rule is directly added in main source file, because overriding was not working due to priority issues. |
This would greatly help me resolve Iron-E/nvim-highlite#15 in my colorscheme. Rather than writing new queries I could simply link highlight types to look as expected. I too have noticed traditional regex plugins provide finer control, and haven't had time to write custom queries to bridge the gap. Edit: to be specific, I would be in favor of making all the treesitter groups more precise in this way, not just typescript. |
Does anybody know how to give user customized rules priority than builtin ones? Like export keyword in above example. |
((super_important_node) @superimportant (#set! "priority" 105)) You may have to add |
How can I use these files to enhance the highlights in my colorscheme? Currently, both the 'await' and 'export' keywords are treated the same, but I want them to have different colors. |
I think current capture / highlighting groups are somewhat vague & need to be divided more precisely.
E.g. currently :
variable declaration & variable used in code share the same group
@variable
. They could be separate -@variable
&@declaration
or something like that.All types of brackets, braces & parens share the same group
@punctuation.bracket
. They could be separate -@punctuation.paren
,@punctuation.brace
, etc.Object key (when defining) & property (when using) have the same group
@property
. One more could be added like@object.key
.try & catch keyword share the same group
@exception
. They could be separate -@exception.try
&@exception.catch
import & from keyword share the same group
@include
. They could be separates@include.import
,@include.from
. There are many more vague keywords.Regular strings & backtick (template strings) share the same group
@string
. One more could be added -@string.template
.....
Why
Doing this will allow user to create more precise highlighting of the code. For e.g. one could make try block in green color, & catch block in red. As catch only executes when try block produces errors. Different uses have different taste, so this will allow users to highlight each part of code exactly as they want.
Lot of traditional syntax highlighting file (e.g. vim-javascript) provide these kinds of precisions & allows better control over code highlighting. The mentioned syntax file even provides separate groups for braces of objects, function, conditionals, etc.
The text was updated successfully, but these errors were encountered: