lawrence-laz / neotest-zig

Test runner for Zig in Neovim using Neotest backend.
MIT License
27 stars 7 forks source link

treesitter Invalid node type "TestDecl" #32

Closed zspher closed 2 months ago

zspher commented 2 months ago

Describe the bug whenever i run neotest with neotest-zig, the tests aren't loaded and i get the ff. error:

   Error  17:28:05 msg_show.lua_error Error executing vim.schedule lua callback: .../faust/.local/share/nvim/lazy/nvim-nio/lua/nio/tasks.lua:100: Async task failed without callback: The coroutine failed with this message: 
...d-0.10.1/share/nvim/runtime/lua/vim/treesitter/query.lua:252: Query error at 2:3. Invalid node type "TestDecl":
    (TestDecl
  ^

stack traceback:
    [C]: in function '_ts_parse_query'
    ...d-0.10.1/share/nvim/runtime/lua/vim/treesitter/query.lua:252: in function 'fn'
    ...pped-0.10.1/share/nvim/runtime/lua/vim/func/_memoize.lua:58: in function 'parse_query'
    ...re/nvim/lazy/neotest/lua/neotest/lib/treesitter/init.lua:104: in function 'normalise_query'
    ...re/nvim/lazy/neotest/lua/neotest/lib/treesitter/init.lua:161: in function 'parse_positions_from_string'
    ...cal/share/nvim/lazy/neotest-zig/lua/neotest-zig/init.lua:136: in function '_does_file_contain_tests'
    ...cal/share/nvim/lazy/neotest-zig/lua/neotest-zig/init.lua:108: in function 'is_test_file'
    ...ocal/share/nvim/lazy/neotest/lua/neotest/client/init.lua:346: in function 'get_adapter'
    ...ocal/share/nvim/lazy/neotest/lua/neotest/client/init.lua:356: in function '_set_focused_file'
    ...ocal/share/nvim/lazy/neotest/lua/neotest/client/init.lua:495: in function '_start'
    ...ocal/share/nvim/lazy/neotest/lua/neotest/client/init.lua:186: in function '_ensure_started'
    ...ocal/share/nvim/lazy/neotest/lua/neotest/client/init.lua:198: in function 'get_position'
    ...ocal/share/nvim/lazy/neotest/lua/neotest/client/init.lua:150: in function 'get_nearest'
    ...share/nvim/lazy/neotest/lua/neotest/consumers/output.lua:177: in function 'func'
    .../faust/.local/share/nvim/lazy/nvim-nio/lua/nio/tasks.lua:173: in function <.../faust/.local/share/nvim/lazy/nvim-nio/lua/nio/tasks.lua:172>
stack traceback:
    [C]: in function 'error'
    .../faust/.local/share/nvim/lazy/nvim-nio/lua/nio/tasks.lua:100: in function 'close_task'
    .../faust/.local/share/nvim/lazy/nvim-nio/lua/nio/tasks.lua:122: in function 'cb'
    .../faust/.local/share/nvim/lazy/nvim-nio/lua/nio/tasks.lua:188: in function <.../faust/.local/share/nvim/lazy/nvim-nio/lua/nio/tasks.lua:187>
   Error  17:28:05 msg_show.lua_error Error executing vim.schedule lua callback: .../faust/.local/share/nvim/lazy/nvim-nio/lua/nio/tasks.lua:100: Async task failed without callback: The coroutine failed with this message: 

Steps To Reproduce

  1. run zig init
  2. run :Neotest run in neovim

Current behavior

neotest-zig outputs a treesitter error

Expected behavior

neotest-zig should be able to find all tests

Screenshots

If applicable, add screenshots to help explain your problem.

Logs

Enable logs with:

require("neotest").setup({
    log_level = vim.log.levels.TRACE,
    -- ...
})

Open logs with: :exe 'edit' stdpath('log').'/neotest-zig.log'

[START][2024-09-05 17:38:32] neotest-zig logging initiated
[TRACE][2024-09-05 17:38:32] ...est-zig/init.lua:46 "Entered match_root_pattern with"   "~/personal/zig-test/src"
[TRACE][2024-09-05 17:38:32] ...est-zig/init.lua:60 "Found a valid root"    "~/personal/zig-test/src"
[DEBUG][2024-09-05 17:38:32] ...est-zig/init.lua:105    "Entered `is_test_file` with"   "~/personal/zig-test/src/main.zig"
[DEBUG][2024-09-05 17:38:41] ...est-zig/init.lua:105    "Entered `is_test_file` with"   "~/.local/state/nvim/neotest-zig.log"
[DEBUG][2024-09-05 17:38:41] ...est-zig/init.lua:110    "Returning from `is_test_file` with"    false

changed homedir with ~/

Environment

Additional context

Add any other context about the problem here.

lawrence-laz commented 2 months ago

There's been a few breaking changes in Zig lately. I patched them up in main branch and was able to run tests again. Looking at the error message it seems like you might be having a different issue than the ones I fixed though. Could you run :checkhealth nvim-treesitter to make sure that treesitter is configured correctly?

Nefendi commented 2 months ago

Hi! I have also run into this problem. Checkhealth returns no errors for me. Looking at the output from treesitter playground I think that the name of at least one of the nodes changed from TestDecl to test_declaration. Although I am not sure, because I don't really know how treesitter works internally.

image

lawrence-laz commented 2 months ago

Seems like I've found the issue: https://github.com/nvim-treesitter/nvim-treesitter/commit/ba921c9aef386ad895b0a6551968126ff90a288d

I'll probably have to update the queries, but that also means everyone will have to update their treesitter. Hm... Maybe there's a way to check which grammar is used and provide appropriate queries

lawrence-laz commented 2 months ago

I updated the query to match the new zig parser, let me know if this solves the issue for you.

Nefendi commented 2 months ago

It works for me. Thanks!