Skip to content

Commit 1631dd5

Browse files
committed
feat(lsp): added type type hierarchy pickers
closes #2379
1 parent fb654cb commit 1631dd5

6 files changed

Lines changed: 60 additions & 19 deletions

File tree

OPTIONS.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1068,6 +1068,14 @@ LSP Incoming Calls
10681068

10691069
LSP Outgoing Calls
10701070

1071+
#### lsp_type_sub
1072+
1073+
LSP Sub types
1074+
1075+
#### lsp_type_super
1076+
1077+
LSP Super types
1078+
10711079
#### lsp_code_actions
10721080

10731081
LSP Code Actions

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,8 @@ Fzf-Lua conveniently comes with a VS-Code like picker by default
286286
| `lsp_live_workspace_symbols` | Workspace Symbols (live query) |
287287
| `lsp_incoming_calls` | Incoming Calls |
288288
| `lsp_outgoing_calls` | Outgoing Calls |
289+
| `lsp_type_sub` | Sub Types |
290+
| `lsp_type_super` | Super Types |
289291
| `lsp_code_actions` | Code Actions |
290292
| `lsp_finder` | All LSP locations, combined view |
291293
| `diagnostics_document` | Document Diagnostics |
@@ -1296,6 +1298,8 @@ previewers = {
12961298
{ "implementations", prefix = FzfLua.utils.ansi_codes.green("impl") },
12971299
{ "incoming_calls", prefix = FzfLua.utils.ansi_codes.cyan("in ") },
12981300
{ "outgoing_calls", prefix = FzfLua.utils.ansi_codes.yellow("out ") },
1301+
{ "type_sub", prefix = FzfLua.utils.utils.ansi_codes.cyan("sub ") },
1302+
{ "type_super", prefix = FzfLua.utils.utils.ansi_codes.yellow("supr") },
12991303
},
13001304
}
13011305
},

doc/fzf-lua-opts.txt

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*fzf-lua-opts.txt* For Neovim >= 0.8.0 Last change: 2025 September 22
1+
*fzf-lua-opts.txt* For Neovim >= 0.8.0 Last change: 2025 October 02
22

33
==============================================================================
44
Table of Contents *fzf-lua-opts-table-of-contents*
@@ -1464,6 +1464,18 @@ LSP Outgoing Calls
14641464

14651465

14661466

1467+
lsp_type_sub *fzf-lua-opts-lsp_type_sub*
1468+
1469+
LSP Sub types
1470+
1471+
1472+
1473+
lsp_type_super *fzf-lua-opts-lsp_type_super*
1474+
1475+
LSP Super types
1476+
1477+
1478+
14671479
lsp_code_actions *fzf-lua-opts-lsp_code_actions*
14681480

14691481
LSP Code Actions

lua/fzf-lua/defaults.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1119,6 +1119,8 @@ M.defaults.lsp.finder = {
11191119
implementations = true,
11201120
incoming_calls = true,
11211121
outgoing_calls = true,
1122+
type_sub = true,
1123+
type_super = true,
11221124
},
11231125
-- by default display all supported providers
11241126
providers = {
@@ -1129,6 +1131,8 @@ M.defaults.lsp.finder = {
11291131
{ "references", prefix = utils.ansi_codes.blue("ref ") },
11301132
{ "incoming_calls", prefix = utils.ansi_codes.cyan("in ") },
11311133
{ "outgoing_calls", prefix = utils.ansi_codes.yellow("out ") },
1134+
{ "type_sub", prefix = utils.ansi_codes.cyan("sub ") },
1135+
{ "type_super", prefix = utils.ansi_codes.yellow("supr") },
11321136
},
11331137
fzf_opts = { ["--multi"] = true },
11341138
_treesitter = true,

lua/fzf-lua/init.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,8 @@ local lazyloaded_modules = {
314314
lsp_code_actions = { "fzf-lua.providers.lsp", "code_actions" },
315315
lsp_incoming_calls = { "fzf-lua.providers.lsp", "incoming_calls" },
316316
lsp_outgoing_calls = { "fzf-lua.providers.lsp", "outgoing_calls" },
317+
lsp_type_sub = { "fzf-lua.providers.lsp", "type_sub" },
318+
lsp_type_super = { "fzf-lua.providers.lsp", "type_super" },
317319
lsp_document_diagnostics = { "fzf-lua.providers.diagnostic", "diagnostics" },
318320
lsp_workspace_diagnostics = { "fzf-lua.providers.diagnostic", "all" },
319321
diagnostics_document = { "fzf-lua.providers.diagnostic", "diagnostics" },

lua/fzf-lua/providers/lsp.lua

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -308,71 +308,72 @@ end
308308
local handlers = {
309309
["code_actions"] = {
310310
label = "Code Actions",
311-
server_capability = "codeActionProvider",
312311
method = "textDocument/codeAction",
313312
},
314313
["references"] = {
315314
label = "References",
316-
server_capability = "referencesProvider",
317315
method = "textDocument/references",
318316
handler = location_handler
319317
},
320318
["definitions"] = {
321319
label = "Definitions",
322-
server_capability = "definitionProvider",
323320
method = "textDocument/definition",
324321
handler = location_handler
325322
},
326323
["declarations"] = {
327324
label = "Declarations",
328-
server_capability = "declarationProvider",
329325
method = "textDocument/declaration",
330326
handler = location_handler
331327
},
332328
["typedefs"] = {
333329
label = "Type Definitions",
334-
server_capability = "typeDefinitionProvider",
335330
method = "textDocument/typeDefinition",
336331
handler = location_handler
337332
},
338333
["implementations"] = {
339334
label = "Implementations",
340-
server_capability = "implementationProvider",
341335
method = "textDocument/implementation",
342336
handler = location_handler
343337
},
344338
["document_symbols"] = {
345339
label = "Document Symbols",
346-
server_capability = "documentSymbolProvider",
347340
method = "textDocument/documentSymbol",
348341
handler = symbol_handler
349342
},
350343
["workspace_symbols"] = {
351344
label = "Workspace Symbols",
352-
server_capability = "workspaceSymbolProvider",
353345
method = "workspace/symbol",
354346
handler = symbol_handler
355347
},
356348
["live_workspace_symbols"] = {
357349
label = "Workspace Symbols",
358-
server_capability = "workspaceSymbolProvider",
359350
method = "workspace/symbol",
360351
handler = symbol_handler
361352
},
362353
["incoming_calls"] = {
363354
label = "Incoming Calls",
364-
server_capability = "callHierarchyProvider",
365355
method = "callHierarchy/incomingCalls",
366356
prep = "textDocument/prepareCallHierarchy",
367357
handler = call_hierarchy_handler
368358
},
369359
["outgoing_calls"] = {
370360
label = "Outgoing Calls",
371-
server_capability = "callHierarchyProvider",
372361
method = "callHierarchy/outgoingCalls",
373362
prep = "textDocument/prepareCallHierarchy",
374363
handler = call_hierarchy_handler
375364
},
365+
["type_sub"] = {
366+
label = "TypeHierarchy Sub",
367+
method = "typeHierarchy/subtypes",
368+
prep = "textDocument/prepareTypeHierarchy",
369+
handler = location_handler
370+
},
371+
["type_super"] = {
372+
label = "TypeHierarchy Super",
373+
method = "typeHierarchy/supertypes",
374+
prep = "textDocument/prepareTypeHierarchy",
375+
handler = location_handler
376+
},
376377
}
377378

378379
local function gen_lsp_contents(opts)
@@ -577,7 +578,7 @@ local function gen_lsp_contents(opts)
577578
end
578579

579580
-- see $VIMRUNTIME/lua/vim/buf.lua:pick_call_hierarchy_item()
580-
local function gen_lsp_contents_call_hierarchy(opts)
581+
local function gen_lsp_contents_hierarchy(opts)
581582
local timeout = 5000
582583
if type(opts.async_or_timeout) == "number" then
583584
timeout = opts.async_or_timeout
@@ -663,11 +664,19 @@ M.implementations = function(opts)
663664
end
664665

665666
M.incoming_calls = function(opts)
666-
return fzf_lsp_locations(opts, gen_lsp_contents_call_hierarchy)
667+
return fzf_lsp_locations(opts, gen_lsp_contents_hierarchy)
667668
end
668669

669670
M.outgoing_calls = function(opts)
670-
return fzf_lsp_locations(opts, gen_lsp_contents_call_hierarchy)
671+
return fzf_lsp_locations(opts, gen_lsp_contents_hierarchy)
672+
end
673+
674+
M.type_sub = function(opts)
675+
return fzf_lsp_locations(opts, gen_lsp_contents_hierarchy)
676+
end
677+
678+
M.type_super = function(opts)
679+
return fzf_lsp_locations(opts, gen_lsp_contents_hierarchy)
671680
end
672681

673682
M.finder = function(opts)
@@ -684,7 +693,6 @@ M.finder = function(opts)
684693
opts.silent = opts.silent == nil and true or opts.silent
685694
opts.no_autoclose = true
686695
opts.lsp_handler = handlers[method]
687-
opts.lsp_handler.capability = opts.lsp_handler.server_capability
688696
opts.lsp_params = lsp_params -- reset previous calls params if existed
689697

690698
-- returns nil for no client attached, false for unsupported capability
@@ -695,8 +703,12 @@ M.finder = function(opts)
695703
return
696704
elseif check then
697705
local _, c = (function()
698-
if method == "incoming_calls" or method == "outgoing_calls" then
699-
return gen_lsp_contents_call_hierarchy(opts)
706+
if method == "incoming_calls"
707+
or method == "outgoing_calls"
708+
or method == "type_sub"
709+
or method == "type_super"
710+
then
711+
return gen_lsp_contents_hierarchy(opts)
700712
else
701713
return gen_lsp_contents(opts)
702714
end
@@ -899,7 +911,6 @@ local function wrap_fn(key, fn)
899911
return function(opts)
900912
opts = opts or {}
901913
opts.lsp_handler = handlers[key]
902-
opts.lsp_handler.capability = opts.lsp_handler.server_capability
903914

904915
-- check_capabilities will print the appropriate warning
905916
if not check_capabilities(opts.lsp_handler, opts.silent) then

0 commit comments

Comments
 (0)