I'm hoping to write a macro that involves jumping to a second argument of a function call and deleting it. The function arguments will sometimes include nested function calls, sometimes not, will sometimes be on multiple lines, and sometimes all on one line.
I was hoping to use nvim-treesitter-textobjects to jump to the next argument via something like this:
require'nvim-treesitter.configs'.setup {
textobjects = {
move = {
enable = true,
set_jumps = true,
goto_previous_start = {
["[["] = "@parameter.inner",
},
goto_next_start = {
["]]"] = "@parameter.inner",
},
},
},
}
And then for example, with a code snippet like this:
func foo(a, b int) int {
return a * b
}
func bar(a, b int) int {
return a + b
}
func main() {
foo(
bar(
1,
2,
),
3,
)
}
When my cursor is on bar
, and I hit ]]
, I'd like it to jump to 3
, the next argument at the same level as the current node. However, it unfortunately jumps to 1
, the next argument at the lower level of the nested function call.
Any suggestions for how to achieve this desired jump?