Skip to content
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

Update c queries and test #363

Merged
merged 2 commits into from
Jan 19, 2024
Merged

Conversation

Danielkonge
Copy link
Contributor

@Danielkonge Danielkonge commented Nov 16, 2023

A lot of the current C queries include an extra line with only { if you format your code in this style:

if ()
{
  //code
}
for ()
{
  //code
}

For the context that whole line with only { is wasted space, so this simplifies some queries to not include that {. If you want to always include { instead, I can update the queries.

Also, this catches if, else if and else with the expected pattern (see #356).

If the queries should catch the extra "{", then I can rewrite this a bit so it still catches else if and else, but otherwise doesn't change anything.

Note: I can rewrite the test that is currently failing if you want to merge this pull request.

@lewis6991
Copy link
Member

Tests are broken.

@Danielkonge Danielkonge force-pushed the testing branch 3 times, most recently from be0e05a to a3353a4 Compare December 8, 2023 13:11
@Danielkonge
Copy link
Contributor Author

Tests are broken.

I tried to fix the error (and during this I simplified this pull request for now), but it seems to be a problem with the parser? Here is the error message:

[126] Expected:

[127] |*{7:struct}{2: Bert {                 }|
[128] |    {8:// comment}                |
[129] |    {9:int} *f2;                  |
[130] |    {8:// comment}                |
[131] |    {8:// comment}                |
[132] |*^    {8:// comment}                |
[133] |*    {8:// comment}                |
[134] |*    {8:// comment}                |
[135] |*};                            |
[136] |*                              |
[137] |*{9:typedef} {9:enum} {                |
[138] |*  E1,                         |
[139] |*  E2,                         |
[140] |*  E3                          |
[141] |*  {8:// comment}                  |
[142] |*                              |

[143] Actual:

[144] |*    {9:int} *f1;                  |
[145] |    {8:// comment}                |
[146] |    {9:int} *f2;                  |
[147] |    {8:// comment}                |
[148] |    {8:// comment}                |
[149] |*    {8:// comment}                |
[150] |*{UNEXPECTED reverse = true, bold = true:                              }|
[151] |*{13:Unable to load context query f}|
[152] |*{13:or c:}                         |
[153] |*{13:...ntext/neovim-v0.9.1/runtime}|
[154] |*{13:/lua/vim/treesitter/query.lua:}|
[155] |*{13:259: query: invalid node type }|
[156] |*{13:at position 301 for language c}|
[157] |*                              |
[158] |*{9:Press ENTER or type command to}|
[159] |*{9: continue}^                     |

Is the parser not updated in the GitHub tests? Or am I maybe misunderstanding the error?

@antoinemadec
Copy link
Contributor

antoinemadec commented Jan 6, 2024

FYI, the else_clause in the C parser is fairly recent.
See this MR from July 2023: tree-sitter/tree-sitter-c#115

@Danielkonge please find the fix here: https://github.com/antoinemadec/nvim-treesitter-context/tree/feat/c_else_clause

You were missing the update on test/ts_context_spec.lua.
make test is working fine on my end.

I will let you merge it on this MR 😉

@Danielkonge
Copy link
Contributor Author

Danielkonge commented Jan 6, 2024

FYI, the else_clause in the C parser is fairly recent. See this MR from July 2023: tree-sitter/tree-sitter-c#115

@Danielkonge please find the fix here: https://github.com/antoinemadec/nvim-treesitter-context/tree/feat/c_else_clause

You were missing the update on test/ts_context_spec.lua. make test is working fine on my end.

I will let you merge it on this MR 😉

Thank for you for the help @antoinemadec, I tried adding your changes, but the GitHub tests seem to still be failing.

Since neovim 0.9.1 (used in the tests) is from May 2023, I guess the parser might not be updated too, but I don't really want to change to much about the tests themselves, since I don't have much knowledge on the details of them. (I can help with writing queries for treesitter or Lua code in general, but I haven't really looked into all the testing stuff for neovim yet, since I don't have a plugin myself.)

(Also, if you are able to fix the tests, feel free to make a separate pull request.)

@lewis6991
Copy link
Member

treesitter is still experimental, so we can just support the latest release (v0.9.5)

@lewis6991 lewis6991 merged commit 85cf977 into nvim-treesitter:master Jan 19, 2024
1 check passed
@Danielkonge Danielkonge deleted the testing branch January 22, 2024 21:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants