mirror of
https://github.com/neovim/neovim.git
synced 2024-09-17 20:58:20 -04:00
Merge 210156c3c4
into 3b54adc6c6
This commit is contained in:
commit
c882aa35b6
@ -1463,13 +1463,14 @@ type_definition({opts}) *vim.lsp.buf.type_definition()*
|
||||
Parameters: ~
|
||||
• {opts} (`vim.lsp.LocationOpts?`) See |vim.lsp.LocationOpts|.
|
||||
|
||||
typehierarchy({kind}) *vim.lsp.buf.typehierarchy()*
|
||||
typehierarchy({kind}, {opts}) *vim.lsp.buf.typehierarchy()*
|
||||
Lists all the subtypes or supertypes of the symbol under the cursor in the
|
||||
|quickfix| window. If the symbol can resolve to multiple items, the user
|
||||
can pick one using |vim.ui.select()|.
|
||||
|
||||
Parameters: ~
|
||||
• {kind} (`"subtypes"|"supertypes"`)
|
||||
• {opts} (`vim.lsp.ListOpts?`) See |vim.lsp.ListOpts|.
|
||||
|
||||
workspace_symbol({query}, {opts}) *vim.lsp.buf.workspace_symbol()*
|
||||
Lists all symbols in the current workspace in the quickfix window.
|
||||
|
@ -47,6 +47,17 @@ local function request_with_opts(name, params, opts)
|
||||
request(name, params, req_handler)
|
||||
end
|
||||
|
||||
--- Calls client.request with the given `opts`.
|
||||
local function client_request_with_options(client, name, params, opts, bufnr)
|
||||
local req_handler --- @type function?
|
||||
if opts then
|
||||
req_handler = function(err, result, ctx, config)
|
||||
local handler = client.handlers[name] or vim.lsp.handlers[name]
|
||||
handler(err, result, ctx, vim.tbl_extend('force', config or {}, opts))
|
||||
end
|
||||
end
|
||||
client.request(name, params, req_handler, bufnr)
|
||||
end
|
||||
--- @class vim.lsp.ListOpts
|
||||
---
|
||||
--- list-handler replacing the default handler.
|
||||
@ -512,7 +523,8 @@ end
|
||||
--- cursor in the |quickfix| window. If the symbol can resolve to
|
||||
--- multiple items, the user can pick one using |vim.ui.select()|.
|
||||
---@param kind "subtypes"|"supertypes"
|
||||
function M.typehierarchy(kind)
|
||||
---@param opts? vim.lsp.ListOpts
|
||||
function M.typehierarchy(kind, opts)
|
||||
local method = kind == 'subtypes' and ms.typeHierarchy_subtypes or ms.typeHierarchy_supertypes
|
||||
|
||||
--- Merge results from multiple clients into a single table. Client-ID is preserved.
|
||||
@ -547,7 +559,8 @@ function M.typehierarchy(kind)
|
||||
local item = merged_results[1]
|
||||
local client = vim.lsp.get_client_by_id(item[1])
|
||||
if client then
|
||||
client.request(method, { item = item[2] }, nil, bufnr)
|
||||
--- @type lsp.TypeHierarchyItem
|
||||
client_request_with_options(client, method, { item = item[2] }, opts, bufnr)
|
||||
else
|
||||
vim.notify(
|
||||
string.format('Client with id=%d disappeared during call hierarchy request', item[1]),
|
||||
@ -570,7 +583,7 @@ function M.typehierarchy(kind)
|
||||
local client = vim.lsp.get_client_by_id(item[1])
|
||||
if client then
|
||||
--- @type lsp.TypeHierarchyItem
|
||||
client.request(method, { item = item[2] }, nil, bufnr)
|
||||
client_request_with_options(client, method, { item = item[2] }, opts, bufnr)
|
||||
else
|
||||
vim.notify(
|
||||
string.format('Client with id=%d disappeared during call hierarchy request', item[1]),
|
||||
|
@ -573,7 +573,7 @@ M[ms.callHierarchy_outgoingCalls] = make_call_hierarchy_handler('to')
|
||||
--- Displays type hierarchy in the quickfix window.
|
||||
local function make_type_hierarchy_handler()
|
||||
--- @param result lsp.TypeHierarchyItem[]
|
||||
return function(_, result, ctx, _)
|
||||
return function(_, result, ctx, config)
|
||||
if not result then
|
||||
return
|
||||
end
|
||||
@ -598,8 +598,19 @@ local function make_type_hierarchy_handler()
|
||||
col = col + 1,
|
||||
})
|
||||
end
|
||||
vim.fn.setqflist({}, ' ', { title = 'LSP type hierarchy', items = items })
|
||||
vim.cmd('botright copen')
|
||||
config = config or {}
|
||||
local list = { title = 'LSP type hierarchy', items = items, context = ctx }
|
||||
|
||||
if config.loclist then
|
||||
vim.fn.setloclist(0, {}, ' ', list)
|
||||
vim.cmd.lopen()
|
||||
elseif config.on_list then
|
||||
assert(vim.is_callable(config.on_list), 'on_list is not a function')
|
||||
config.on_list(list)
|
||||
else
|
||||
vim.fn.setqflist({}, ' ', list)
|
||||
vim.cmd.copen({ mods = { split = 'botright' } })
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -3725,6 +3725,92 @@ describe('LSP', function()
|
||||
eq(expected, qflist)
|
||||
end)
|
||||
|
||||
it('Opens the loclist if config contains `loclist`', function()
|
||||
exec_lua(create_server_definition)
|
||||
local loclist = exec_lua([=[
|
||||
local response = { {
|
||||
name = "foo",
|
||||
range = {
|
||||
["end"] = {
|
||||
character = 8,
|
||||
line = 9
|
||||
},
|
||||
start = {
|
||||
character = 6,
|
||||
line = 9
|
||||
}
|
||||
},
|
||||
uri = "file://foo.cpp"
|
||||
}}
|
||||
|
||||
local server = _create_server({
|
||||
capabilities = {
|
||||
positionEncoding = "utf-8"
|
||||
},
|
||||
})
|
||||
local client_id = vim.lsp.start({ name = 'dummy', cmd = server.cmd })
|
||||
local handler = require'vim.lsp.handlers'['typeHierarchy/subtypes']
|
||||
handler(nil, response, { client_id = client_id, bufnr = 1 }, { loclist = true })
|
||||
return vim.fn.getloclist(0)
|
||||
]=])
|
||||
|
||||
eq({
|
||||
{
|
||||
bufnr = 2,
|
||||
col = 7,
|
||||
end_col = 0,
|
||||
end_lnum = 0,
|
||||
lnum = 10,
|
||||
module = '',
|
||||
nr = 0,
|
||||
pattern = '',
|
||||
text = 'foo',
|
||||
type = '',
|
||||
valid = 1,
|
||||
vcol = 0,
|
||||
},
|
||||
}, loclist)
|
||||
end)
|
||||
|
||||
it('Calls on_list if given', function()
|
||||
exec_lua(create_server_definition)
|
||||
local items = exec_lua([=[
|
||||
local response = { {
|
||||
name = "foo",
|
||||
range = {
|
||||
["end"] = {
|
||||
character = 8,
|
||||
line = 9
|
||||
},
|
||||
start = {
|
||||
character = 6,
|
||||
line = 9
|
||||
}
|
||||
},
|
||||
uri = "file://foo.cpp"
|
||||
}}
|
||||
|
||||
local server = _create_server({
|
||||
capabilities = {
|
||||
positionEncoding = "utf-8"
|
||||
},
|
||||
})
|
||||
local client_id = vim.lsp.start({ name = 'dummy', cmd = server.cmd })
|
||||
local handler = require'vim.lsp.handlers'['typeHierarchy/subtypes']
|
||||
local items
|
||||
handler(nil, response, { client_id = client_id, bufnr = 1 }, { on_list = function(list) items = list.items end })
|
||||
return items
|
||||
]=])
|
||||
|
||||
eq({
|
||||
{
|
||||
filename = '/foo.cpp',
|
||||
text = 'foo',
|
||||
lnum = 10,
|
||||
col = 7,
|
||||
},
|
||||
}, items)
|
||||
end)
|
||||
it('opens the quickfix list with the right subtypes and details', function()
|
||||
clear()
|
||||
exec_lua(create_server_definition)
|
||||
|
Loading…
Reference in New Issue
Block a user