how to list treesitter symbols in mini.pick #1220
-
I'm looking for alternative to |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
Apart from built-in pickers in 'mini.pick' itself, there are additional pickers in 'mini.extra'. In particular, there is a So after calling |
Beta Was this translation helpful? Give feedback.
-
I shows up like this - How to see function names without going in preview mode |
Beta Was this translation helpful? Give feedback.
-
Created picker to show given type of TS symbols and preview node text M.treesitter = function(type)
local buf_id = vim.api.nvim_get_current_buf()
local has_parser, parser = pcall(vim.treesitter.get_parser, buf_id)
if not has_parser or parser == nil then
return
end
-- Make items by traversing roots of all trees (including injections)
local items, traverse = {}, nil
traverse = function(node, depth)
if depth >= 1000 then
return
end
for child in node:iter_children() do
if child:named() then
if child:type() == type then
local lnum, col, end_lnum, end_col = child:range()
lnum, col, end_lnum, end_col = lnum + 1, col + 1, end_lnum + 1, end_col + 1
local text = vim.treesitter.get_node_text(child, buf_id)
local item = { text = text, bufnr = buf_id, lnum = lnum, col = col, end_lnum = end_lnum, end_col = end_col }
table.insert(items, item)
end
traverse(child, depth + 1)
end
end
end
parser:for_each_tree(function(ts_tree, _)
traverse(ts_tree:root(), 0)
end)
return M.pick_start(items, { source = { name = "Tree-sitter nodes" } })
end |
Beta Was this translation helpful? Give feedback.
Apart from built-in pickers in 'mini.pick' itself, there are additional pickers in 'mini.extra'. In particular, there is a
treesitter
picker.So after calling
require('mini.pick').setup()
andrequire('mini.extra').setup()
, you can execute:Pick treesitter
and then type'function
to filter nodes that contain "function" in their name.