nvim-treesitter / nvim-treesitter/nvim-treesitter-textobjects

`swap` can not swap children across parents

Open
#677 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

bug NEXT
Dominant language
Tree-sitter Query
Stars
2.8k
Forks
271
Avg merge
8d 8h
Merged PRs (30d)
1

Description

To record a regression I found while refactoring main.

function f1(arg1, arg2)
  ...
end

function f2(arg3, arg4)
  ...
end

Formerly if we call swap_next("@parameter.inner") while the cursor is at arg2, nothing will happen, because there's no next parameter in the same parent node. Now it will swap with arg3 in f2 because it is the next parameter even though they do not have a common parent node.

Currently, it seems not possible to do this because we only record nodes' range, but it should be easily fixed if we complete https://github.com/nvim-treesitter/nvim-treesitter-textobjects/pull/674.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the example by calling swap_next("@parameter.inner") at arg2, then read PR #674 and the swap_next entry point to understand the recorded node ranges. Done means parameters are swapped only when they share a parent, so arg2 is not exchanged with arg3 in f2.

Written by the indexing model from the issue text.

Assessment

Tech stack
lua, neovim
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.