nvim-treesitter / nvim-treesitter/nvim-treesitter-textobjects
Support for GNU Makefiles: swap function arguments
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 would like to use the module swap for GNU Make function arguments. An example is
$(foreach ext, $(CLEAN_EXTS), $(docs:%.$(FORMAT)=%.$(ext)))
https://www.gnu.org/software/make/manual/html_node/Syntax-of-Functions.html
with the syntax tree:
function_call [0, 0] - [0, 59]
arguments [0, 10] - [0, 58]
argument: text [0, 10] - [0, 58]
variable_reference [0, 15] - [0, 28]
word [0, 17] - [0, 27]
substitution_reference [0, 30] - [0, 58]
text: word [0, 32] - [0, 36]
pattern: concatenation [0, 37] - [0, 48]
word [0, 37] - [0, 39]
variable_reference [0, 39] - [0, 48]
word [0, 41] - [0, 47]
replacement: concatenation [0, 49] - [0, 57]
word [0, 49] - [0, 51]
variable_reference [0, 51] - [0, 57]
word [0, 53] - [0, 56]
Could I use the mappings <leader>a and <leader>A to swap arguments?
Note the first argument is delimited on the left with whitespace and the last argument is delimited on the right with ). All others are surrounded with ,.
My current textobjects.scm is based on other files in this repository without much understanding.
((arguments
"," @_start . (_) @parameter.inner)
(#make-range! "parameter.outer" @_start @parameter.inner))
((arguments
. (_) @parameter.inner . ","? @_end)
(#make-range! "parameter.outer" @parameter.inner @_end))
And it throws an error when I press <leader>a
|| E5108: Error executing lua: ...ter-textobjects/lua/nvim-treesitter/textobjects/swap.lua:11: bad argument #1 to 'ipairs' (table expected, got nil)
|| stack traceback:
|| [C]: in function 'ipairs'
|| ...ter-textobjects/lua/nvim-treesitter/textobjects/swap.lua:11: in function 'swap_textobject'
|| ...ter-textobjects/lua/nvim-treesitter/textobjects/swap.lua:34: in function <...ter-textobjects/lua/nvim-treesitter/textobjects/swap.lua:32>
|| ...r-textobjects/lua/nvim-treesitter/textobjects/attach.lua:28: in function <...r-textobjects/lua/nvim-treesitter/textobjects/attach.lua:27>
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 with the supplied textobjects.scm query and lua/nvim-treesitter/textobjects/swap.lua, then inspect lua/nvim-treesitter/textobjects/attach.lua to understand how swap mappings receive captures. Reproduce the GNU Make example and its syntax tree, and consider the issue complete when the swap mappings work for the first, middle, and last arguments without the reported Lua error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- lua, neovim
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100