mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
fix(lsp): handle mixed encoding in tagfunc params
Relates to https://github.com/neovim/neovim/issues/30034
This commit is contained in:
parent
50e63c8171
commit
008782208d
@ -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)
|
||||
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
|
||||
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)
|
||||
for _, location in ipairs(result) do
|
||||
if location.range then -- Location
|
||||
add(location.range, location.uri, encoding)
|
||||
else -- LocationLink
|
||||
add(item.targetSelectionRange, item.targetUri, offset_encoding)
|
||||
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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user