mirror of
				https://github.com/neovim/neovim.git
				synced 2025-10-26 12:27:24 +00:00 
			
		
		
		
	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:
		![41898282+github-actions[bot]@users.noreply.github.com](/assets/img/avatar_default.png) github-actions[bot]
					github-actions[bot]
				
			
				
					committed by
					
						 GitHub
						GitHub
					
				
			
			
				
	
			
			
			 GitHub
						GitHub
					
				
			
						parent
						
							b9e540cc70
						
					
				
				
					commit
					e98637e8c0
				
			| @@ -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) | ||||
|   | ||||
| @@ -530,6 +530,34 @@ describe('LSP', function() | ||||
|       ]]) | ||||
|     end) | ||||
|  | ||||
|     it('should allow on_lines + nvim_buf_delete during LSP initialization #28575', function() | ||||
|       clear() | ||||
|       exec_lua(create_server_definition) | ||||
|       exec_lua([[ | ||||
|         local initialized = false | ||||
|         local server = _create_server({ | ||||
|           handlers = { | ||||
|             initialize = function(method, params, callback) | ||||
|               vim.schedule(function() | ||||
|                 callback(nil, { capabilities = {} }) | ||||
|                 initialized = true | ||||
|               end) | ||||
|             end | ||||
|           } | ||||
|         }) | ||||
|         local bufnr = vim.api.nvim_create_buf(false, true) | ||||
|         vim.api.nvim_set_current_buf(bufnr) | ||||
|         local client_id = vim.lsp.start({ | ||||
|           name = 'detach-dummy', | ||||
|           cmd = server.cmd, | ||||
|         }) | ||||
|         vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, {"hello"}) | ||||
|         vim.api.nvim_buf_delete(bufnr, {}) | ||||
|         local ok = vim.wait(1000, function() return initialized end) | ||||
|         assert(ok, "lsp did not initialize") | ||||
|       ]]) | ||||
|     end) | ||||
|  | ||||
|     it('client should return settings via workspace/configuration handler', function() | ||||
|       local expected_handlers = { | ||||
|         { NIL, {}, { method = 'shutdown', client_id = 1 } }, | ||||
|   | ||||
		Reference in New Issue
	
	Block a user