mirror of
https://github.com/neovim/neovim.git
synced 2024-12-20 03:05:11 -07:00
fix(lsp): change signature of buf_highlight_references (#16345)
the prior signature did not assume an active language client this function can now be used directly by passing an offset encoding defaults to utf-16 (standard for LSP)
This commit is contained in:
parent
c0efe49e78
commit
eb3d59126e
@ -350,7 +350,10 @@ M['textDocument/signatureHelp'] = M.signature_help
|
||||
--see: https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_documentHighlight
|
||||
M['textDocument/documentHighlight'] = function(_, result, ctx, _)
|
||||
if not result then return end
|
||||
util.buf_highlight_references(ctx.bufnr, result, ctx.client_id)
|
||||
local client_id = ctx.client_id
|
||||
local client = vim.lsp.get_client_by_id(client_id)
|
||||
if not client then return end
|
||||
util.buf_highlight_references(ctx.bufnr, result, client.offset_encoding)
|
||||
end
|
||||
|
||||
---@private
|
||||
|
@ -1341,19 +1341,17 @@ do --[[ References ]]
|
||||
---
|
||||
---@param bufnr buffer id
|
||||
---@param references List of `DocumentHighlight` objects to highlight
|
||||
---@param offset_encoding string utf-8|utf-16|utf-32|nil defaults to utf-16
|
||||
---@see https://microsoft.github.io/language-server-protocol/specifications/specification-3-17/#documentHighlight
|
||||
function M.buf_highlight_references(bufnr, references, client_id)
|
||||
function M.buf_highlight_references(bufnr, references, offset_encoding)
|
||||
validate { bufnr = {bufnr, 'n', true} }
|
||||
local client = vim.lsp.get_client_by_id(client_id)
|
||||
if not client then
|
||||
return
|
||||
end
|
||||
offset_encoding = offset_encoding or 'utf-16'
|
||||
for _, reference in ipairs(references) do
|
||||
local start_line, start_char = reference["range"]["start"]["line"], reference["range"]["start"]["character"]
|
||||
local end_line, end_char = reference["range"]["end"]["line"], reference["range"]["end"]["character"]
|
||||
|
||||
local start_idx = get_line_byte_from_position(bufnr, { line = start_line, character = start_char }, client.offset_encoding)
|
||||
local end_idx = get_line_byte_from_position(bufnr, { line = start_line, character = end_char }, client.offset_encoding)
|
||||
local start_idx = get_line_byte_from_position(bufnr, { line = start_line, character = start_char }, offset_encoding)
|
||||
local end_idx = get_line_byte_from_position(bufnr, { line = start_line, character = end_char }, offset_encoding)
|
||||
|
||||
local document_highlight_kind = {
|
||||
[protocol.DocumentHighlightKind.Text] = "LspReferenceText";
|
||||
|
Loading…
Reference in New Issue
Block a user