fix: make lsp_* async (#1506)
This commit is contained in:
@@ -16,17 +16,15 @@ lsp.references = function(opts)
|
||||
local params = vim.lsp.util.make_position_params()
|
||||
params.context = { includeDeclaration = true }
|
||||
|
||||
local results_lsp, err = vim.lsp.buf_request_sync(0, "textDocument/references", params, opts.timeout or 10000)
|
||||
vim.lsp.buf_request(0, "textDocument/references", params, function(err, result, _ctx, _config)
|
||||
if err then
|
||||
vim.api.nvim_err_writeln("Error when finding references: " .. err)
|
||||
return
|
||||
end
|
||||
|
||||
local locations = {}
|
||||
for _, server_results in pairs(results_lsp) do
|
||||
if server_results.result then
|
||||
vim.list_extend(locations, vim.lsp.util.locations_to_items(server_results.result) or {})
|
||||
end
|
||||
if result then
|
||||
vim.list_extend(locations, vim.lsp.util.locations_to_items(result) or {})
|
||||
end
|
||||
|
||||
if vim.tbl_isempty(locations) then
|
||||
@@ -42,28 +40,26 @@ lsp.references = function(opts)
|
||||
previewer = conf.qflist_previewer(opts),
|
||||
sorter = conf.generic_sorter(opts),
|
||||
}):find()
|
||||
end)
|
||||
end
|
||||
|
||||
local function list_or_jump(action, title, opts)
|
||||
opts = opts or {}
|
||||
|
||||
local params = vim.lsp.util.make_position_params()
|
||||
local result, err = vim.lsp.buf_request_sync(0, action, params, opts.timeout or 10000)
|
||||
vim.lsp.buf_request(0, action, params, function(err, result, _ctx, _config)
|
||||
if err then
|
||||
vim.api.nvim_err_writeln("Error when executing " .. action .. " : " .. err)
|
||||
return
|
||||
end
|
||||
local flattened_results = {}
|
||||
for _, server_results in pairs(result) do
|
||||
if server_results.result then
|
||||
if result then
|
||||
-- textDocument/definition can return Location or Location[]
|
||||
if not vim.tbl_islist(server_results.result) then
|
||||
flattened_results = { server_results.result }
|
||||
break
|
||||
if not vim.tbl_islist(result) then
|
||||
flattened_results = { result }
|
||||
end
|
||||
|
||||
vim.list_extend(flattened_results, server_results.result)
|
||||
end
|
||||
vim.list_extend(flattened_results, result)
|
||||
end
|
||||
|
||||
if #flattened_results == 0 then
|
||||
@@ -89,6 +85,7 @@ local function list_or_jump(action, title, opts)
|
||||
sorter = conf.generic_sorter(opts),
|
||||
}):find()
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
lsp.definitions = function(opts)
|
||||
@@ -105,21 +102,19 @@ end
|
||||
|
||||
lsp.document_symbols = function(opts)
|
||||
local params = vim.lsp.util.make_position_params()
|
||||
local results_lsp, err = vim.lsp.buf_request_sync(0, "textDocument/documentSymbol", params, opts.timeout or 10000)
|
||||
vim.lsp.buf_request(0, "textDocument/documentSymbol", params, function(err, result, _ctx, _config)
|
||||
if err then
|
||||
vim.api.nvim_err_writeln("Error when finding document symbols: " .. err)
|
||||
return
|
||||
end
|
||||
|
||||
if not results_lsp or vim.tbl_isempty(results_lsp) then
|
||||
if not result or vim.tbl_isempty(result) then
|
||||
print "No results from textDocument/documentSymbol"
|
||||
return
|
||||
end
|
||||
|
||||
local locations = {}
|
||||
for _, server_results in pairs(results_lsp) do
|
||||
vim.list_extend(locations, vim.lsp.util.symbols_to_items(server_results.result, 0) or {})
|
||||
end
|
||||
vim.list_extend(locations, vim.lsp.util.symbols_to_items(result, 0) or {})
|
||||
|
||||
locations = utils.filter_symbols(locations, opts)
|
||||
if locations == nil then
|
||||
@@ -144,6 +139,7 @@ lsp.document_symbols = function(opts)
|
||||
sorter = conf.generic_sorter(opts),
|
||||
},
|
||||
}):find()
|
||||
end)
|
||||
end
|
||||
|
||||
lsp.code_actions = function(opts)
|
||||
@@ -337,7 +333,7 @@ end
|
||||
|
||||
lsp.workspace_symbols = function(opts)
|
||||
local params = { query = opts.query or "" }
|
||||
local results_lsp, err = vim.lsp.buf_request_sync(0, "workspace/symbol", params, opts.timeout or 10000)
|
||||
vim.lsp.buf_request(0, "workspace/symbol", params, function(err, server_result, _ctx, _config)
|
||||
if err then
|
||||
vim.api.nvim_err_writeln("Error when finding workspace symbols: " .. err)
|
||||
return
|
||||
@@ -345,12 +341,10 @@ lsp.workspace_symbols = function(opts)
|
||||
|
||||
local locations = {}
|
||||
|
||||
if results_lsp and not vim.tbl_isempty(results_lsp) then
|
||||
for _, server_results in pairs(results_lsp) do
|
||||
if server_result and not vim.tbl_isempty(server_result) then
|
||||
-- Some LSPs (like Clangd and intelephense) might return { { result = {} } }, so make sure we have result
|
||||
if server_results and server_results.result and not vim.tbl_isempty(server_results.result) then
|
||||
vim.list_extend(locations, vim.lsp.util.symbols_to_items(server_results.result, 0) or {})
|
||||
end
|
||||
if server_result and server_result.result and not vim.tbl_isempty(server_result.result) then
|
||||
vim.list_extend(locations, vim.lsp.util.symbols_to_items(server_result.result, 0) or {})
|
||||
end
|
||||
end
|
||||
|
||||
@@ -382,6 +376,7 @@ lsp.workspace_symbols = function(opts)
|
||||
sorter = conf.generic_sorter(opts),
|
||||
},
|
||||
}):find()
|
||||
end)
|
||||
end
|
||||
|
||||
local function get_workspace_symbols_requester(bufnr, opts)
|
||||
|
||||
Reference in New Issue
Block a user