-
-
Notifications
You must be signed in to change notification settings - Fork 105
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
fix: lua function declaration name highlighting #250
Conversation
This PR belongs to nvim-treesitter Also please take performance into consideration, this query isn't good. |
I get that. If you had read my post you would have seen this comment:
Why isn't the performance very good? Do you have proof of this? There shouldn't be any issues with performance: the file is small and the query only recurses as needed/necessary depending upon the code (number of properties/dot expressions present) that the query is being applied to. The only thing is that there may be a small increase in parse time, however, ts queries are entirely parsed and compiled in C. The entire implementation for running a query is likewise in C, even on Neovim's side (i.e. the entire Yes the solution is not pretty, perhaps a pinch harder to look at and maintain, but it gets the job done and there is no alternative to accomplish the very same thing that I am aware of. The only real caveat is that it only works up to a limited number of indices, but this should be sufficient for 99.9% of code. If the query "isn't good", do you have an alternative better solution or suggestion? Performance implications of this pr amount to all of:
|
Unsure why but wouldn't (function_declaration
[
(method_index_expression)
(dot_index_expression)
] @func)
(method_index_expression ":" @punctuation)
(dot_index_expression ":" @punctuation) suffice? |
Yeah something similar to this is what I originally had and would work for making the entire name one color, however it would not allow the end-user to highlight the different parts of the function declaration name independently (e.g. it could not be customized/overridden via the hl group overrides passed to (method_index_expression ":" @punctuation)
(dot_index_expression ":" @punctuation) This^ would be too general as this query would also apply to index expressions not in fn declaration names. Also, ...but yeah, that's the general idea and is what I originally had. Also see |
Time to read file and parse query, no
|
Within a function declaration, the entire function name should be the same color, regardless of whether it's a method etc., and including any punctuation within. This change also introduces new treesitter-capture highlight groups which may each be independently overridden by the user. Note: in Neovim, groups like `@x.y.z` fallback to `@x` implicitly if `@x.y.z` is not defined.
I reduced the size of the query/pattern slightly; it now covers up to 8 fields. I believe that this should still be sufficient for most Lua found out in the wild. The maintainer of the Lua treesitter grammar said that they didn't want to change these recursive nodes to be sequential as this is a common pattern among all of the language grammars. There is an issue open in the treesitter repo for recursive query support, but it has been open for a couple of years now and hasn't gotten that much attention. I still need to incorporate these changes into the default highlight query and see if nvim-treesitter wants it, I haven't done that yet. |
Within a function declaration, the entire function name should be the same color, regardless of whether it's a method etc., and including any punctuation within. This change introduces new treesitter-capture highlight groups which may each be independently overridden by the user.
Note: in Neovim, groups like
@x.y.z
fallback to@x
implicitly if@x.y.z
is not defined.