mirror of
https://github.com/neovim/neovim.git
synced 2024-12-31 17:13:26 -07:00
perf(lsp): refresh only on the corresponding client
This commit is contained in:
parent
f52c2753d1
commit
8bb15e4cf4
@ -141,7 +141,8 @@ function M.on_document_highlight(err, result, ctx)
|
|||||||
end
|
end
|
||||||
|
|
||||||
---@param bufnr integer
|
---@param bufnr integer
|
||||||
local function refresh(bufnr)
|
---@param opts? {client_id?: integer}
|
||||||
|
local function refresh(bufnr, opts)
|
||||||
local bufstate = assert(bufstates[bufnr])
|
local bufstate = assert(bufstates[bufnr])
|
||||||
local enabled = bufstate.enabled
|
local enabled = bufstate.enabled
|
||||||
if enabled == nil then
|
if enabled == nil then
|
||||||
@ -154,7 +155,16 @@ local function refresh(bufnr)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local clients = vim.lsp.get_clients({ bufnr = bufnr, method = ms.textDocument_documentHighlight })
|
opts = opts or {}
|
||||||
|
|
||||||
|
---@type vim.lsp.Client[]
|
||||||
|
local clients
|
||||||
|
if opts.client_id then
|
||||||
|
clients = { assert(vim.lsp.get_client_by_id(opts.client_id)) }
|
||||||
|
else
|
||||||
|
clients = vim.lsp.get_clients({ bufnr = bufnr, method = ms.textDocument_documentHighlight })
|
||||||
|
end
|
||||||
|
|
||||||
for _, client in ipairs(clients) do
|
for _, client in ipairs(clients) do
|
||||||
local params = util.make_position_params(0, client.offset_encoding)
|
local params = util.make_position_params(0, client.offset_encoding)
|
||||||
client:request(ms.textDocument_documentHighlight, params, nil, bufnr)
|
client:request(ms.textDocument_documentHighlight, params, nil, bufnr)
|
||||||
@ -211,14 +221,16 @@ api.nvim_create_autocmd('LspNotify', {
|
|||||||
callback = function(args)
|
callback = function(args)
|
||||||
---@type integer
|
---@type integer
|
||||||
local bufnr = args.buf
|
local bufnr = args.buf
|
||||||
|
local client = assert(vim.lsp.get_client_by_id(args.data.client_id))
|
||||||
if
|
if
|
||||||
bufstates[bufnr]
|
bufstates[bufnr]
|
||||||
|
and client:supports_method(ms.textDocument_documentHighlight, bufnr)
|
||||||
and (
|
and (
|
||||||
args.data.method == ms.textDocument_didChange
|
args.data.method == ms.textDocument_didChange
|
||||||
or args.data.method == ms.textDocument_didOpen
|
or args.data.method == ms.textDocument_didOpen
|
||||||
)
|
)
|
||||||
then
|
then
|
||||||
refresh(bufnr)
|
refresh(bufnr, { client_id = client.id })
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
@ -410,6 +422,7 @@ end
|
|||||||
|
|
||||||
---@class vim.lsp.document_highlight.JumpOpts
|
---@class vim.lsp.document_highlight.JumpOpts
|
||||||
---@inlinedoc
|
---@inlinedoc
|
||||||
|
---
|
||||||
---The number of highlights to move by, starting from {pos}. A positive
|
---The number of highlights to move by, starting from {pos}. A positive
|
||||||
---integer moves forward by {count} highlights, while a negative integer moves
|
---integer moves forward by {count} highlights, while a negative integer moves
|
||||||
---backward by {count} highlights.
|
---backward by {count} highlights.
|
||||||
|
Loading…
Reference in New Issue
Block a user