rouge8/neotest-rust

Treesitter query: invalid node type

Closed this issue · 1 comments

Getting "No tests found", looking at neotest.log:

ERROR | 2022-11-08T08:06:37Z-0800 | ...te/pack/packer/start/neotest/lua/neotest/client/init.lua:274 | Couldn't find positions in path /Users/aiden/src/test-neotest/src/lib.rs /usr/local/share/nvim/runtime/lua/vim/treesitter/query.lua:219: query: invalid node type at position 33 for language rust

I opened up the :TSPlaygroundToggle and looked at what treesitter was showing for a simple test (cargo new --lib ...):
Screen Shot 2022-11-08 at 8 03 40 AM

I got a working treesitter query to capture tests using the following:

Untitled

Is perhaps the treesitter query in this repo out of date with the latest grammar? Happy to submit a PR.

:version
NVIM v0.8.0
Build type: RelWithDebInfo
LuaJIT 2.1.0-beta3
Compilation: /Library/Developer/CommandLineTools/usr/bin/cc -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -DNVIM_TS_HAS_SET_MATCH_LIMIT -DNVIM_TS_HAS_SET_ALLOCATOR -O2 -g -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prot
otypes -std=gnu99 -Wshadow -Wconversion -Wdouble-promotion -Wmissing-noreturn -Wmissing-format-attribute -Wmissing-prototypes -Wimplicit-fallthrough -Wvla -fstack-protector-strong -fno-common -fdiagnostics-color=always -DI
NCLUDE_GENERATED_DECLARATIONS -DNVIM_MSGPACK_HAS_FLOAT32 -DNVIM_UNIBI_HAS_VAR_FROM -DMIN_LOG_LEVEL=3 -I/Users/aiden/src/neovim/build/cmake.config -I/Users/aiden/src/neovim/src -I/Users/aiden/src/neovim/.deps/usr/include -I
/Library/Developer/CommandLineTools/SDKs/MacOSX12.3.sdk/usr/include -I/usr/local/opt/gettext/include -I/Users/aiden/src/neovim/build/src/nvim/auto -I/Users/aiden/src/neovim/build/include
Compiled by aiden@aimbp.local

Features: +acl +iconv +tui
See ":help feature-compile"

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "/usr/local/share/nvim"

  nvim-treesitter: require("nvim-treesitter.health").check()
  ========================================================================
  ## Installation
    - OK: `tree-sitter` found 0.20.6 (parser generator, only needed for :TSInstallFromGrammar)
    - OK: `node` found v19.0.1 (only needed for :TSInstallFromGrammar)
    - OK: `git` executable found.
    - OK: `cc` executable found. Selected from { vim.NIL, "cc", "gcc", "clang", "cl", "zig" }
      Version: Apple clang version 14.0.0 (clang-1400.0.29.102)
    - OK: Neovim was compiled with tree-sitter runtime ABI version 14 (required >=13). Parsers must be compatible with runtime ABI.
  vim.treesitter: require("vim.treesitter.health").check()
  ========================================================================
    - INFO: Runtime ABI version : 14
    - OK: Loaded parser for bash: ABI version 14
    - OK: Loaded parser for c: ABI version 13
    - OK: Loaded parser for clojure: ABI version 13                                                                                                                                                                               - OK: Loaded parser for css: ABI version 13
    - OK: Loaded parser for dockerfile: ABI version 13
    - OK: Loaded parser for elixir: ABI version 14
    - OK: Loaded parser for erlang: ABI version 13
    - OK: Loaded parser for go: ABI version 14
    - OK: Loaded parser for graphql: ABI version 13
    - OK: Loaded parser for hcl: ABI version 13
    - OK: Loaded parser for heex: ABI version 14
    - OK: Loaded parser for help: ABI version 14
    - OK: Loaded parser for html: ABI version 13
    - OK: Loaded parser for javascript: ABI version 13
    - OK: Loaded parser for json: ABI version 13
    - OK: Loaded parser for lua: ABI version 13
    - OK: Loaded parser for python: ABI version 14
    - OK: Loaded parser for query: ABI version 14
    - OK: Loaded parser for ruby: ABI version 13
    - OK: Loaded parser for rust: ABI version 13
    - OK: Loaded parser for svelte: ABI version 13
    - OK: Loaded parser for toml: ABI version 13
    - OK: Loaded parser for tsx: ABI version 13
    - OK: Loaded parser for typescript: ABI version 14
    - OK: Loaded parser for vim: ABI version 14
    - OK: Loaded parser for yaml: ABI version 13
    - OK: Loaded parser for c: ABI version 13
    - OK: Loaded parser for help: ABI version 14
    - OK: Loaded parser for lua: ABI version 13
    - OK: Loaded parser for vim: ABI version 14

Confirmed that if I edit init.lua and replace the treesitter query with the following, it works:

(
  (attribute_item
    (meta_item
      (identifier) @macro_name
    )
  )+
  .
  (function_item
    name: (identifier) @test.name
  ) @test.definition
  (#contains? @macro_name "test" "rstest" "case")
)
(mod_item name: (identifier) @namespace.name)? @namespace.definition

Fixed by deleting and re-installing nvim-treesitter (nvim-treesitter/nvim-treesitter#3092)