diff options
author | rhcher <kaer41@qq.com> | 2022-08-04 03:44:33 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-03 21:44:33 +0200 |
commit | 7c997dbc5db145ccfa3c4d687b85168819c8b7d2 (patch) | |
tree | 7a88fc3943ad007d7c09b4ca342e229335f6829b /runtime/lua/vim/lsp/handlers.lua | |
parent | 43cd91a4f4276da2b9cb231032ca63e47e7f32a2 (diff) | |
download | rneovim-7c997dbc5db145ccfa3c4d687b85168819c8b7d2.tar.gz rneovim-7c997dbc5db145ccfa3c4d687b85168819c8b7d2.tar.bz2 rneovim-7c997dbc5db145ccfa3c4d687b85168819c8b7d2.zip |
fix(lsp): prevent unexpected position jumps (#19370)
Diffstat (limited to 'runtime/lua/vim/lsp/handlers.lua')
-rw-r--r-- | runtime/lua/vim/lsp/handlers.lua | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/runtime/lua/vim/lsp/handlers.lua b/runtime/lua/vim/lsp/handlers.lua index 1e6ac8dddf..624436bc9b 100644 --- a/runtime/lua/vim/lsp/handlers.lua +++ b/runtime/lua/vim/lsp/handlers.lua @@ -348,19 +348,19 @@ local function location_handler(_, result, ctx, config) -- https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_definition if vim.tbl_islist(result) then - util.jump_to_location(result[1], client.offset_encoding, config.reuse_win) - - if #result > 1 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 - vim.fn.setqflist({}, ' ', { title = title, items = items }) - api.nvim_command('botright copen') + 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) |