-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpeekstack.lua
More file actions
73 lines (67 loc) · 2.03 KB
/
peekstack.lua
File metadata and controls
73 lines (67 loc) · 2.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
local ext = require("peekstack.extensions")
local notify = require("peekstack.util.notify")
---@param entry table
---@param opts? table
local function push_from_telescope(entry, opts)
if not entry then
return
end
ext.push_entry({
filename = entry.path or entry.filename or entry.value,
lnum = entry.lnum,
col = entry.col,
}, opts)
end
---@param builtin_name string
---@param provider string
---@param opts? table
local function open_builtin(builtin_name, provider, opts)
opts = opts or {}
local builtin = require("telescope.builtin")
local fn = builtin[builtin_name]
if not fn then
notify.warn("telescope.builtin." .. builtin_name .. " not found")
return
end
local push_opts = { provider = provider, mode = opts.mode }
fn(vim.tbl_extend("force", opts, {
attach_mappings = function(_, map)
local actions = require("telescope.actions")
local state = require("telescope.actions.state")
local function on_select(prompt_bufnr)
local entry = state.get_selected_entry()
actions.close(prompt_bufnr)
push_from_telescope(entry, push_opts)
end
map("i", "<CR>", on_select)
map("n", "<CR>", on_select)
return true
end,
}))
end
--- Generic action for use in custom telescope mappings.
---@param prompt_bufnr integer
---@param opts? { provider?: string, mode?: string }
local function push_action(prompt_bufnr, opts)
local actions = require("telescope.actions")
local state = require("telescope.actions.state")
local entry = state.get_selected_entry()
actions.close(prompt_bufnr)
push_from_telescope(entry, opts)
end
return require("telescope").register_extension({
exports = {
push_file = function(opts)
open_builtin("find_files", "extension.file", opts)
end,
push_grep = function(opts)
open_builtin("live_grep", "extension.grep", opts)
end,
push_lsp_references = function(opts)
open_builtin("lsp_references", "extension.lsp_references", opts)
end,
actions = {
push = push_action,
},
},
})