mirror of
https://github.com/neovim/neovim.git
synced 2024-12-19 18:55:14 -07:00
feat(lsp): allow synchronous refresh of document highlights
This commit is contained in:
parent
8bb15e4cf4
commit
c2ff6d6b78
@ -1611,6 +1611,8 @@ jump({opts}) *vim.lsp.document_highlight.jump()*
|
||||
find the nearest highlight. Default is the current cursor
|
||||
position.
|
||||
• {winid}? (`integer`, default: `0`) Window ID
|
||||
• {refresh}? (`boolean`) Refresh documents highlights
|
||||
immediately before jumping.
|
||||
|
||||
*vim.lsp.document_highlight.on_document_highlight()*
|
||||
on_document_highlight({result}, {ctx})
|
||||
|
@ -141,7 +141,7 @@ function M.on_document_highlight(err, result, ctx)
|
||||
end
|
||||
|
||||
---@param bufnr integer
|
||||
---@param opts? {client_id?: integer}
|
||||
---@param opts? {client_id?: integer, sync?: boolean}
|
||||
local function refresh(bufnr, opts)
|
||||
local bufstate = assert(bufstates[bufnr])
|
||||
local enabled = bufstate.enabled
|
||||
@ -167,9 +167,23 @@ local function refresh(bufnr, opts)
|
||||
|
||||
for _, client in ipairs(clients) do
|
||||
local params = util.make_position_params(0, client.offset_encoding)
|
||||
|
||||
if opts.sync then
|
||||
local response = client:request_sync(ms.textDocument_documentHighlight, params, nil, bufnr)
|
||||
if response == nil then
|
||||
return
|
||||
end
|
||||
|
||||
M.on_document_highlight(
|
||||
response.err,
|
||||
response.result,
|
||||
{ bufnr = bufnr, client_id = client.id, method = ms.textDocument_documentHighlight }
|
||||
)
|
||||
else
|
||||
client:request(ms.textDocument_documentHighlight, params, nil, bufnr)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
---@param f function
|
||||
---@param timeout integer
|
||||
@ -436,6 +450,9 @@ end
|
||||
---Window ID
|
||||
---(default: `0`)
|
||||
---@field winid? integer
|
||||
---
|
||||
---Refresh documents highlights immediately before jumping.
|
||||
---@field refresh? boolean
|
||||
|
||||
---Move to a document highlight
|
||||
---@param opts vim.lsp.document_highlight.JumpOpts
|
||||
@ -456,6 +473,10 @@ function M.jump(opts)
|
||||
return
|
||||
end
|
||||
|
||||
if opts.refresh then
|
||||
refresh(bufnr, { sync = true })
|
||||
end
|
||||
|
||||
while count > 0 do
|
||||
pos = jump_next(bufnr, pos, bufstate.client_highlights)
|
||||
count = count - 1
|
||||
|
Loading…
Reference in New Issue
Block a user