-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfzf_lua.lua
More file actions
67 lines (57 loc) · 1.42 KB
/
fzf_lua.lua
File metadata and controls
67 lines (57 loc) · 1.42 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
local ext = require("peekstack.extensions")
local notify = require("peekstack.util.notify")
local M = {}
---@param selected string[]
---@param opts? table
local function push_action(selected, opts)
if not selected or not selected[1] then
return
end
local ok, fzf = pcall(require, "fzf-lua")
if not ok then
return
end
local entry = fzf.path.entry_to_file(selected[1])
if entry then
ext.push_entry({
filename = entry.path,
lnum = entry.line,
col = entry.col,
}, opts)
end
end
---@param fzf_picker string
---@param provider string
---@param opts? table
local function open_picker(fzf_picker, provider, opts)
opts = opts or {}
local ok, fzf = pcall(require, "fzf-lua")
if not ok then
notify.warn("fzf-lua not available")
return
end
local fn = fzf[fzf_picker]
if not fn then
notify.warn("fzf-lua." .. fzf_picker .. " not found")
return
end
local push_opts = { provider = provider, mode = opts.mode }
fn(vim.tbl_extend("force", opts, {
actions = {
["default"] = function(selected)
push_action(selected, push_opts)
end,
},
}))
end
function M.push_file(opts)
open_picker("files", "extension.file", opts)
end
function M.push_grep(opts)
open_picker("live_grep", "extension.grep", opts)
end
function M.push_lsp_references(opts)
open_picker("lsp_references", "extension.lsp_references", opts)
end
M.actions = { push = push_action }
return M