nvim-treesitter / nvim-treesitter-textobjects

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`-` in capture name makes move submodule key maps ineffective

jakubkaczor opened this issue · comments

Describe the bug
The move submodule key maps aren't effective, when custom capture has - character in the name, but others, for example select, do. I have defined (code_fence_content) @code-block.inner in Markdown's textobjects.scm. I can do things like vic (visual inner code) having ["ic"] = "@code-block.inner", in the select submodule configuration, but ["]c"] = "@code-block.inner" in move submodule configuration doesn't work. When I rename code-block to code_block everywhere, it works as expected.

To Reproduce
Steps to reproduce the behavior:

  1. Create textobjects.scm for Markdown containing (code_fence_content) @code-block.inner,
  2. edit configuration to contain
    textobjects = {
        select = {
            enable = true,
            lookahead = true,
            keymaps = {
                ["ic"] = "@code-block.inner",
            },
        },
        move = {
            enable = true,
            goto_next_start = {
                ["]c"] = "@code-block.inner",
        },
    },
  3. open any Markdown file containing code blocks,
  4. press ]c and see it is ineffective.

Expected behavior
Key maps working despite - in capture name.

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 v16.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 (GCC) 12.2.1 20230201 - 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.2.6-arch1-1",
sysname = "Linux",
version = "#1 SMP PREEMPT_DYNAMIC Mon, 13 Mar 2023 17:02:08 +0000"
}

Parser/Features H L F I J

  • bash ✓ ✓ ✓ . ✓
  • bibtex ✓ . ✓ ✓ .
  • c ✓ ✓ ✓ ✓ ✓
  • comment ✓ . . . .
  • css ✓ . ✓ ✓ ✓
  • diff ✓ . . . .
  • dockerfile ✓ . . . ✓
  • dot ✓ . . . ✓
  • git_rebase ✓ . . . ✓
  • gitattributes ✓ . . . ✓
  • gitcommit ✓ . . . ✓
  • gitignore ✓ . . . .
  • help ✓ . . . ✓
  • hjson ✓ ✓ ✓ ✓ ✓
  • html ✓ ✓ ✓ ✓ ✓
  • json ✓ ✓ ✓ ✓ .
  • julia ✓ ✓ ✓ ✓ ✓
  • latex ✓ . ✓ . ✓
  • lua ✓ ✓ ✓ ✓ ✓
  • make ✓ . ✓ . ✓
  • markdown ✓ . ✓ . ✓
  • markdown_inline ✓ . . . ✓
  • norg . . . . .
  • nu ✓ ✓ ✓ . ✓
  • python ✓ ✓ ✓ ✓ ✓
  • query ✓ ✓ ✓ ✓ ✓
  • r ✓ ✓ . ✓ ✓
  • regex ✓ . . . .
  • rnoweb ✓ . ✓ . ✓
  • rst ✓ ✓ . . ✓
  • rust ✓ ✓ ✓ ✓ ✓
  • scss ✓ . ✓ ✓ .
  • sparql ✓ ✓ ✓ ✓ ✓
  • sql x . . . ✓
  • toml ✓ ✓ ✓ ✓ ✓
  • yaml ✓ ✓ ✓ ✓ ✓

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: sql(highlights): /usr/share/nvim/runtime/lua/vim/treesitter/query.lua:219: query: invalid node type at position 3557 for language sql
    sql(highlights) is concatenated from the following files:
    | [ERROR]:"/home/jakub/.local/share/nvim/lazy/nvim-treesitter/queries/sql/highlights.scm", failed to load: /usr/share/nvim/runtime/lua/vim/treesitter/query.lua:219: query: invalid node type at position 3557 for language sql

Output of nvim --version

NVIM v0.8.3
Build type: Release
LuaJIT 2.1.0-beta3
Compiled by builduser

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

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

Run :checkhealth for more info

Additional context
Captures with - in the name are even mentioned in the README, but with select submodule.

The query string is a regex now. You'll need to escape it (@code%-block.inner) or avoid special characters. Readme should be updated

@kiyoon thank you, that explains everything. I read the README carefully once again, and indeed, there is one example saying that it can be a regex. I assume that these are Lua patterns, to be specific. I did the necessary changes and now it works as expected. I assume that this is specific to the move module, is this correct? If these are Lua patterns, then . should also be replaced with %.. Perhaps replacing . with %. in all examples would make it clear, that every such a string is interpreted as a Lua pattern.

Yes, it is only for move and it's a lua pattern and dot should be escaped, but I guess that's optional unless you have a weird name. Will update readme soon to make it more clear