Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Treesitter textobjects #210

Open
timoleistner opened this issue Mar 18, 2022 · 4 comments
Open

Add support for Treesitter textobjects #210

timoleistner opened this issue Mar 18, 2022 · 4 comments

Comments

@timoleistner
Copy link

timoleistner commented Mar 18, 2022

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
Copy link
Collaborator

hkupty commented Mar 21, 2022

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

@hkupty hkupty added this to the 3.2 - Features milestone May 18, 2022
@f3fora
Copy link
Contributor

f3fora commented Jun 24, 2023

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
Copy link

makp commented May 24, 2024

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
Copy link

echaya commented Aug 16, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants