ziontee113 / syntax-tree-surfer

A plugin for Neovim that helps you surf through your document and move elements around using the nvim-treesitter API.
MIT License
469 stars 9 forks source link

Unable to swap nodes #1

Closed mehalter closed 2 years ago

mehalter commented 2 years ago

I am giving this plugin a try and so far it is great! One thing that I am running into is I am unable to use the swap commands at all both in normal mode or visual mode. I get the following error every time:

2022-04-18_10:01:22_screenshot

I'm currently using these as my bindings:

    map("x", "J", function()
      require("syntax-tree-surfer").surf("next", "visual")
    end)
    map("x", "K", function()
      require("syntax-tree-surfer").surf("prev", "visual")
    end)
    map("x", "H", function()
      require("syntax-tree-surfer").surf("parent", "visual")
    end)
    map("x", "L", function()
      require("syntax-tree-surfer").surf("child", "visual")
    end)
    map("x", "<c-j>", function()
      require("syntax-tree-surfer").surf("next", "visual", true)
    end)
    map("x", "<c-l>", function()
      require("syntax-tree-surfer").surf("next", "visual", true)
    end)
    map("x", "<c-k>", function()
      require("syntax-tree-surfer").surf("prev", "visual", true)
    end)
    map("x", "<c-h>", function()
      require("syntax-tree-surfer").surf("prev", "visual", true)
    end)
    map("n", "<c-down>", function()
      require("syntax-tree-surfer").move("n", false)
    end)
    map("n", "<c-right>", function()
      require("syntax-tree-surfer").move("n", false)
    end)
    map("n", "<c-up>", function()
      require("syntax-tree-surfer").move("n", true)
    end)
    map("n", "<c-left>", function()
      require("syntax-tree-surfer").move("n", true)
    end)

Also I am using neovim v0.7 stable

fsouza commented 2 years ago

Yeah there's a breaking change in nvim-treesitter. I can send a PR later today if no one beats me to it.

fsouza commented 2 years ago

This is a breakage in nvim-treesitter: https://github.com/nvim-treesitter/nvim-treesitter/pull/2834/files#r852542169

fsouza commented 2 years ago

Sent the PR nvim-treesitter/nvim-treesitter#2838, but an easy workaround for now is to pin nvim-treesitter to 21ac88b9551072f49ba994f461f78794af43a5aa.

ziontee113 commented 2 years ago

Hi @fsouza & @mehalter . I'm sorry for not replying sooner. I just realized the swapping functionalities stopped working by now. This is my first time handling an issue / PR. I'll try to figure things out as soon as possible. Thank you!

fsouza commented 2 years ago

Hi @fsouza & @mehalter . I'm sorry for not replying sooner. I just realized the swapping functionalities stopped working by now. This is my first time handling an issue / PR. I'll try to figure things out as soon as possible. Thank you!

No worries. It's taken care of with that nvim-treesitter PR, just need to wait for it to be merged.

ziontee113 commented 2 years ago

Hi @fsouza , I saw that the PR got accepted. Do we have to wait for it to get merged into nvim-treesitter core as well? This is quite a long & difficult process.

fsouza commented 2 years ago

Hi @fsouza , I saw that the PR got accepted. Do we have to wait for it to get merged into nvim-treesitter core as well? This is quite a long & difficult process.

I think they asked for one additional change, which I'll address later today.

In order to unblock users of syntax-tree-surfer, we could:

  1. Document the required version of nvim-treesitter so users can pin it
  2. Fork the swap_nodes function and bring a private copy of it to this repo.

I prefer a third option: wait and see if we can get that PR merged today, and maybe if that doesn't happen, act tomorrow on option 1 or 2.

ziontee113 commented 2 years ago

Thank you for your hard work 🙏. I'll follow your advice.

fsouza commented 2 years ago

It's merged now! We can probably close this issue now 🎉

ziontee113 commented 2 years ago

Nice!