|
1 | | ----@class fle.config.Function: fzf-lua.config.Base |
2 | | -local __DEFAULT__ = {} |
3 | | - |
4 | | -local getfunc = function(s) |
| 1 | +local funcinfo = function(s) |
5 | 2 | if not s then return end |
6 | 3 | ---@type string? |
7 | 4 | local name = s:match('function (.*)%(') |
8 | 5 | if not name then return end |
9 | | - local content = vim.split(vim.api.nvim_exec2('function ' .. name, { output = true }).output, '\n') |
10 | | - if not content[1] then return end |
11 | | - local skip_col = #content[1]:match('(.*)function') |
12 | | - local new_content = vim |
13 | | - .iter(content) |
14 | | - :map(function(line) return line:sub(skip_col + 1) end) |
15 | | - :totable() |
16 | | - return name, new_content |
| 6 | + local content = |
| 7 | + vim.split(vim.api.nvim_exec2('verb function ' .. name, { output = true }).output, '\n') |
| 8 | + if not content[1] or not content[2] then return end |
| 9 | + local path, lnum = content[2]:match('Last set from (.*) line (%d+)') |
| 10 | + return path and vim.fs.normalize(path) or nil, tonumber(lnum) |
17 | 11 | end |
18 | 12 |
|
19 | | ----@param _self fzf-lua.previewer.Builtin |
20 | | ----@param content string[] |
21 | | -local preview_with = vim.schedule_wrap(function(_self, content) |
22 | | - local tmpbuf = _self:get_tmp_buffer() |
23 | | - vim.api.nvim_buf_set_lines(tmpbuf, 0, -1, false, content) |
24 | | - ---@diagnostic disable-next-line: undefined-field |
25 | | - if _self.filetype then vim.bo[tmpbuf].filetype = _self.filetype end |
26 | | - _self:set_preview_buf(tmpbuf) |
27 | | - _self.win:update_preview_scrollbar() |
28 | | -end) |
| 13 | +local format = function(e) return ('%s:%s:'):format(funcinfo(e)) end |
29 | 14 |
|
30 | | -return function(opts) |
31 | | - assert(__DEFAULT__) |
32 | | - opts = opts or {} |
33 | | - opts._treesitter = function(line) return 'foo.vim', nil, line end |
34 | | - opts.actions = { |
35 | | - enter = { |
36 | | - fn = function(sel) |
37 | | - local name, content = getfunc(sel[1]) |
38 | | - if not name or not content then return end |
39 | | - vim.cmd.tabnew() |
40 | | - vim.bo.ft = 'vim' |
41 | | - vim.api.nvim_buf_set_lines(vim.api.nvim_get_current_buf(), 0, -1, false, content) |
42 | | - end, |
43 | | - }, |
44 | | - } |
45 | | - -- opts.preview = { |
46 | | - -- fn = function(sel) |
47 | | - -- local name = d(sel[1]) |
48 | | - -- if not name then return end |
49 | | - -- return vim.api.nvim_exec2('function ' .. name, { output = true }).output |
50 | | - -- end, |
51 | | - -- } |
52 | | - opts.previewer = { |
| 15 | +---@class fle.config.Function: fzf-lua.config.Base |
| 16 | +local __DEFAULT__ = { |
| 17 | + _treesitter = function(line) return 'foo.vim', nil, line end, |
| 18 | + fzf_colors = { ['hl'] = '-1:reverse', ['hl+'] = '-1:reverse' }, |
| 19 | + _actions = function() return require('fzf-lua-extra.utils').fix_actions(format) end, |
| 20 | + previewer = { |
53 | 21 | _ctor = function() |
54 | 22 | local p = require('fzf-lua.previewer.builtin').buffer_or_file:extend() |
55 | | - function p:populate_preview_buf(sel) |
56 | | - local name, content = getfunc(sel) |
57 | | - if not name or not content then return end |
58 | | - self.filetype = 'vim' |
59 | | - preview_with(self, content) |
| 23 | + function p:parse_entry(sel) |
| 24 | + local path, lnum = funcinfo(sel) |
| 25 | + return { path = path, line = lnum } |
60 | 26 | end |
61 | 27 | return p |
62 | 28 | end, |
63 | | - } |
| 29 | + }, |
| 30 | +} |
64 | 31 |
|
65 | | - opts.fzf_colors = { ['hl'] = '-1:reverse', ['hl+'] = '-1:reverse' } |
| 32 | +return function(opts) |
| 33 | + assert(__DEFAULT__) |
66 | 34 | FzfLua.fzf_exec(vim.split(vim.api.nvim_exec2('function', { output = true }).output, '\n'), opts) |
67 | 35 | end |
0 commit comments