nvim-ts-rainbow2 icon indicating copy to clipboard operation
nvim-ts-rainbow2 copied to clipboard

feat(v): add queries

Open ttytm opened this issue 1 year ago • 10 comments

ttytm avatar Apr 17 '23 13:04 ttytm

I get an error at the root node of the test file:

ERROR [0, 0] - [42, 1]
  ERROR [0, 7] - [41, 32]
    simple_identifier [0, 7] - [0, 11]
    simple_identifier [0, 14] - [0, 22]
...

HiPhish avatar Apr 17 '23 19:04 HiPhish

Hey thanks for taking care if this. Looks like i was sloppy there. I'll check on it asap :+1:

Sorry about the inconvenience.

ttytm avatar Apr 17 '23 19:04 ttytm

Main problem I've forgot about is that vim sets the ft for files with a .v to verilog. For V it needs to be user set. I'd still need to improve the test but I'll submit the upstream support first then come back to this. Making this draft for now.

ttytm avatar Apr 18 '23 12:04 ttytm

Main problem I've forgot about is that vim sets the ft for files with a .v to verilog. For V it needs to be user set.

Don't worry about that, it's outside the scope of this project. Anyone who uses V will already have adjusted the file type detection, and those who have not don't use V anyway.

HiPhish avatar Apr 18 '23 12:04 HiPhish

Hey @HiPhish,

I updated the test to include code that actually compiles. It's still code that doesn't make a lot of sense. Sorry again about the miss in the initial PR.

Can you tell me how you run your tests? I haven't found anything in either the readme or the contribution file. Unfortunately, I have fairly little time to find out by doing my own investigation. Then I would be happy to adapt to further needs :+1:

ttytm avatar Apr 21 '23 18:04 ttytm

Can you tell me how you run your tests?

I open the test file manually, then I open the Tree-sitter playground and check whether everything looks correct. It's not very efficient, but queries rarely change, so it's not a big deal. Still, it would be good to automate the process, especially for testing strategies.

Neovim 0.9 has introduced vim.inspect_pos(), so now I can at least programmatically check the highlighting. With that I could use a testing framework to write automated tests. I have used in the past Vader, but it is flawed in that tests are all run in the same instance as the test framework itself. We would need a test framework that spawns a fresh Neovim per test so that failure or crashes in one test don't bring down all other tests. And first-class support for Lua (and maybe other languages?) of course.

HiPhish avatar Apr 23 '23 23:04 HiPhish

I am still getting parser errors.

Screenshot_20230424_110336

HiPhish avatar Apr 24 '23 09:04 HiPhish

Thanks for you message @HiPhish. Totally fine to do it that way. And now, I know what to look at!

But I don't get the parsing errors. Could it be that it's because of a wrong filetype when you entering the .v file?

I submitted proper filetype detection the vim just about last week or so. Meanwhile it also made it into vim. Are you using nightly?

https://user-images.githubusercontent.com/34311583/235243816-208fa42c-1c26-4dd6-9e99-9d97acccbcaa.mp4

ttytm avatar Apr 28 '23 20:04 ttytm

You are correct, I had the file type Verilog set, my bad. It would be a good idea to add a little modeline comment at the end of the file to set the file type explicitly when there is any possibility of ambiguity. See :h modeline. I did the same in the test file for the query file type (test/highlight/query/regular.scm) to ensure that it is not interpreted as Scheme instead.

Anyway, I have now looked into it and there are a number of node types I don't see in the tree:

  • parenthesized_expression
  • type_cast_expression
  • special_argument_list
  • comptime_selector_expression
  • multi_return_type
  • fixed_array_type
  • exposed_variables_list
  • slice_expression
  • attribute_declaration
  • empty_literal_value
  • select_expression
  • map (there is map_type in the tree)

Am I missing something again?

HiPhish avatar May 13 '23 15:05 HiPhish

No you are right again @HiPhish. I didn't added all of the node types in the test file. I'll update it in the coming week.

ttytm avatar May 29 '23 19:05 ttytm