nvim-treesitter / nvim-treesitter/nvim-treesitter-textobjects
[Question] How to jump to next argument without going into nested function calls
Nobody has claimed this yet.
- Dominant language
- Tree-sitter Query
- Stars
- 2.8k
- Forks
- 271
- Avg merge
- 8d 8h
- Merged PRs (30d)
- 1
Description
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'm struggling to figure out how to use nvim-treesitter-textobjects to achieve the desired jumps.
My move configuration currently looks 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 currently jumps to 1, the next argument at the lower level of the nested function call.
Any suggestions for how to achieve this desired jump? Thank you for your help!
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start from the textobjects.move configuration shown in the issue and reproduce the nested Go example with @parameter.inner. Inspect how the next-start movement handles nested parameters and determine whether same-level navigation is supported or needs a change. Done means pressing ]] from bar lands on 3 rather than 1.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- lua
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100