Vigemus / iron.nvim

Interactive Repl Over Neovim
BSD 3-Clause "New" or "Revised" License
1.01k stars 81 forks source link

Add support for Treesitter textobjects #210

Open timoleistner opened 2 years ago

timoleistner commented 2 years ago

I was thinking about sending the output of a treesitter.textobjects command to irons REPL but I fear my lua skills aren't there yet. I tried this :lua require('iron').core.send(vim.bo.ft, require'nvim-treesitter.textobjects.select'.select_textobject('@function.outer', 'o')) and this require("iron").core.visual_send(vim.bo.ft, require'nvim-treesitter.textobjects.select'.select_textobject('@function.outer', 'o')) without success and I dont really understand whats meant with "data" in the documentation, help about this would be appreciated. If it is feasible it would be nice to have native support for treesitter objects :)

hkupty commented 2 years ago

This would definitely be an amazing addition.. I'll have a look at it and will try to come up with something workable :)

f3fora commented 1 year ago

I use succesfully the following snippet.

local is = require("nvim-treesitter.incremental_selection")
local function treesitter_selection()
  is.init_selection()
  is.node_incremental()
end
require("iron").core.visual_send(vim.bo.ft, treesitter_selection)
makp commented 5 months ago
local is = require("nvim-treesitter.incremental_selection")
local function treesitter_selection()
  is.init_selection()
  is.node_incremental()
end
require("iron").core.visual_send(vim.bo.ft, treesitter_selection)

I might be mistaken, but it seems that visual_send doesn't take any arguments. Am I missing something?

echaya commented 2 months ago

Not entirely sure this is needed at repl level given searching / selecting treesitter object is a non-trivial task and can be used beyond the scope of repl. This is actually implemented neatly by motion plugins:

Some simple keymap would achieve what is requested. e..g,

vim.keymap.set(
  { "n" },
  "gt",
  function()
      vim.cmd('normal V')
      require("leap.treesitter").select()
      require("iron.core").visual_send()
      vim.cmd("norm! j")
  end,
  { desc = "send treesitter textobj" }
)

In my opinion, we could simply update the README instead of reinvent the wheel.