aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--runtime/lua/vim/lsp/_tagfunc.lua44
1 files changed, 28 insertions, 16 deletions
diff --git a/runtime/lua/vim/lsp/_tagfunc.lua b/runtime/lua/vim/lsp/_tagfunc.lua
index 70917de48d..f75d43f373 100644
--- a/runtime/lua/vim/lsp/_tagfunc.lua
+++ b/runtime/lua/vim/lsp/_tagfunc.lua
@@ -1,4 +1,5 @@
local lsp = vim.lsp
+local api = vim.api
local util = lsp.util
local ms = lsp.protocol.Methods
@@ -21,11 +22,12 @@ end
---@param pattern string
---@return table[]
local function query_definition(pattern)
- local params = util.make_position_params()
- local results_by_client, err = lsp.buf_request_sync(0, ms.textDocument_definition, params, 1000)
- if err then
+ local bufnr = api.nvim_get_current_buf()
+ local clients = vim.lsp.get_clients({ bufnr = bufnr, method = ms.textDocument_definition })
+ if not next(clients) then
return {}
end
+ local win = api.nvim_get_current_win()
local results = {}
--- @param range lsp.Range
@@ -35,23 +37,33 @@ local function query_definition(pattern)
table.insert(results, mk_tag_item(pattern, range, uri, offset_encoding))
end
- for client_id, lsp_results in pairs(assert(results_by_client)) do
- local client = lsp.get_client_by_id(client_id)
- local offset_encoding = client and client.offset_encoding or 'utf-16'
- local result = lsp_results.result or {}
- if result.range then -- Location
- add(result.range, result.uri, offset_encoding)
- else
- result = result --[[@as (lsp.Location[]|lsp.LocationLink[])]]
- for _, item in pairs(result) do
- if item.range then -- Location
- add(item.range, item.uri, offset_encoding)
- else -- LocationLink
- add(item.targetSelectionRange, item.targetUri, offset_encoding)
+ local remaining = #clients
+ for _, client in ipairs(clients) do
+ ---@param result nil|lsp.Location|lsp.Location[]|lsp.LocationLink[]
+ local function on_response(_, result)
+ if result then
+ local encoding = client.offset_encoding
+ -- single Location
+ if result.range then
+ add(result.range, result.uri, encoding)
+ else
+ for _, location in ipairs(result) do
+ if location.range then -- Location
+ add(location.range, location.uri, encoding)
+ else -- LocationLink
+ add(location.targetSelectionRange, location.targetUri, encoding)
+ end
+ end
end
end
+ remaining = remaining - 1
end
+ local params = util.make_position_params(win, client.offset_encoding)
+ client.request(ms.textDocument_definition, params, on_response, bufnr)
end
+ vim.wait(1000, function()
+ return remaining == 0
+ end)
return results
end