nvim-treesitter / nvim-treesitter

Nvim Treesitter configurations and abstraction layer
Apache License 2.0
10.88k stars 906 forks source link

Regression: parameter substitution in bash raises error `Invalid node type ""` #7338

Closed hejops closed 2 weeks ago

hejops commented 2 weeks ago

Describe the bug

The following bash code

${foo/a/b}

raises the error:

Error in decoration provider treesitter/highlighter.win:
Error executing lua: ...2962/usr/share/nvim/runtime/lua/vim/treesitter/query.lua:252: Query error at 9:4. Invalid nod
e type "":
  "<"
   ^

stack traceback:
        [C]: in function '_ts_parse_query'
        ...2962/usr/share/nvim/runtime/lua/vim/treesitter/query.lua:252: in function 'fn'
        ...im/2962/usr/share/nvim/runtime/lua/vim/func/_memoize.lua:58: in function 'fn'
        ...im/2962/usr/share/nvim/runtime/lua/vim/func/_memoize.lua:58: in function 'get'
        ...sr/share/nvim/runtime/lua/vim/treesitter/highlighter.lua:28: in function 'new'
        ...sr/share/nvim/runtime/lua/vim/treesitter/highlighter.lua:243: in function 'get_query'
        ...sr/share/nvim/runtime/lua/vim/treesitter/highlighter.lua:191: in function 'fn'
        ...r/share/nvim/runtime/lua/vim/treesitter/languagetree.lua:491: in function 'for_each_tree'
        ...r/share/nvim/runtime/lua/vim/treesitter/languagetree.lua:495: in function 'for_each_tree'
        ...sr/share/nvim/runtime/lua/vim/treesitter/highlighter.lua:178: in function 'pre

This regression seems to have been introduced in eab2005cb5a839abb4af9961a76bbf819650a1a9.

To Reproduce

echo '${foo/a/b}' > foo.sh
nvim foo.sh

Expected behavior

With commit c91122d2012682301df68307cfc049a57c3fd286, the code is parsed and highlighted with no errors. With commit eab2005cb5a839abb4af9961a76bbf819650a1a9 and onwards, the above error is raised.

Output of :checkhealth nvim-treesitter

==============================================================================
nvim-treesitter: require("nvim-treesitter.health").check()

Installation ~
- OK `tree-sitter` found 0.20.8 (parser generator, only needed for :TSInstallFromGrammar)
- OK `node` found v18.19.1 (only needed for :TSInstallFromGrammar)
- OK `git` executable found.
- OK `cc` executable found. Selected from { vim.NIL, "cc", "gcc", "clang", "cl", "zig" }
  Version: cc (Ubuntu 13.2.0-23ubuntu4) 13.2.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.8.0-47-generic",
  sysname = "Linux",
  version = "#47-Ubuntu SMP PREEMPT_DYNAMIC Fri Sep 27 21:40:26 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                ✓ ✓ ✓ ✓ ✓
  - desktop             ✓ . ✓ . ✓
  - 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             ✓ . . ✓ ✓
  - gren                ✓ . . . ✓
  - 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                   x ✓ . ✓ ✓
  - racket              ✓ . ✓ . ✓
  - ralph               ✓ . . . ✓
  - rasi                ✓ ✓ ✓ ✓ ✓
  - rbs                 ✓ . ✓ ✓ ✓
  - re2c                ✓ ✓ ✓ ✓ ✓
  - readline            ✓ . ✓ ✓ ✓
  - regex               x . . . .
  - 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       ✓ ✓ ✓ ✓ ✓
  - superhtml           ✓ . . . ✓
  - surface             ✓ . ✓ ✓ ✓
  - svelte              ✓ ✓ ✓ ✓ ✓
  - sxhkdrc             ✓ . ✓ . ✓
  - systemtap           ✓ ✓ ✓ . ✓
  - 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                 ✓ ✓ ✓ ✓ ✓
  - xresources          ✓ ✓ ✓ . ✓
  - yaml                ✓ ✓ ✓ ✓ ✓
  - yang                ✓ . ✓ ✓ ✓
  - yuck                ✓ ✓ ✓ ✓ ✓
  - zathurarc           ✓ . . . ✓
  - zig                 ✓ ✓ ✓ ✓ ✓
  - ziggy               ✓ . . ✓ .
  - ziggy_schema        ✓ . . ✓ .

  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} ~

The following errors have been detected: ~
- ERROR r(highlights): ...2962/usr/share/nvim/runtime/lua/vim/treesitter/query.lua:252: Query error at 151:2. Invalid node type "dollar":
  (dollar
   ^

  r(highlights) is concatenated from the following files:
  |    [OK]:"/home/joseph/.local/share/nvim/lazy/nvim-treesitter/queries/r/highlights.scm"
  | [ERROR]:"/home/joseph/.local/share/nvim/lazy/night-owl.nvim/after/queries/r/highlights.scm", failed to load: ...2962/usr/share/nvim/runtime/lua/vim/treesitter/query.lua:252: Query error at 3:2. Invalid node type "dollar":
  (dollar
   ^

- ERROR regex(highlights): ...2962/usr/share/nvim/runtime/lua/vim/treesitter/query.lua:252: Query error at 9:4. Invalid node type "":
    "<"
     ^

  regex(highlights) is concatenated from the following files:
  | [ERROR]:"/home/joseph/.local/share/nvim/lazy/nvim-treesitter/queries/regex/highlights.scm", failed to load: ...2962/usr/share/nvim/runtime/lua/vim/treesitter/query.lua:252: Query error at 9:4. Invalid node type "":
    "<"
     ^

Output of nvim --version

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

Additional context

require("nvim-treesitter.configs").setup({
    modules = {},
    ignore_install = {},
    sync_install = #vim.api.nvim_list_uis() == 0,
    ensure_installed = {
        "bash",
        "css",
        "csv",
        "diff",
        "gitcommit",
        "gitignore",
        "go",
        "gomod",
        "gosum",
        "html",
        "htmldjango",
        "javascript",
        "jsdoc",
        "json",
        "jsonc",
        "lua",
        "markdown",
        "markdown_inline",
        "muttrc",
        "python",
        "rasi",
        "rust",
        "sql",
        "toml",
        "typescript",
        "vim",
        "vimdoc",
        "yaml",
        "zig",
    },
    auto_install = false, 
    highlight = { enable = true }, 
    indent = { enable = true },
    textobjects = {
        select = {
            enable = true,
            lookahead = true, 
            keymaps = {
                ["aa"] = "@parameter.outer",
                ["ac"] = "@class.outer",
                ["af"] = "@function.outer", 
                ["ia"] = "@parameter.inner",
                ["ic"] = "@class.inner",
                ["if"] = "@function.inner",
            },
        },
        move = { 
            enable = true,
            set_jumps = false, 
            goto_next_start = {
                ["gj"] = "@function.outer", 
                ["gJ"] = "@class.outer", 
            },
            goto_previous_start = {
                ["gk"] = "@function.outer",
                ["gK"] = "@class.outer",
            },
            goto_next_end = {
                ["gl"] = "@function.outer",
                ["gL"] = "@class.outer",
            },
            goto_previous_end = {
                ["gh"] = "@function.outer",
                ["gH"] = "@class.outer",
            },
        },
    },
    incremental_selection = { 
        enable = true,
        keymaps = {
            init_selection = "<c-space>", 
            node_decremental = "grm",
            node_incremental = "grn",
            scope_incremental = "grc", 
        },
    },
})
victorgdb commented 2 weeks ago

Thanks for reporting the issue.

return {
  'nvim-treesitter/nvim-treesitter', 
  commit = 'c91122d2012682301df68307cfc049a57c3fd286',
   ...
}

Pinning the commit you specified to nvim-treesitter lazy config works as a workaround.

hejops commented 2 weeks ago

Yep, that's what I'm doing at the moment 😃

clason commented 2 weeks ago

Duplicate of #3092