nvim-treesitter / nvim-treesitter-textobjects

Apache License 2.0
2.16k stars 194 forks source link

shared.lua:91: attempt to index a nil value on main branch when selecting outer class #703

Closed ibrokemypie closed 3 days ago

ibrokemypie commented 3 days ago

Describe the bug When running require "nvim-treesitter-textobjects.select".select_textobject("@class.outer", "textobjects") I get this big error:

E5108: Error executing lua ...r-textobjects/lua/nvim-treesitter-textobjects/shared.lua:91: attempt to index a nil value
stack traceback:                                                                                                       
        ...r-textobjects/lua/nvim-treesitter-textobjects/shared.lua:91: in function 'fn'                               
        ...r-textobjects/lua/nvim-treesitter-textobjects/shared.lua:39: in function 'get_query_matches'                
        ...r-textobjects/lua/nvim-treesitter-textobjects/shared.lua:167: in function 'fn'                              
        ...2/share/nvim/runtime/lua/vim/treesitter/languagetree.lua:491: in function 'for_each_tree'                   
        ...r-textobjects/lua/nvim-treesitter-textobjects/shared.lua:164: in function 'get_capture_ranges_recursively'  
        ...r-textobjects/lua/nvim-treesitter-textobjects/shared.lua:359: in function 'textobject_at_point'             
        ...r-textobjects/lua/nvim-treesitter-textobjects/select.lua:155: in function 'select_textobject'               
        [string ":lua"]:1: in main chunk                                                                               

To Reproduce Steps to reproduce the behavior:

  1. Configure nvim-treesitter-textobjects as below (lazy.nvim spec):
    {
        "nvim-treesitter/nvim-treesitter-textobjects",
        branch = "main",
        opts = {
            select = {
                -- Automatically jump forward to textobj, similar to targets.vim
                lookahead = true,
                -- You can choose the select mode (default is charwise 'v')
                --
                -- Can also be a function which gets passed a table with the keys
                -- * query_string: eg '@function.inner'
                -- * method: eg 'v' or 'o'
                -- and should return the mode ('v', 'V', or '<c-v>') or a table
                -- mapping query_strings to modes.
                selection_modes = {
                    ["@parameter.outer"] = "v", -- charwise
                    ["@function.outer"] = "V", -- linewise
                    ["@class.outer"] = "<c-v>", -- blockwise
                },
                -- If you set this to `true` (default is `false`) then any textobject is
                -- extended to include preceding or succeeding whitespace. Succeeding
                -- whitespace has priority in order to act similarly to eg the built-in
                -- `ap`.
                --
                -- Can also be a function which gets passed a table with the keys
                -- * query_string: eg '@function.inner'
                -- * selection_mode: eg 'v'
                -- and should return true of false
                include_surrounding_whitespace = false,
            },
        },
        keys = {
            {
                -- operator pending or visual
                mode = { "x", "o" },
                "af",
                function()
                    require("nvim-treesitter-textobjects.select").select_textobject(
                    "@function.outer", "textobjects")
                end,
                desc = "around function",
            },
            {
                -- operator pending or visual
                mode = { "x", "o" },
                "if",
                function()
                    require("nvim-treesitter-textobjects.select").select_textobject(
                    "@function.inner", "textobjects")
                end,
                desc = "inside function",
            },
            {
                -- operator pending or visual
                mode = { "x", "o" },
                "ac",
                function()
                    require("nvim-treesitter-textobjects.select").select_textobject("@class.outer",
                        "textobjects")
                end,
                desc = "around class",
            },
            {
                -- operator pending or visual
                mode = { "x", "o" },
                "ic",
                function()
                    require("nvim-treesitter-textobjects.select").select_textobject("@class.inner",
                        "textobjects")
                end,
                desc = "inside class",
            },
        },
    },
  2. Press dac or run lua require "nvim-treesitter-textobjects.select".select_textobject("@class.outer", "textobjects") with the cursor within a python class.

Expected behavior The class definition is deleted/selected

Output of :checkhealth nvim-treesitter

============================================================================== nvim-treesitter: require("nvim-treesitter.health").check() Installation ~ - WARNING `tree-sitter` executable not found (parser generator, only needed for :TSInstallFromGrammar, not required for :TSInstall) - WARNING `node` executable not found (only needed for :TSInstallFromGrammar, not required for :TSInstall) - OK `git` executable found. - OK `cc` executable found. Selected from { vim.NIL, "cc", "gcc", "clang", "cl", "zig" } Version: gcc (GCC) 13.3.0 - OK Neovim was compiled with tree-sitter runtime ABI version 14 (required >=13). Parsers must be compatible with runtime ABI. OS Info: { machine = "x86_64", release = "6.6.54", sysname = "Linux", version = "#1-NixOS SMP PREEMPT_DYNAMIC Fri Oct 4 14:30:05 UTC 2024" } ~ Parser/Features H L F I J - ada ✓ ✓ ✓ . ✓ - agda ✓ . ✓ . ✓ - angular ✓ ✓ ✓ ✓ ✓ - apex ✓ ✓ ✓ . ✓ - arduino ✓ ✓ ✓ ✓ ✓ - asm ✓ . . . ✓ - astro ✓ ✓ ✓ ✓ ✓ - authzed ✓ . . . ✓ - awk ✓ . . . ✓ - bash ✓ ✓ ✓ . ✓ - bass ✓ ✓ ✓ ✓ ✓ - beancount ✓ . ✓ . ✓ - bibtex ✓ . ✓ ✓ ✓ - bicep ✓ ✓ ✓ ✓ ✓ - bitbake ✓ ✓ ✓ ✓ ✓ - blueprint ✓ . . . ✓ - bp ✓ ✓ ✓ ✓ ✓ - c ✓ ✓ ✓ ✓ ✓ - c_sharp ✓ ✓ ✓ . ✓ - cairo ✓ ✓ ✓ ✓ ✓ - capnp ✓ ✓ ✓ ✓ ✓ - chatito ✓ ✓ ✓ ✓ ✓ - clojure ✓ ✓ ✓ . ✓ - cmake ✓ . ✓ ✓ ✓ - comment ✓ . . . . - commonlisp ✓ ✓ ✓ . ✓ - cooklang ✓ . . . ✓ - corn ✓ ✓ ✓ ✓ ✓ - cpon ✓ ✓ ✓ ✓ ✓ - cpp ✓ ✓ ✓ ✓ ✓ - css ✓ . ✓ ✓ ✓ - csv ✓ . . . . - cuda ✓ ✓ ✓ ✓ ✓ - cue ✓ ✓ ✓ ✓ ✓ - d ✓ ✓ ✓ ✓ ✓ - dart ✓ ✓ ✓ ✓ ✓ - devicetree ✓ ✓ ✓ ✓ ✓ - dhall ✓ . ✓ . ✓ - diff ✓ . ✓ . ✓ - disassembly ✓ . . . ✓ - djot ✓ ✓ ✓ ✓ ✓ - dockerfile ✓ . . . ✓ - dot ✓ . . ✓ ✓ - doxygen ✓ . . ✓ ✓ - dtd ✓ ✓ ✓ . ✓ - earthfile ✓ . . . ✓ - ebnf ✓ . . . ✓ - editorconfig ✓ . ✓ . ✓ - eds ✓ . ✓ . . - eex ✓ . . . ✓ - elixir ✓ ✓ ✓ ✓ ✓ - elm ✓ ✓ ✓ . ✓ - elsa ✓ ✓ ✓ ✓ ✓ - elvish ✓ . . . ✓ - embedded_template ✓ . . . ✓ - erlang ✓ . ✓ . ✓ - facility ✓ . ✓ ✓ ✓ - faust ✓ ✓ . . ✓ - fennel ✓ ✓ ✓ . ✓ - fidl ✓ . ✓ . ✓ - firrtl ✓ ✓ ✓ ✓ ✓ - fish ✓ ✓ ✓ ✓ ✓ - foam ✓ ✓ ✓ ✓ ✓ - forth ✓ ✓ ✓ ✓ ✓ - fortran ✓ . ✓ ✓ ✓ - fsh ✓ . . . ✓ - fsharp ✓ . . . ✓ - func ✓ . . . ✓ - fusion ✓ ✓ ✓ ✓ ✓ - gap ✓ ✓ ✓ . ✓ - gaptst ✓ . ✓ . ✓ - gdscript ✓ ✓ ✓ ✓ ✓ - gdshader ✓ . . . ✓ - git_config ✓ . ✓ . ✓ - git_rebase ✓ . . . ✓ - gitattributes ✓ ✓ . . ✓ - gitcommit ✓ . . . ✓ - gitignore ✓ . . . ✓ - gleam ✓ ✓ ✓ ✓ ✓ - glimmer ✓ ✓ ✓ ✓ ✓ - glimmer_javascript ✓ ✓ . ✓ ✓ - glimmer_typescript ✓ . . ✓ ✓ - glsl ✓ ✓ ✓ ✓ ✓ - gn ✓ ✓ ✓ ✓ ✓ - gnuplot ✓ ✓ . . ✓ - go ✓ ✓ ✓ ✓ ✓ - goctl ✓ . ✓ ✓ ✓ - godot_resource ✓ ✓ ✓ . ✓ - gomod ✓ . . . ✓ - gosum ✓ . . . . - gotmpl ✓ ✓ ✓ . ✓ - gowork ✓ . . . ✓ - gpg ✓ . . . ✓ - graphql ✓ . . ✓ ✓ - groovy ✓ ✓ ✓ ✓ ✓ - gstlaunch ✓ . . . . - hack ✓ . . . ✓ - hare ✓ ✓ ✓ ✓ ✓ - haskell ✓ ✓ ✓ . ✓ - haskell_persistent ✓ . ✓ . . - hcl ✓ . ✓ ✓ ✓ - heex ✓ ✓ ✓ ✓ ✓ - helm ✓ ✓ ✓ . ✓ - hjson ✓ ✓ ✓ ✓ ✓ - hlsl ✓ ✓ ✓ ✓ ✓ - hlsplaylist ✓ . . . ✓ - hocon ✓ . ✓ . ✓ - hoon ✓ ✓ ✓ . ✓ - html ✓ ✓ ✓ ✓ ✓ - htmldjango ✓ . ✓ ✓ ✓ - http ✓ . . . ✓ - hurl ✓ . ✓ ✓ ✓ - hyprlang ✓ . ✓ ✓ ✓ - idl ✓ . . ✓ ✓ - ini ✓ . ✓ . ✓ - inko ✓ ✓ ✓ ✓ ✓ - ispc ✓ ✓ ✓ ✓ ✓ - janet_simple ✓ ✓ ✓ . ✓ - java ✓ ✓ ✓ ✓ ✓ - javascript ✓ ✓ ✓ ✓ ✓ - jq ✓ ✓ . . ✓ - jsdoc ✓ . . . . - json ✓ ✓ ✓ ✓ . - json5 ✓ . . . ✓ - jsonc ✓ ✓ ✓ ✓ ✓ - jsonnet ✓ ✓ ✓ . ✓ - julia ✓ ✓ ✓ ✓ ✓ - just ✓ ✓ ✓ ✓ ✓ - kconfig ✓ ✓ ✓ ✓ ✓ - kdl ✓ ✓ ✓ ✓ ✓ - kotlin ✓ ✓ ✓ . ✓ - koto ✓ ✓ ✓ . ✓ - kusto ✓ . . . ✓ - lalrpop ✓ ✓ ✓ . ✓ - ledger ✓ . ✓ ✓ ✓ - leo ✓ . . ✓ ✓ - linkerscript ✓ ✓ ✓ ✓ ✓ - liquid ✓ . . . ✓ - liquidsoap ✓ ✓ ✓ ✓ ✓ - llvm ✓ . . . ✓ - lua ✓ ✓ ✓ ✓ ✓ - luadoc ✓ . . . . - luap ✓ . . . . - luau ✓ ✓ ✓ ✓ ✓ - m68k ✓ ✓ ✓ . ✓ - make ✓ . ✓ . ✓ - markdown ✓ . ✓ ✓ ✓ - markdown_inline ✓ . . . ✓ - matlab ✓ ✓ ✓ ✓ ✓ - menhir ✓ . . . ✓ - mermaid ✓ . ✓ ✓ ✓ - meson ✓ . ✓ ✓ ✓ - muttrc ✓ . . . ✓ - nasm ✓ . . . ✓ - nginx ✓ . ✓ . ✓ - nickel ✓ . . ✓ ✓ - nim ✓ ✓ ✓ . ✓ - nim_format_string ✓ . . . ✓ - ninja ✓ . ✓ ✓ ✓ - nix ✓ ✓ ✓ ✓ ✓ - norg . . . . . - nqc ✓ ✓ ✓ ✓ ✓ - objc ✓ ✓ ✓ ✓ ✓ - objdump ✓ . . . ✓ - ocaml ✓ ✓ ✓ ✓ ✓ - ocaml_interface ✓ ✓ ✓ ✓ ✓ - odin ✓ ✓ ✓ ✓ ✓ - org ✓ . . . . - pascal ✓ ✓ ✓ ✓ ✓ - passwd ✓ . . . . - pem ✓ . ✓ . ✓ - perl ✓ . ✓ . ✓ - php ✓ ✓ ✓ ✓ ✓ - php_only ✓ ✓ ✓ ✓ ✓ - phpdoc ✓ . . . . - pioasm ✓ . . . ✓ - po ✓ . ✓ . ✓ - pod ✓ . . . . - poe_filter ✓ . ✓ ✓ ✓ - pony ✓ ✓ ✓ ✓ ✓ - powershell ✓ ✓ ✓ ✓ ✓ - printf ✓ . . . . - prisma ✓ . ✓ . ✓ - problog ✓ . ✓ ✓ ✓ - prolog ✓ . ✓ ✓ ✓ - promql ✓ . . . ✓ - properties ✓ ✓ . . ✓ - proto ✓ . ✓ ✓ ✓ - prql ✓ . . . ✓ - psv ✓ . . . . - pug ✓ . . . ✓ - puppet ✓ ✓ ✓ ✓ ✓ - purescript ✓ ✓ . . ✓ - pymanifest ✓ . . . ✓ - python ✓ ✓ ✓ ✓ ✓ - ql ✓ ✓ ✓ ✓ ✓ - qmldir ✓ . . . ✓ - qmljs ✓ ✓ ✓ . ✓ - query ✓ ✓ ✓ ✓ ✓ - r ✓ ✓ . ✓ ✓ - racket ✓ ✓ ✓ . ✓ - ralph ✓ . . . ✓ - rasi ✓ ✓ ✓ ✓ ✓ - rbs ✓ . ✓ ✓ ✓ - re2c ✓ ✓ ✓ ✓ ✓ - readline ✓ . ✓ ✓ ✓ - regex ✓ . . . . - rego ✓ ✓ . . ✓ - requirements ✓ . . . ✓ - rescript ✓ ✓ ✓ ✓ ✓ - rnoweb ✓ . ✓ . ✓ - robot ✓ . ✓ ✓ ✓ - robots ✓ . . . ✓ - roc ✓ ✓ . ✓ ✓ - ron ✓ ✓ ✓ ✓ ✓ - rst ✓ ✓ . . ✓ - ruby ✓ ✓ ✓ ✓ ✓ - rust ✓ ✓ ✓ ✓ ✓ - scala ✓ ✓ ✓ ✓ ✓ - scheme ✓ . ✓ . ✓ - scss ✓ . ✓ ✓ ✓ - sflog ✓ . . . . - slang ✓ ✓ ✓ ✓ ✓ - slint ✓ ✓ ✓ ✓ ✓ - smali ✓ ✓ ✓ ✓ ✓ - smithy ✓ . . . ✓ - snakemake ✓ ✓ ✓ ✓ ✓ - solidity ✓ ✓ ✓ . ✓ - soql ✓ . . . . - sosl ✓ . . . . - sourcepawn ✓ ✓ . . ✓ - sparql ✓ ✓ ✓ ✓ ✓ - sql ✓ . . ✓ ✓ - squirrel ✓ ✓ ✓ ✓ ✓ - ssh_config ✓ ✓ ✓ ✓ ✓ - starlark ✓ ✓ ✓ ✓ ✓ - strace ✓ . . . ✓ - styled ✓ . ✓ ✓ ✓ - supercollider ✓ ✓ ✓ ✓ ✓ - surface ✓ . ✓ ✓ ✓ - svelte ✓ ✓ ✓ ✓ ✓ - sxhkdrc ✓ . ✓ . ✓ - systemtap ✓ ✓ ✓ . ✓ - systemverilog ✓ . ✓ . ✓ - t32 ✓ ✓ ✓ ✓ ✓ - tablegen ✓ ✓ ✓ ✓ ✓ - tact ✓ ✓ ✓ ✓ ✓ - tcl ✓ . ✓ ✓ ✓ - templ ✓ . ✓ . ✓ - terraform ✓ . ✓ ✓ ✓ - textproto ✓ . ✓ ✓ ✓ - thrift ✓ ✓ ✓ ✓ ✓ - tiger ✓ ✓ ✓ ✓ ✓ - tlaplus ✓ ✓ ✓ . ✓ - tmux ✓ . . . ✓ - todotxt ✓ . . . . - toml ✓ ✓ ✓ ✓ ✓ - tsv ✓ . . . . - tsx ✓ ✓ ✓ ✓ ✓ - turtle ✓ ✓ ✓ ✓ ✓ - twig ✓ . . . ✓ - typescript ✓ ✓ ✓ ✓ ✓ - typespec ✓ . . ✓ ✓ - typoscript ✓ . ✓ ✓ ✓ - typst ✓ . ✓ ✓ ✓ - udev ✓ ✓ . . ✓ - ungrammar ✓ ✓ ✓ ✓ ✓ - usd ✓ ✓ ✓ ✓ ✓ - uxntal ✓ ✓ ✓ ✓ ✓ - v ✓ ✓ ✓ ✓ ✓ - vala ✓ ✓ ✓ . ✓ - vento ✓ . . . ✓ - verilog ✓ ✓ ✓ . ✓ - vhdl ✓ . ✓ . ✓ - vhs ✓ . . . ✓ - vim ✓ ✓ ✓ . ✓ - vimdoc ✓ . . . ✓ - vrl ✓ ✓ ✓ ✓ ✓ - vue ✓ . ✓ ✓ ✓ - wgsl ✓ . ✓ ✓ ✓ - wgsl_bevy ✓ . ✓ ✓ . - wing ✓ ✓ ✓ . ✓ - wit ✓ . ✓ . ✓ - xcompose ✓ ✓ . . ✓ - xml ✓ ✓ ✓ ✓ ✓ - yaml ✓ ✓ ✓ ✓ ✓ - yang ✓ . ✓ ✓ ✓ - yuck ✓ ✓ ✓ ✓ ✓ - zathurarc ✓ . . . ✓ - zig ✓ ✓ ✓ ✓ ✓ Legend: H[ighlight], L[ocals], F[olds], I[ndents], In[j]ections +) multiple parsers found, only one will be used x) errors found in the query, try to run :TSUpdate {lang} ~

Output of nvim --version

NVIM v0.10.2
Build type: Release
LuaJIT 2.1.1713773202
Run "nvim -V1 -v" for more info

Additional context This is using the main branch rather than master, as I am using nvim 0.10

clason commented 3 days ago

The main branch is not ready for use yet, and requires Neovim nightly.