mirror of
https://github.com/neovim/neovim.git
synced 2025-10-21 09:12:07 +00:00
feat(lsp)!: support multiple clients in goto methods (#30877)
Relates to: - https://github.com/neovim/neovim/issues/30034 - https://github.com/neovim/neovim/issues/17712 - https://github.com/neovim/neovim/issues/16363 Closes: - https://github.com/neovim/neovim/issues/26936 (but only provides bufnr and method) - https://github.com/neovim/neovim/issues/22318 Might fix: https://github.com/neovim/neovim/issues/30737
This commit is contained in:

committed by
GitHub

parent
9b8907d905
commit
0083e03d6f
@@ -386,57 +386,6 @@ end
|
||||
--- @see # https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_hover
|
||||
M[ms.textDocument_hover] = M.hover
|
||||
|
||||
--- Jumps to a location. Used as a handler for multiple LSP methods.
|
||||
---@param _ nil not used
|
||||
---@param result (table) result of LSP method; a location or a list of locations.
|
||||
---@param ctx (lsp.HandlerContext) table containing the context of the request, including the method
|
||||
---@param config? vim.lsp.LocationOpts
|
||||
---(`textDocument/definition` can return `Location` or `Location[]`
|
||||
local function location_handler(_, result, ctx, config)
|
||||
if result == nil or vim.tbl_isempty(result) then
|
||||
log.info(ctx.method, 'No location found')
|
||||
return nil
|
||||
end
|
||||
local client = assert(vim.lsp.get_client_by_id(ctx.client_id))
|
||||
|
||||
config = config or {}
|
||||
|
||||
-- textDocument/definition can return Location or Location[]
|
||||
-- https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_definition
|
||||
if not vim.islist(result) then
|
||||
result = { result }
|
||||
end
|
||||
|
||||
local title = 'LSP locations'
|
||||
local items = util.locations_to_items(result, client.offset_encoding)
|
||||
|
||||
if config.on_list then
|
||||
assert(vim.is_callable(config.on_list), 'on_list is not a function')
|
||||
config.on_list({ title = title, items = items })
|
||||
return
|
||||
end
|
||||
if #result == 1 then
|
||||
util.jump_to_location(result[1], client.offset_encoding, config.reuse_win)
|
||||
return
|
||||
end
|
||||
if config.loclist then
|
||||
vim.fn.setloclist(0, {}, ' ', { title = title, items = items })
|
||||
vim.cmd.lopen()
|
||||
else
|
||||
vim.fn.setqflist({}, ' ', { title = title, items = items })
|
||||
vim.cmd('botright copen')
|
||||
end
|
||||
end
|
||||
|
||||
--- @see # https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_declaration
|
||||
M[ms.textDocument_declaration] = location_handler
|
||||
--- @see # https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_definition
|
||||
M[ms.textDocument_definition] = location_handler
|
||||
--- @see # https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_typeDefinition
|
||||
M[ms.textDocument_typeDefinition] = location_handler
|
||||
--- @see # https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_implementation
|
||||
M[ms.textDocument_implementation] = location_handler
|
||||
|
||||
local sig_help_ns = api.nvim_create_namespace('vim_lsp_signature_help')
|
||||
|
||||
--- |lsp-handler| for the method "textDocument/signatureHelp".
|
||||
|
Reference in New Issue
Block a user