diff options
author | Josh Rahm <joshuarahm@gmail.com> | 2022-08-03 00:08:17 -0600 |
---|---|---|
committer | Josh Rahm <joshuarahm@gmail.com> | 2022-08-03 00:08:17 -0600 |
commit | 9449e1b8d273ff78eb894c588110ffa0c17d6ee3 (patch) | |
tree | 9e4470c33bd4187d9f42f0b2c4aaa995310c5be8 /runtime/lua/vim/lsp/handlers.lua | |
parent | 308e1940dcd64aa6c344c403d4f9e0dda58d9c5c (diff) | |
parent | b8dcbcc732baf84fc48d6b272c3ade0bcb129b3b (diff) | |
download | rneovim-9449e1b8d273ff78eb894c588110ffa0c17d6ee3.tar.gz rneovim-9449e1b8d273ff78eb894c588110ffa0c17d6ee3.tar.bz2 rneovim-9449e1b8d273ff78eb894c588110ffa0c17d6ee3.zip |
Merge remote-tracking branch 'upstream/master' into rahm
Diffstat (limited to 'runtime/lua/vim/lsp/handlers.lua')
-rw-r--r-- | runtime/lua/vim/lsp/handlers.lua | 52 |
1 files changed, 27 insertions, 25 deletions
diff --git a/runtime/lua/vim/lsp/handlers.lua b/runtime/lua/vim/lsp/handlers.lua index 3b869d8f5c..1e6ac8dddf 100644 --- a/runtime/lua/vim/lsp/handlers.lua +++ b/runtime/lua/vim/lsp/handlers.lua @@ -189,19 +189,17 @@ M['textDocument/references'] = function(_, result, ctx, config) else local client = vim.lsp.get_client_by_id(ctx.client_id) config = config or {} + local title = 'References' + local items = util.locations_to_items(result, client.offset_encoding) + if config.loclist then - vim.fn.setloclist(0, {}, ' ', { - title = 'References', - items = util.locations_to_items(result, client.offset_encoding), - context = ctx, - }) + vim.fn.setloclist(0, {}, ' ', { title = title, items = items, context = ctx }) api.nvim_command('lopen') + elseif config.on_list then + assert(type(config.on_list) == 'function', 'on_list is not a function') + config.on_list({ title = title, items = items, context = ctx }) else - vim.fn.setqflist({}, ' ', { - title = 'References', - items = util.locations_to_items(result, client.offset_encoding), - context = ctx, - }) + vim.fn.setqflist({}, ' ', { title = title, items = items, context = ctx }) api.nvim_command('botright copen') end end @@ -224,19 +222,17 @@ local function response_to_list(map_result, entity, title_fn) vim.notify('No ' .. entity .. ' found') else config = config or {} + local title = title_fn(ctx) + local items = map_result(result, ctx.bufnr) + if config.loclist then - vim.fn.setloclist(0, {}, ' ', { - title = title_fn(ctx), - items = map_result(result, ctx.bufnr), - context = ctx, - }) + vim.fn.setloclist(0, {}, ' ', { title = title, items = items, context = ctx }) api.nvim_command('lopen') + elseif config.on_list then + assert(type(config.on_list) == 'function', 'on_list is not a function') + config.on_list({ title = title, items = items, context = ctx }) else - vim.fn.setqflist({}, ' ', { - title = title_fn(ctx), - items = map_result(result, ctx.bufnr), - context = ctx, - }) + vim.fn.setqflist({}, ' ', { title = title, items = items, context = ctx }) api.nvim_command('botright copen') end end @@ -261,6 +257,7 @@ end) --see: https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_rename M['textDocument/rename'] = function(_, result, ctx, _) if not result then + vim.notify("Language server couldn't provide rename result", vim.log.levels.INFO) return end local client = vim.lsp.get_client_by_id(ctx.client_id) @@ -354,11 +351,16 @@ local function location_handler(_, result, ctx, config) util.jump_to_location(result[1], client.offset_encoding, config.reuse_win) if #result > 1 then - vim.fn.setqflist({}, ' ', { - title = 'LSP locations', - items = util.locations_to_items(result, client.offset_encoding), - }) - api.nvim_command('botright copen') + 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') + end end else util.jump_to_location(result, client.offset_encoding, config.reuse_win) |