nushell / tree-sitter-nu

A tree-sitter grammar for nu-lang, the language of nushell
MIT License
122 stars 27 forks source link

nvim queries: Conform to commonly used highlight names #99

Closed hedyhli closed 5 months ago

hedyhli commented 5 months ago

This updates:

Query Highlight name Like in...
Punctuation :, , punctuation.special TOML, Bash, JSON, ...
Key fields in tables/records variable.member Go, Zig, V, TOML
Returns -> punctuation.special Rust
Variable $ punctuation.special Bash, Awk
Variable identifier variable Bash, Awk, Perl, Fish
Shebang keyword.directive Bash, Awk
Built-in types type Zig et al[^1]
Numbers number Zig, Rust, Python, TOML, Bash, ...
Arguments variable.parameter Bash[^2]
Redirect operator operator Bash, Fish
Redirect destination variable.parameter Bash

[^1]: Note that for built-in types, languages like Rust, Python, Go differentiates highlights of built-in types and other types (such as structs), but there are no other types in Nu, I'll leave this up to debate, IMO a generic type will suffice here.

[^2]: Perl, Fish and Awk all leave these unhighlighted.

Also adds highlights for documentation comments for functions and parameters.

I've tried to put newly introduced highlight queries into the correct groups in the file, let me know if there are any other prevailing styles I should follow!

fdncred commented 5 months ago

I'm willing to give this a try. I like this idea for sure!! Thanks

fdncred commented 5 months ago

How do you control which highlights.scm file nvim uses for a particular language?

hedyhli commented 5 months ago

How do you control which highlights.scm file nvim uses for a particular language?

If the Lua plugin in this repo is used, the file will be in queries/nu/ in the runtime. And nvim-treesitter will see the filetype, nu, then fetch queries/<nu>/ in the runtime.

If there are multiple, precendence is determined in a similar manner to $PATH, as listed in :set rtp?. Notice how the first path is ~/.config/nvim, so to have a queries/nu/highlight.scm file override all others of the same path in the runtime, then put it in ~/.config/nvim/queries/nu/highlight.scm.

fdncred commented 5 months ago

That's very helpful. Thanks

fdncred commented 5 months ago

It looks like the highlighting is a bit off now. This is from the toolkit.nu file in the root of the nushell repo.

Before

image

After

image

fdncred commented 5 months ago

@hedyhli wondering about your thoughts on this broken highlighting?

fdncred commented 4 months ago

@hedyhli will you have an opportunity to look at this issue?