Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'mini.surround' treesitter surrounding throws error with "@parameter" capture #1682

Open
3 tasks done
mdietrich16 opened this issue Mar 16, 2025 · 3 comments
Open
3 tasks done
Labels
bug Something isn't working mini.surround

Comments

@mdietrich16
Copy link

Contributing guidelines

Module(s)

mini.surround

Neovim version

0.10.x

Description

On both 0.10.x and latest 0.11 nightly (on NixOS via official overlay), an error is thrown when using the keymap associated with the treesitter capture "@parameter.inner" and "@parameter.outer". On 0.10.x, the error is

E5108: Error executing lua ...d-0.10.4/share/nvim/runtime/lua/vim/treesitter/query.lua:952: bad argument #1 to '_create_ts_querycursor' (treesitter_node expected, got table)
stack traceback:
	[C]: in function '_create_ts_querycursor'
	...d-0.10.4/share/nvim/runtime/lua/vim/treesitter/query.lua:952: in function 'iter_matches'
	...ckages/opt/nvim-treesitter/lua/nvim-treesitter/query.lua:251: in function 'iter_group_results'
	...ckages/opt/nvim-treesitter/lua/nvim-treesitter/query.lua:320: in function 'get_capture_matches'
	...myNeovimPackages/opt/mini.surround/lua/mini/surround.lua:1506: in function <...myNeovimPackages/opt/mini.surround/lua/mini/surround.lua:1505>
	vim/shared.lua: in function 'range_pair_querier'
	...myNeovimPackages/opt/mini.surround/lua/mini/surround.lua:1040: in function 'input'
	[string ":lua"]:1: in main chunk

The corresponding "nvim-treesitter-textobjects" mappings work (i.e. select "ia" and "aa" work)

Reproduction

Using "mini.surround" standalone, with "nvim-treesitter" and "nvim-treesitter-textobjects" installed. All are lazy-loaded with lze on a "DeferredUIEnter" event ("VeryLazy" equivalent). The configurations are

require("nvim-treesitter.configs").setup({
  highlight = { enable = true, disable = { "latex" } },
  indent = { enable = false },
  incremental_selection = {
    enable = true,
    keymaps = {
      init_selection = "<c-space>",
      node_incremental = "<c-space>",
      scope_incremental = "<c-s>",
      node_decremental = "<M-space>",
    },
  },
  textobjects = {
    select = {
      enable = true,
      lookahead = true,
      keymaps = {
        ["aa"] = { query = "@parameter.outer", desc = "Select around parameter" },
        ["ia"] = { query = "@parameter.inner", desc = "Select inside parameter" },
        ["af"] = { query = "@function.outer", desc = "Select around function" },
        ["if"] = { query = "@function.inner", desc = "Select inner part of function" },
        ["ac"] = { query = "@class.outer", desc = "Select around class" },
        ["ic"] = { query = "@class.inner", desc = "Select inner part of class" },
        ["as"] = { query = "@scope", query_group = "locals", desc = "Select language scope" },
        ["ab"] = { query = "@code_cell.outer", desc = "Select around block" },
        ["ib"] = { query = "@code_cell.inner", desc = "Select inner block" },
      },
    },
  },
})

local ts_input = require("mini.surround").gen_spec.input.treesitter
require("mini.surround").setup({
  custom_surroundings = {
    a = {
      input = ts_input({ outer = "@parameter.outer", inner = "@parameter.inner" }),
    },
    f = {
      input = ts_input({ outer = "@function.outer", inner = "@function.inner" }),
    },
    c = {
      input = ts_input({ outer = "@class.outer", inner = "@class.inner" }),
    },
    s = {
      input = ts_input({ outer = "@scope.outer", inner = "@scope.inner" }),
    },
    b = {
      input = ts_input({ outer = "@code_cell.outer", inner = "@code_cell.inner" }),
    },
    i = {
      input = ts_input({ outer = "@conditional.outer", inner = "@conditional.inner" }),
    },
  },
})
@mdietrich16 mdietrich16 added the bug Something isn't working label Mar 16, 2025
@echasnovski
Copy link
Owner

Thanks for the issue!

I can reproduce with built-in Lua tree-sitter parser. But this seems to happen only for @parameter.outer+@parameter.inner pair. Using 'nvim-treesitter' (current default) throws error while using built-in vim.treesitter just doesn't find a surrounding. I'll take a look.


As surrounding based on @parameter.{outer,inner} pair doesn't look useful to me (it usually matches a comma and some whitespace), what is your use case for this surrounding?

@mdietrich16
Copy link
Author

Actually, it seems I hadn't thought this completely through, you are right that it doesn't really make sense to use. I think I actually wanted the 'saaa{' ('[s]urround [a]dd [a]round [a]rgument [{]') actions, which works with just default 'mini.surround' + 'nvim-treesitter-context'. Should I close this issue or leave it open since it seems to be a bug, albeit quite inconsequential?

@echasnovski
Copy link
Owner

Should I close this issue or leave it open since it seems to be a bug, albeit quite inconsequential?

I am pretty sure that it is either 'nvim-treesitter/nvim-treesitter' or vim.treesitter issue. Let's keep it open for a while, so that I'd not forget to try to take a closer look into it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working mini.surround
Projects
None yet
Development

No branches or pull requests

2 participants