fix(lsp): send didOpen on save to all clients+groups #37454

Problem: _get_and_set_name edits the name for the whole group,
thus only one client per group gets the didOpen message.

Solution: move the logic to _changetracking and loop over every
client per group.
This commit is contained in:
Emilv2
2026-04-12 16:56:12 +02:00
committed by GitHub
parent b7cbad7489
commit 37eb1b9979
3 changed files with 78 additions and 45 deletions

View File

@@ -883,42 +883,7 @@ end
---Buffer lifecycle handler for textDocument/didSave
--- @param bufnr integer
local function text_document_did_save_handler(bufnr)
bufnr = vim._resolve_bufnr(bufnr)
local uri = vim.uri_from_bufnr(bufnr)
local text = vim.func._memoize('concat', lsp._buf_get_full_text)
for _, client in ipairs(lsp.get_clients({ bufnr = bufnr })) do
local name = api.nvim_buf_get_name(bufnr)
local old_name = changetracking._get_and_set_name(client, bufnr, name)
if old_name and name ~= old_name then
client:notify('textDocument/didClose', {
textDocument = {
uri = vim.uri_from_fname(old_name),
},
})
client:notify('textDocument/didOpen', {
textDocument = {
version = 0,
uri = uri,
languageId = client.get_language_id(bufnr, vim.bo[bufnr].filetype),
text = lsp._buf_get_full_text(bufnr),
},
})
util.buf_versions[bufnr] = 0
end
local save_capability = vim.tbl_get(client.server_capabilities, 'textDocumentSync', 'save')
if save_capability then
local included_text --- @type string?
if type(save_capability) == 'table' and save_capability.includeText then
included_text = text(bufnr)
end
client:notify('textDocument/didSave', {
textDocument = {
uri = uri,
},
text = included_text,
})
end
end
changetracking._send_did_save(bufnr)
end
--- @type table<integer,true>