Skip to content

Commit

Permalink
feat(lsp): new provider lsp_finder, customized combined view
Browse files Browse the repository at this point in the history
of all LSP locations, for more info see README#Default Options
under `lsp.finder`.

To accommodate the new feature LSP code was refactored and
`fzf_exec` `contents` parameter now accepts a "table of tables"
or a "table of functions" with optional prefixes which are then
merged into a single dataset.

Closes #669
  • Loading branch information
ibhagwan committed Mar 22, 2023
1 parent 37125a1 commit a81d18e
Show file tree
Hide file tree
Showing 7 changed files with 446 additions and 338 deletions.
26 changes: 25 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ vim.api.nvim_set_keymap('n', '<c-P>',
| `lsp_code_actions` | Code Actions |
| `lsp_incoming_calls` | Incoming Calls |
| `lsp_outgoing_calls` | Outgoing Calls |
| `lsp_finder` | All LSP locations, combined view |
| `diagnostics_document` | Document Diagnostics |
| `diagnostics_workspace` | Workspace Diagnostics |
| `lsp_document_diagnostics` | alias to `diagnostics_document` |
Expand Down Expand Up @@ -953,6 +954,9 @@ require'fzf-lua'.setup {
async_or_timeout = 5000, -- timeout(ms) or 'true' for async calls
file_icons = true,
git_icons = false,
-- The equivalent of using `includeDeclaration` in lsp buf calls, e.g:
-- :lua vim.lsp.buf.references({includeDeclaration = false})
includeDeclaration = true, -- include current declaration in LSP context
-- settings for 'lsp_{document|workspace|lsp_live_workspace}_symbols'
symbols = {
async_or_timeout = true, -- symbols are async by default
Expand Down Expand Up @@ -1002,13 +1006,33 @@ require'fzf-lua'.setup {
},
code_actions = {
prompt = 'Code Actions> ',
ui_select = true, -- use 'vim.ui.select'?
async_or_timeout = 5000,
winopts = {
row = 0.40,
height = 0.35,
width = 0.60,
},
},
finder = {
prompt = "LSP Finder> ",
file_icons = true,
color_icons = true,
git_icons = false,
async = true, -- async by default
silent = true, -- suppress "not found"
separator = "| ", -- separator after provider prefix, `false` to disable
includeDeclaration = true, -- include current declaration in LSP context
-- by default display all LSP locations
-- to customize, duplicate table and delete unwanted providers
providers = {
{ "references", prefix = require("fzf-lua").utils.ansi_codes.blue("ref ") },
{ "definitions", prefix = require("fzf-lua").utils.ansi_codes.green("def ") },
{ "declarations", prefix = require("fzf-lua").utils.ansi_codes.magenta("decl") },
{ "typedefs", prefix = require("fzf-lua").utils.ansi_codes.red("tdef") },
{ "implementations", prefix = require("fzf-lua").utils.ansi_codes.green("impl") },
{ "incoming_calls", prefix = require("fzf-lua").utils.ansi_codes.cyan("in ") },
{ "outgoing_calls", prefix = require("fzf-lua").utils.ansi_codes.yellow("out ") },
},
}
},
diagnostics ={
Expand Down
30 changes: 27 additions & 3 deletions doc/fzf-lua.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
*fzf-lua.txt* For Neovim >= 0.5.0 Last change: 2023 March 20
*fzf-lua.txt* For Neovim >= 0.5.0 Last change: 2023 March 21

==============================================================================
Table of Contents *fzf-lua-table-of-contents*
Expand Down Expand Up @@ -291,6 +291,7 @@ LSP/DIAGNOSTICS *fzf-lua-lsp/diagnostics*
| `lsp_code_actions` | Code Actions |
| `lsp_incoming_calls` | Incoming Calls |
| `lsp_outgoing_calls` | Outgoing Calls |
| `lsp_finder` | All LSP locations, combined view |
| `diagnostics_document` | Document Diagnostics |
| `diagnostics_workspace` | Workspace Diagnostics |
| `lsp_document_diagnostics` | alias to `diagnostics_document` |
Expand Down Expand Up @@ -1048,6 +1049,9 @@ open an issue and I'll be more than happy to help.**
async_or_timeout = 5000, -- timeout(ms) or 'true' for async calls
file_icons = true,
git_icons = false,
-- The equivalent of using `includeDeclaration` in lsp buf calls, e.g:
-- :lua vim.lsp.buf.references({includeDeclaration = false})
includeDeclaration = true, -- include current declaration in LSP context
-- settings for 'lsp_{document|workspace|lsp_live_workspace}_symbols'
symbols = {
async_or_timeout = true, -- symbols are async by default
Expand Down Expand Up @@ -1097,13 +1101,33 @@ open an issue and I'll be more than happy to help.**
},
code_actions = {
prompt = 'Code Actions> ',
ui_select = true, -- use 'vim.ui.select'?
async_or_timeout = 5000,
winopts = {
row = 0.40,
height = 0.35,
width = 0.60,
},
},
finder = {
prompt = "LSP Finder> ",
file_icons = true,
color_icons = true,
git_icons = false,
async = true, -- async by default
silent = true, -- suppress "not found"
separator = "| ", -- separator after provider prefix, `false` to disable
includeDeclaration = true, -- include current declaration in LSP context
-- by default display all LSP locations
-- to customize, duplicate table and delete unwanted providers
providers = {
{ "references", prefix = require("fzf-lua").utils.ansi_codes.blue("ref ") },
{ "definitions", prefix = require("fzf-lua").utils.ansi_codes.green("def ") },
{ "declarations", prefix = require("fzf-lua").utils.ansi_codes.magenta("decl") },
{ "typedefs", prefix = require("fzf-lua").utils.ansi_codes.red("tdef") },
{ "implementations", prefix = require("fzf-lua").utils.ansi_codes.green("impl") },
{ "incoming_calls", prefix = require("fzf-lua").utils.ansi_codes.cyan("in ") },
{ "outgoing_calls", prefix = require("fzf-lua").utils.ansi_codes.yellow("out ") },
},
}
},
diagnostics ={
Expand Down Expand Up @@ -1249,4 +1273,4 @@ I missed your name feel free to contact me and I'll add it below:
as baseline for the builtin previewer and his must have plugin nvim-bqf
<https://github.com/kevinhwang91/nvim-bqf>

vim:tw=78:ts=8:ft=help:norl:
vim:tw=78:ts=8:ft=help:norl:
60 changes: 53 additions & 7 deletions lua/fzf-lua/core.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,62 @@ local ACTION_DEFINITIONS = {
[actions.buf_del] = { fn_reload = "close", "close" },
}

-- converts contents array sent to `fzf_exec` into a single contents
-- argument with an optional prefix, currently used to combine LSP providers
local contents_from_arr = function(cont_arr)
-- must have at least one contents item in index 1
assert(cont_arr[1].contents)
local cont_type = type(cont_arr[1].contents)
local contents
if cont_type == "table" then
contents = {}
for _, t in ipairs(cont_arr) do
assert(type(t.contents) == cont_type, "Unable to combine contents of different types")
contents = utils.tbl_extend(contents, t.prefix and
vim.tbl_map(function(x)
return t.prefix .. x
end, t.contents)
or t.contents)
end
elseif cont_type == "function" then
contents = function(fzf_cb)
coroutine.wrap(function()
local co = coroutine.running()
for _, t in ipairs(cont_arr) do
assert(type(t.contents) == cont_type, "Unable to combine contents of different types")
local is_async = true
t.contents(function(entry, cb)
-- we need to hijack the EOF signal and only send it once the entire dataset
-- was sent to fzf, if the innner coroutine is different than outer, the caller's
-- callback is async and we need to yield|resume, otherwise ignore EOF
is_async = co ~= coroutine.running()
if entry then
fzf_cb(t.prefix and t.prefix .. entry or entry, cb)
elseif is_async then
coroutine.resume(co)
end
end)
-- wait for EOF if async
if is_async then
coroutine.yield()
end
end
-- done
fzf_cb()
end)()
end
elseif cont_type == "string" then
assert(false, "Not yet supported")
end
return contents
end

-- Main API, see:
-- https://github.com/ibhagwan/fzf-lua/wiki/Advanced
M.fzf_exec = function(contents, opts)
if type(contents) == "table" and type(contents[1]) == "table" then
contents = contents_from_arr(contents)
end
if not opts or not opts._normalized then
opts = config.normalize_opts(opts or {}, {})
if not opts then return end
Expand Down Expand Up @@ -659,13 +712,6 @@ M.set_header = function(opts, hdr_tbl)
return opts
end

-- NOT IN USE, here for backward compat
M.fzf_files = function(opts, contents)
utils.warn("'core.fzf_files' is deprecated, use 'fzf_exec' instead,"
.. " see github@fzf-lua/wiki/Advanced.")
M.fzf_exec(contents or opts and opts.fzf_fn and opts.fzf_fn, opts)
end

M.setup_fzf_interactive_flags = function(command, fzf_field_expression, opts)
-- query cannot be 'nil'
opts.query = opts.query or ""
Expand Down
33 changes: 32 additions & 1 deletion lua/fzf-lua/defaults.lua
Original file line number Diff line number Diff line change
Expand Up @@ -589,9 +589,40 @@ M.defaults.lsp.symbols = {
actions = { ["ctrl-g"] = { actions.sym_lsym } },
}

M.defaults.lsp.finder = {
previewer = M._default_previewer_fn,
prompt = "LSP Finder> ",
file_icons = true and M._has_devicons,
color_icons = true,
git_icons = false,
async = true,
silent = true,
separator = "| ",
_actions = function() return M.globals.actions.files end,
-- currently supported providers, defined as map so we can query easily
_providers = {
references = true,
definitions = true,
declarations = true,
typedefs = true,
implementations = true,
incoming_calls = true,
outgoing_calls = true,
},
-- by default display all supported providers
providers = {
{ "references", prefix = utils.ansi_codes.blue("ref ") },
{ "definitions", prefix = utils.ansi_codes.green("def ") },
{ "declarations", prefix = utils.ansi_codes.magenta("decl") },
{ "typedefs", prefix = utils.ansi_codes.red("tdef") },
{ "implementations", prefix = utils.ansi_codes.green("impl") },
{ "incoming_calls", prefix = utils.ansi_codes.cyan("in ") },
{ "outgoing_calls", prefix = utils.ansi_codes.yellow("out ") },
},
}

M.defaults.lsp.code_actions = {
prompt = "Code Actions> ",
ui_select = true,
async_or_timeout = 5000,
winopts = {
row = 0.40,
Expand Down
1 change: 1 addition & 0 deletions lua/fzf-lua/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ do
spell_suggest = { "fzf-lua.providers.nvim", "spell_suggest" },
filetypes = { "fzf-lua.providers.nvim", "filetypes" },
packadd = { "fzf-lua.providers.nvim", "packadd" },
lsp_finder = { "fzf-lua.providers.lsp", "finder" },
lsp_typedefs = { "fzf-lua.providers.lsp", "typedefs" },
lsp_references = { "fzf-lua.providers.lsp", "references" },
lsp_definitions = { "fzf-lua.providers.lsp", "definitions" },
Expand Down
Loading

0 comments on commit a81d18e

Please sign in to comment.