mirror of
				https://github.com/neovim/neovim.git
				synced 2025-11-04 01:34:25 +00:00 
			
		
		
		
	fix(lsp): clear lsp client diagnostics (#29050)
Problem: When an lsp client is stopped, the client will only clear the diagnostics for the attached buffers but not the unattached buffers. Solution: Reset the diagnostics for the whole namespace rather than for only the attached buffers.
This commit is contained in:
		@@ -391,8 +391,8 @@ end
 | 
				
			|||||||
local function on_client_exit(code, signal, client_id)
 | 
					local function on_client_exit(code, signal, client_id)
 | 
				
			||||||
  local client = all_clients[client_id]
 | 
					  local client = all_clients[client_id]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  for bufnr in pairs(client.attached_buffers) do
 | 
					 | 
				
			||||||
  vim.schedule(function()
 | 
					  vim.schedule(function()
 | 
				
			||||||
 | 
					    for bufnr in pairs(client.attached_buffers) do
 | 
				
			||||||
      if client and client.attached_buffers[bufnr] then
 | 
					      if client and client.attached_buffers[bufnr] then
 | 
				
			||||||
        api.nvim_exec_autocmds('LspDetach', {
 | 
					        api.nvim_exec_autocmds('LspDetach', {
 | 
				
			||||||
          buffer = bufnr,
 | 
					          buffer = bufnr,
 | 
				
			||||||
@@ -401,16 +401,17 @@ local function on_client_exit(code, signal, client_id)
 | 
				
			|||||||
        })
 | 
					        })
 | 
				
			||||||
      end
 | 
					      end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      local namespace = vim.lsp.diagnostic.get_namespace(client_id)
 | 
					 | 
				
			||||||
      vim.diagnostic.reset(namespace, bufnr)
 | 
					 | 
				
			||||||
      client.attached_buffers[bufnr] = nil
 | 
					      client.attached_buffers[bufnr] = nil
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      if #lsp.get_clients({ bufnr = bufnr, _uninitialized = true }) == 0 then
 | 
					      if #lsp.get_clients({ bufnr = bufnr, _uninitialized = true }) == 0 then
 | 
				
			||||||
        reset_defaults(bufnr)
 | 
					        reset_defaults(bufnr)
 | 
				
			||||||
      end
 | 
					      end
 | 
				
			||||||
    end)
 | 
					 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    local namespace = vim.lsp.diagnostic.get_namespace(client_id)
 | 
				
			||||||
 | 
					    vim.diagnostic.reset(namespace)
 | 
				
			||||||
 | 
					  end)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  local name = client.name or 'unknown'
 | 
					  local name = client.name or 'unknown'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  -- Schedule the deletion of the client object so that it exists in the execution of LspDetach
 | 
					  -- Schedule the deletion of the client object so that it exists in the execution of LspDetach
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user