feat(lsp): support requests to many servers for some pickers (#3211)

* Implement list_or_jump_all and use it

* Update lua/telescope/builtin/__lsp.lua

Co-authored-by: James Trew <66286082+jamestrew@users.noreply.github.com>

* Make list_or_jump listen to multiple lsps at once

* Don't fail early if an lsp errors

---------

Co-authored-by: James Trew <66286082+jamestrew@users.noreply.github.com>
This commit is contained in:
Enric Lluelles
2024-08-02 03:12:41 +02:00
committed by GitHub
parent 10b8a82b04
commit 3b1600d0fd

View File

@@ -177,24 +177,40 @@ local function list_or_jump(action, title, funname, params, opts)
opts.reuse_win = vim.F.if_nil(opts.reuse_win, false) opts.reuse_win = vim.F.if_nil(opts.reuse_win, false)
opts.curr_filepath = vim.api.nvim_buf_get_name(opts.bufnr) opts.curr_filepath = vim.api.nvim_buf_get_name(opts.bufnr)
vim.lsp.buf_request(opts.bufnr, action, params, function(err, result, ctx, _) vim.lsp.buf_request_all(opts.bufnr, action, params, function(results_per_client)
if err then local items = {}
vim.api.nvim_err_writeln("Error when executing " .. action .. " : " .. err.message) local first_encoding
return local errors = {}
end
if result == nil then
return
end
for client_id, result_or_error in pairs(results_per_client) do
local error, result = result_or_error.error, result_or_error.result
if error then
errors[client_id] = error
else
if result ~= nil then
local locations = {} local locations = {}
if not utils.islist(result) then
locations = { result }
end
vim.list_extend(locations, result)
local offset_encoding = vim.lsp.get_client_by_id(ctx.client_id).offset_encoding if not utils.islist(result) then
local items = vim.lsp.util.locations_to_items(locations, offset_encoding) vim.list_extend(locations, { result })
else
vim.list_extend(locations, result)
end
local offset_encoding = vim.lsp.get_client_by_id(client_id).offset_encoding
if not vim.tbl_isempty(result) then
first_encoding = offset_encoding
end
vim.list_extend(items, vim.lsp.util.locations_to_items(locations, offset_encoding))
end
end
end
for _, error in pairs(errors) do
vim.api.nvim_err_writeln("Error when executing " .. action .. " : " .. error.message)
end
items = apply_action_handler(action, items, opts) items = apply_action_handler(action, items, opts)
items = filter_file_ignore_patters(items, opts) items = filter_file_ignore_patters(items, opts)
@@ -225,8 +241,8 @@ local function list_or_jump(action, title, funname, params, opts)
end end
end end
local location = item_to_location(item, offset_encoding) local location = item_to_location(item, first_encoding)
vim.lsp.util.jump_to_location(location, offset_encoding, opts.reuse_win) vim.lsp.util.jump_to_location(location, first_encoding, opts.reuse_win)
else else
pickers pickers
.new(opts, { .new(opts, {