aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/vim/lsp/handlers.lua
diff options
context:
space:
mode:
authorEvgeni Chasnovski <evgeni.chasnovski@gmail.com>2023-10-31 14:18:44 +0200
committerGitHub <noreply@github.com>2023-10-31 13:18:44 +0100
commitadbe7f368397da21465f27181e254dd3694820e9 (patch)
treee57b7448ff156a3a0a9a3a12d31ce9605c7bbd8e /runtime/lua/vim/lsp/handlers.lua
parentc1a93285d25be8c832eceecc440e6128b773dc01 (diff)
downloadrneovim-adbe7f368397da21465f27181e254dd3694820e9.tar.gz
rneovim-adbe7f368397da21465f27181e254dd3694820e9.tar.bz2
rneovim-adbe7f368397da21465f27181e254dd3694820e9.zip
fix(lsp): call `on_list()` even for single location (#25830)
Problem: Currently there is no way of customizing behavior of `declaration`, `definition`, `typeDefinition`, and `implementation` methods in `vim.lsp.buf` when LSP server returns `Location`. Instead, cursor jumps to that location directly. Solution: Normalize LSP response to be `Location[]` for those four cases.
Diffstat (limited to 'runtime/lua/vim/lsp/handlers.lua')
-rw-r--r--runtime/lua/vim/lsp/handlers.lua31
1 files changed, 15 insertions, 16 deletions
diff --git a/runtime/lua/vim/lsp/handlers.lua b/runtime/lua/vim/lsp/handlers.lua
index d153b956ee..6fde55cf04 100644
--- a/runtime/lua/vim/lsp/handlers.lua
+++ b/runtime/lua/vim/lsp/handlers.lua
@@ -407,25 +407,24 @@ local function location_handler(_, result, ctx, config)
-- textDocument/definition can return Location or Location[]
-- https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_definition
+ if not vim.tbl_islist(result) then
+ result = { result }
+ end
- if vim.tbl_islist(result) then
- local title = 'LSP locations'
- local items = util.locations_to_items(result, client.offset_encoding)
+ local title = 'LSP locations'
+ local items = util.locations_to_items(result, client.offset_encoding)
- if config.on_list then
- assert(type(config.on_list) == 'function', 'on_list is not a function')
- config.on_list({ title = title, items = items })
- else
- if #result == 1 then
- util.jump_to_location(result[1], client.offset_encoding, config.reuse_win)
- return
- end
- vim.fn.setqflist({}, ' ', { title = title, items = items })
- api.nvim_command('botright copen')
- end
- else
- util.jump_to_location(result, client.offset_encoding, config.reuse_win)
+ if config.on_list then
+ assert(type(config.on_list) == 'function', '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
+ vim.fn.setqflist({}, ' ', { title = title, items = items })
+ api.nvim_command('botright copen')
end
--see: https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_declaration