This commit is contained in:
Julian Delerme 2024-09-16 23:32:42 +01:00 committed by GitHub
commit bd1dcc5d0a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 51 additions and 5 deletions

View File

@ -1033,6 +1033,11 @@ Lua module: vim.lsp.client *lsp-client*
`150`) Debounce `didChange` notifications to
the server by the given number in
milliseconds. No debounce occurs if `nil`.
• {pull_diagnostics_on_save} (`boolean`,
default: `false`) Request diagnostics from
the server on `didSave` events instead of
`didChange` events. Has no effect if the
server does not support pull diagnostics.
• {exit_timeout} (`integer|false`, default:
`false`) Milliseconds to wait for server to
exit cleanly after sending the "shutdown"
@ -1204,6 +1209,11 @@ Lua module: vim.lsp.client *lsp-client*
`150`) Debounce `didChange` notifications to
the server by the given number in
milliseconds. No debounce occurs if `nil`.
• {pull_diagnostics_on_save} (`boolean`,
default: `false`) Request diagnostics from the
server on `didSave` events instead of
`didChange` events. Has no effect if the
server does not support pull diagnostics.
• {exit_timeout} (`integer|false`, default:
`false`) Milliseconds to wait for server to
exit cleanly after sending the "shutdown"

View File

@ -141,6 +141,8 @@ LSP
• Completion side effects (including snippet expansion, execution of commands
and application of additional text edits) is now built-in.
• |vim.lsp.Client| flag `pull_diagnostic_on_save` sends diagnostic requests on
save instead of change
• |vim.lsp.util.locations_to_items()| sets `end_col` and `end_lnum` fields.
• |vim.lsp.buf.format()| now supports passing a list of ranges
via the `range` parameter (this requires support for the

View File

@ -23,6 +23,11 @@ local validate = vim.validate
--- (default: `150`)
--- @field debounce_text_changes integer
---
--- Request diagnostics from the server on `didSave` events instead of `didChange` events.
--- Has no effect if the server does not support pull diagnostics.
--- (default: `false`)
--- @field pull_diagnostics_on_save boolean
---
--- Milliseconds to wait for server to exit cleanly after sending the
--- "shutdown" request before sending kill -15. If set to false, nvim exits
--- immediately after sending the "shutdown" request to the server.

View File

@ -438,14 +438,43 @@ function M._enable(bufnr)
buffer = bufnr,
callback = function(opts)
if
opts.data.method ~= ms.textDocument_didChange
and opts.data.method ~= ms.textDocument_didOpen
not (bufstates[bufnr] and bufstates[bufnr].enabled)
or (
opts.data.method ~= ms.textDocument_didChange
and opts.data.method ~= ms.textDocument_didSave
and opts.data.method ~= ms.textDocument_didOpen
)
then
return
end
if bufstates[bufnr] and bufstates[bufnr].enabled then
local client_id = opts.data.client_id --- @type integer?
_refresh(bufnr, { only_visible = true, client_id = client_id })
local opts_client_id = opts.data.client_id --- @type integer?
if opts.data.method == ms.textDocument_didOpen then
_refresh(bufnr, { only_visible = true, client_id = opts_client_id })
return
end
local clients = vim.lsp.get_clients({
bufnr = bufnr,
method = ms.textDocument_diagnostic,
client_id = opts_client_id,
})
local on_save_client_ids = {} --- @type integer[]
local on_change_client_ids = {} --- @type integer[]
for _, client in pairs(clients) do
if client.flags.pull_diagnostics_on_save then
on_save_client_ids[#on_save_client_ids + 1] = client.id
else
on_change_client_ids[#on_change_client_ids + 1] = client.id
end
end
if opts.data.method == ms.textDocument_didSave then
for _, client_id in pairs(on_save_client_ids) do
_refresh(bufnr, { only_visible = true, client_id = client_id })
end
else
for _, client_id in pairs(on_change_client_ids) do
_refresh(bufnr, { only_visible = true, client_id = client_id })
end
end
end,
group = augroup,