fix(lsp): do not detach from buffer if there are uninitialized clients (#29043)

Problem: if on_lines is called before the LSP is initialized, the buffer
is detached.
Solution: check for uninitialized clients before detaching.

(cherry picked from commit 292365fa1b)

Co-authored-by: Ilia Choly <ilia.choly@gmail.com>
This commit is contained in:
github-actions[bot]
2024-05-27 17:26:42 +02:00
committed by GitHub
parent b9e540cc70
commit e98637e8c0
2 changed files with 30 additions and 1 deletions

View File

@@ -573,7 +573,8 @@ local function buf_attach(bufnr)
api.nvim_buf_attach(bufnr, false, {
on_lines = function(_, _, changedtick, firstline, lastline, new_lastline)
if #lsp.get_clients({ bufnr = bufnr }) == 0 then
return true -- detach
-- detach if there are no clients
return #lsp.get_clients({ bufnr = bufnr, _uninitialized = true }) == 0
end
util.buf_versions[bufnr] = changedtick
changetracking.send_changes(bufnr, firstline, lastline, new_lastline)