Closed RRethy closed 2 years ago
I experienced the same attempt to index local 'query' (a nil value)
error when trying to define custom textobjects for the Go language. I threw in some debugging and discovered that the plugin was falling back to the comment
language at some point during the text object flow. I've got no idea if this should be expected, but removing unused languages including the comment
language silenced the error.
Unfortunately, the custom textobjects still don't seem to trigger for me after this change.
I think this option should be deprecated and instead recommend putting your custom queries on ~/.config/nvim/after/queries/go/textobjects.scm
@stsewd could you elaborate on what you mean? I'm running into the same issue...
@stsewd could you elaborate on what you mean? I'm running into the same issue...
@dlants create a file in ~/.config/nvim/after/queries/go/textobjects.scm
(node) @mycustomobject
with your custom queries, and then in your config
require'nvim-treesitter.configs'.setup {
textobjects = {
select = {
enable = true,
lookahead = true,
keymaps = {
-- You can use the capture groups defined in textobjects.scm
["af"] = "@mycustomobject",
},
},
}
@stsewd I can't get your solution to work. I tried creating the following textobjects.csm
file
;; ~/.config/nvim/after/queries/typescript/textobjects.scm
(method_definition) @mymethod
And I'm using the following minimal lazy.nvim config:
{
'nvim-treesitter/nvim-treesitter',
dependencies = 'nvim-treesitter/nvim-treesitter-textobjects',
build = ':TSUpdate',
config = function()
require('nvim-treesitter.configs').setup({
ensure_installed = 'all',
highlight = {
enable = true,
},
textobjects = {
move = {
enable = true,
goto_next_start = {
[']m'] = '@mymethod'
}
}
}
})
end
}
Nothing happens when I press ]m
inside a TypeScript file (with a bunch of methods). I want ]m
to jump to the next method. What am I doing wrong?
@mawkler Maybe you need to put ; extends
@kiyoon That works, thank you!
Do you have a link to some resource that explains what ; extends
does? I couldn't find any info online.
Describe the bug I am unable to define custom textobjects for the select submodule.
To Reproduce Config:
C file:
Doing
viF
results inE5108: Error executing lua ...ckpack/opt/nvim-treesitter/lua/nvim-treesitter/query.lua:144: attempt to index local 'query' (a nil value)
.Expected behavior
I expect the function to be selected.
Output of
:checkhealth nvim_treesitter
health#nvim_treesitter#check ======================================================================== ## Installation - OK: `tree-sitter` found 0.19.4 (4e321f34a0688f2ad0ce6ec32d0700b039e8436c) (parser generator, only needed for :TSInstallFromGrammar) - OK: `node` found v12.16.3 (only needed for :TSInstallFromGrammar) - OK: `git` executable found. - OK: `cc` executable found. Selected from { vim.NIL, "cc", "gcc", "clang", "cl" } - OK: Neovim was compiled with tree-sitter runtime ABI version 13 (required >=13). Parsers must be compatible with runtime ABI. ## Parser/Features H L F I - swift . . . . - fortran ✓ . ✓ . - c_sharp ✓ . . . - rust ✓ ✓ ✓ ✓ - go ✓ ✓ ✓ ✓ - ledger ✓ . ✓ ✓ - ruby ✓ ✓ ✓ ✓ - zig ✓ ✓ ✓ ✓ - rst ✓ ✓ . . - bibtex ✓ . ✓ ✓ - fennel ✓ ✓ . . - latex ✓ . ✓ . - teal ✓ ✓ ✓ ✓ - gomod ✓ . . . - beancount ✓ . ✓ . - graphql ✓ . . ✓ - r ✓ ✓ . . - glimmer ✓ . . . - verilog ✓ ✓ ✓ . - jsonc ✓ ✓ ✓ ✓ - bash ✓ ✓ ✓ . - elm . . . . - c ✓ ✓ ✓ ✓ - comment ✓ . . . - dart ✓ ✓ . ✓ - fish ✓ ✓ ✓ ✓ - sparql ✓ ✓ ✓ ✓ - query ✓ ✓ ✓ ✓ - jsdoc ✓ . . . - php x x ✓ ✓ - regex ✓ . . . - ql ✓ ✓ . ✓ - gdscript x x . . - nix x x x . - typescript ✓ ✓ ✓ ✓ - yaml x x ✓ ✓ - turtle ✓ ✓ ✓ ✓ - html ✓ ✓ ✓ ✓ - devicetree x x x x - julia ✓ ✓ ✓ . - json ✓ ✓ ✓ ✓ - javascript ✓ ✓ ✓ ✓ - svelte x . ✓ ✓ - css ✓ . ✓ ✓ - supercollider x x x x - scss ✓ . . ✓ - haskell . . . . - erlang . . . . - toml ✓ ✓ ✓ ✓ - scala . . . . - elixir ✓ ✓ . ✓ - tsx ✓ ✓ ✓ ✓ - clojure ✓ ✓ ✓ . - kotlin ✓ . . . - ocaml x ✓ ✓ . - commonlisp ✓ ✓ ✓ . - vue ✓ . ✓ . - python ✓ ✓ ✓ ✓ - lua ✓ ✓ ✓ ✓ - ocaml_interfacex ✓ ✓ . - java x ✓ . ✓ - cpp ✓ ✓ ✓ ✓ - ocamllex x . . . - dockerfile ✓ . . . Legend: H[ighlight], L[ocals], F[olds], I[ndents] +) multiple parsers found, only one will be used x) errors found in the query, try to run :TSUpdate {lang} The following errors have been detected: - ERROR: php(highlights): /usr/local/share/nvim/runtime/lua/vim/treesitter/query.lua:161: query: invalid node type at position 100 - ERROR: php(locals): /usr/local/share/nvim/runtime/lua/vim/treesitter/query.lua:161: query: invalid node type at position 987 - ERROR: gdscript(highlights): ...local/share/nvim/runtime/lua/vim/treesitter/language.lua:33: ABI version mismatch for /Users/rethy/.local/share/nvim/site/pack/backpack/opt/nvim-treesitter/parser/gdscript.so: supported between 13 and 13, found 12 - ERROR: gdscript(locals): ...local/share/nvim/runtime/lua/vim/treesitter/language.lua:33: ABI version mismatch for /Users/rethy/.local/share/nvim/site/pack/backpack/opt/nvim-treesitter/parser/gdscript.so: supported between 13 and 13, found 12 - ERROR: nix(highlights): ...local/share/nvim/runtime/lua/vim/treesitter/language.lua:33: ABI version mismatch for /Users/rethy/.local/share/nvim/site/pack/backpack/opt/nvim-treesitter/parser/nix.so: supported between 13 and 13, found 12 - ERROR: nix(locals): ...local/share/nvim/runtime/lua/vim/treesitter/language.lua:33: ABI version mismatch for /Users/rethy/.local/share/nvim/site/pack/backpack/opt/nvim-treesitter/parser/nix.so: supported between 13 and 13, found 12 - ERROR: nix(folds): ...local/share/nvim/runtime/lua/vim/treesitter/language.lua:33: ABI version mismatch for /Users/rethy/.local/share/nvim/site/pack/backpack/opt/nvim-treesitter/parser/nix.so: supported between 13 and 13, found 12 - ERROR: yaml(highlights): /usr/local/share/nvim/runtime/lua/vim/treesitter/query.lua:161: query: invalid node type at position 291 - ERROR: yaml(locals): /usr/local/share/nvim/runtime/lua/vim/treesitter/query.lua:161: query: invalid node type at position 20 - ERROR: devicetree(highlights): ...local/share/nvim/runtime/lua/vim/treesitter/language.lua:33: ABI version mismatch for /Users/rethy/.local/share/nvim/site/pack/backpack/opt/nvim-treesitter/parser/devicetree.so: supported between 13 and 13, found 12 - ERROR: devicetree(locals): ...local/share/nvim/runtime/lua/vim/treesitter/language.lua:33: ABI version mismatch for /Users/rethy/.local/share/nvim/site/pack/backpack/opt/nvim-treesitter/parser/devicetree.so: supported between 13 and 13, found 12 - ERROR: devicetree(folds): ...local/share/nvim/runtime/lua/vim/treesitter/language.lua:33: ABI version mismatch for /Users/rethy/.local/share/nvim/site/pack/backpack/opt/nvim-treesitter/parser/devicetree.so: supported between 13 and 13, found 12 - ERROR: devicetree(indents): ...local/share/nvim/runtime/lua/vim/treesitter/language.lua:33: ABI version mismatch for /Users/rethy/.local/share/nvim/site/pack/backpack/opt/nvim-treesitter/parser/devicetree.so: supported between 13 and 13, found 12 - ERROR: svelte(highlights): /usr/local/share/nvim/runtime/lua/vim/treesitter/query.lua:161: query: invalid node type at position 17 - ERROR: supercollider(highlights): ...local/share/nvim/runtime/lua/vim/treesitter/language.lua:33: ABI version mismatch for /Users/rethy/.local/share/nvim/site/pack/backpack/opt/nvim-treesitter/parser/supercollider.so: supported between 13 and 13, found 12 - ERROR: supercollider(locals): ...local/share/nvim/runtime/lua/vim/treesitter/language.lua:33: ABI version mismatch for /Users/rethy/.local/share/nvim/site/pack/backpack/opt/nvim-treesitter/parser/supercollider.so: supported between 13 and 13, found 12 - ERROR: supercollider(folds): ...local/share/nvim/runtime/lua/vim/treesitter/language.lua:33: ABI version mismatch for /Users/rethy/.local/share/nvim/site/pack/backpack/opt/nvim-treesitter/parser/supercollider.so: supported between 13 and 13, found 12 - ERROR: supercollider(indents): ...local/share/nvim/runtime/lua/vim/treesitter/language.lua:33: ABI version mismatch for /Users/rethy/.local/share/nvim/site/pack/backpack/opt/nvim-treesitter/parser/supercollider.so: supported between 13 and 13, found 12 - ERROR: ocaml(highlights): /usr/local/share/nvim/runtime/lua/vim/treesitter/query.lua:161: query: invalid node type at position 2729 - ERROR: ocaml_interface(highlights): /usr/local/share/nvim/runtime/lua/vim/treesitter/query.lua:161: query: invalid node type at position 2729 - ERROR: java(highlights): /usr/local/share/nvim/runtime/lua/vim/treesitter/query.lua:161: query: invalid node type at position 2209 - ERROR: ocamllex(highlights): ...local/share/nvim/runtime/lua/vim/treesitter/language.lua:33: ABI version mismatch for /Users/rethy/.local/share/nvim/site/pack/backpack/opt/nvim-treesitter/parser/ocamllex.so: supported between 13 and 13, found 11
Output of
nvim --version
Additional context I looked at the code and I don't think it should work unless I misunderstand the following snippet:
shared.lua