HiPhish / nvim-ts-rainbow2

Rainbow delimiters for Neovim through Tree-sitter
https://gitlab.com/HiPhish/nvim-ts-rainbow2
Apache License 2.0
338 stars 35 forks source link

Add Rust query and test files #3

Closed CatThingy closed 1 year ago

CatThingy commented 1 year ago

This was my first time writing a query - code cleanup suggestionss would be appreciated.

HiPhish commented 1 year ago

Hello,

Thank you very much for your contribution, but Tree-sitter is showing me four parser errors in the syntax tree of your sample Rust file. Please fix the errors, I only want syntactically correct code in the test files. Otherwise the test is not really representative of a real source file. It would be cool if your code could also compile, but that's not necessary.

I don't know Rust, so unfortunately I cannot help you out with that part. I use the TS Playground to inspect the syntax tree. You can press a to toggle anonymous nodes and o to open a query editor where you can try out your queries and get life feedback.

BTW, how did you find out what captures to use? Did you read the manual? If so, what is your opinion, is there something I should improve? I wanted to write a proper contribution guide eventually, but beat me to it.

CatThingy commented 1 year ago

The tree-sitter parser errors appear to be errors in the tree-sitter parser, as the test file does compile (with a typo fixed).

I implemented my query by using the other implemented queries as an example. I skimmed over the manual, but I don't think I referred to it when implementing this query. Reading through it now, I think that a missing component is an explanation of what the captures themselves represent. I'm not entirely sure what intermediate is intended for.

HiPhish commented 1 year ago

I have looked through your code, looks good. Can you please rebase on the current master branch for easier merging? I have a few suggestions:

;;; Redundant parentheses around child nodes
(enum_variant_list
  (("{" @opening)
   ("}" @closing))) @container

;;; Redundant parentheses removed
(enum_variant_list
  ("{" @opening)
  ("}" @closing)) @container

Reading through it now, I think that a missing component is an explanation of what the captures themselves represent.

Good point. I will address this.

I'm not entirely sure what intermediate is intended for,

The capture @.***is for intermediate delimiters. For example, in Lua if you want to use blocks as delimiters, then the opening delimiter isif ... then, the closing delimiter isendand the intermediate delimiters are one or moreelseif ... then`. An intermediate delimiter could also be the comma inside an argument list. Will this make the text buffer too vibrant? Maybe, but that is something which can be controlled by the query, I mainly wanted to leave the option open. Personally I would not add commas as intermediate delimiters to the query, at least not in the default query.

CatThingy commented 1 year ago

Thanks for your suggesstions. I've implemented them and rebased this branch.