-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathfzf_lua.lua
More file actions
68 lines (59 loc) · 1.76 KB
/
Copy pathfzf_lua.lua
File metadata and controls
68 lines (59 loc) · 1.76 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
--- @class Fzflua: GoDocPicker
local M = {}
--- @param adapter GoDocAdapter
--- @param config GoDocConfig
--- @param callback fun(choice: GoDocCallbackData)
function M.show(adapter, config, callback)
local core = require("fzf-lua.core")
local builtin = require("fzf-lua.previewer.builtin")
local documentation_previewer = builtin.base:extend()
function documentation_previewer:new(o, opts, fzf_win)
documentation_previewer.super.new(self, o, opts, fzf_win)
setmetatable(self, documentation_previewer)
return self
end
---@param entry_str string
function documentation_previewer:populate_preview_buf(entry_str)
local tmpbuf = self:get_tmp_buffer()
vim.api.nvim_set_option_value("filetype", "godoc", { buf = tmpbuf })
vim.api.nvim_buf_set_lines(
tmpbuf,
0,
-1,
false,
self.opts.adapter.get_content(entry_str)
)
self:set_preview_buf(tmpbuf)
end
local opts = {
prompt = "Select item: ",
fn_transform = function() end,
debug = false,
actions = {
["default"] = function(selected, _)
callback({
type = "show_documentation",
choice = table.concat(selected, ""),
})
end,
-- TODO: fzf lua doesn't accept 'gd' as a keymap
["ctrl-s"] = function(selected, _)
callback({
type = "goto_definition",
choice = table.concat(selected, ""),
})
end,
},
adapter = adapter, -- Allow previewer to access adapter
previewer = documentation_previewer,
}
if config.picker.fzf_lua then
opts = vim.tbl_deep_extend("force", opts, config.picker.fzf_lua)
end
core.fzf_exec(adapter.get_items(), opts)
end
--- @return nil
M.goto_definition = function()
require("fzf-lua").lsp_definitions()
end
return M