nvim-treesitter / nvim-treesitter/nvim-treesitter-textobjects
Pasting a copied parameter before/after the current parameter
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 think it would be so useful to use something like this:
require'nvim-treesitter.configs'.setup {
textobjects = {
select = {
enable = true,
keymaps = {
["ap"] = "@parameter.outer",
}
}
}
}
nmap <leader>P :TSPasteParameterBefore<CR>
nmap <leader>p :TSPasteParameterAfter<CR>
Then if I could take a function call like:
blah(arg1, arg2, arg3);
and hover arg2 and use dap to delete arg2.
Then hover arg1 and use a keybinding to paste the parameter I just copied before arg1 or use a different keybinding to paste the parameter after arg1 (in this case <leader>P for "before" and <leader>p for "after").
When I do dap it copies the preceding , (or sometimes the trailing ,). When pasting the code would first need to remove the preceding/trailing , and then enter a new , after the pasted parameter when pasting before the final parameter, or enter a preceding , when pasting into the final parameter position. If there are no parameters then no trailing/preceding , would be added (for languages that support trailing , after the last parameter, could leave it up to the user's code formatter to handle this but in cases where a trailing , already exists then pasting into the final parameter position should not enter the preceding ,). I'm aware there are languages that don't use , between parameters such as Haskell, for such languages it would be easier.
This might not be the direction you see nvim-treesitter-textobjects going, and if not, I'm happy to provide this support in a new plugin, but I'd be really grateful for any advice you could give me on how I might implement this.
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 by reviewing the nvim-treesitter-textobjects setup shown in the issue, especially the @parameter.outer selection and proposed TSPasteParameterBefore/TSPasteParameterAfter mappings. Trace how dap deletes or copies a parameter, then determine how parameter separators should behave across the listed cases and languages. Done means copied parameters can be pasted before or after the active parameter without malformed separators.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- lua, neovim
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100