 notomo
		
	
	bbfcde3ab2
	
	
	fix(lsp): check if buffer is valid in scheduled client:on_attach() #35672
			notomo
		
	
	bbfcde3ab2
	
	
	fix(lsp): check if buffer is valid in scheduled client:on_attach() #35672
		
			
			Problem:
lsp._capability.is_enabled() can raise error if buffer is invalid in client:on_attach().
- error
```
./build/bin/nvim --clean --headless +"source ./minimal.lua"
vim.schedule callback: ...omo/workspace/neovim/runtime/lua/vim/lsp/_capability.lua:209: scoped variable: Invalid buffer id: 2
stack traceback:
        [C]: in function '__index'
        ...omo/workspace/neovim/runtime/lua/vim/lsp/_capability.lua:209: in function 'is_enabled'
        ...e/notomo/workspace/neovim/runtime/lua/vim/lsp/client.lua:1108: in function <...e/notomo/workspace/neovim/runtime/lua/vim/lsp/client.lua:1101>
```
- reproduction minimal.lua
```lua
vim.opt.runtimepath:append("/path/to/nvim-lspconfig/")
vim.lsp.enable("lua_ls")
vim.cmd.tabedit("runtime/lua/vim/_defaults.lua")
vim.api.nvim_create_autocmd({ "LspAttach" }, {
  group = vim.api.nvim_create_augroup("test", {}),
  callback = function()
    vim.cmd.tabedit("runtime/lua/vim/_defaults.lua")
    local bufnr = vim.api.nvim_get_current_buf()
    vim.api.nvim_buf_delete(bufnr, { force = true })
  end,
})
```
Solution:
Check whether buffer is valid.
		
	
 
		2025-09-08 17:52:25 -07:00
	 
	
	
	
		 ..
	
	
	
		
			
			
			
			
			
			2025-08-28 06:41:31 -07:00
		 
	
		
			
			
			
			
			
			2025-09-06 14:19:12 -07:00
		 
	
		
			
			
			
			
			
			2025-05-06 05:15:31 -07:00
		 
	
		
			
			
			
			
			
			2025-09-08 11:40:12 +08:00
		 
	
		
			
			
			
			
			
			2024-06-04 06:06:02 -07:00
		 
	
		
			
			
			
			
			
			2025-09-05 17:22:24 +08:00
		 
	
		
			
			
			
			
			
			2025-01-05 12:28:01 +01:00
		 
	
		
			
			
			
			
			
			2025-08-27 20:01:07 -07:00
		 
	
		
			
			
			
			
			
			2025-09-08 17:52:25 -07:00
		 
	
		
			
			
			
			
			
			2025-08-17 20:40:28 -07:00
		 
	
		
			
			
			
			
			
			2025-07-04 15:56:28 +03:00
		 
	
		
			
			
			
			
			
			2025-08-31 11:17:21 -07:00
		 
	
		
			
			
			
			
			
			2025-09-01 14:08:08 -07:00
		 
	
		
			
			
			
			
			
			2025-08-22 15:05:43 -05:00
		 
	
		
			
			
			
			
			
			2025-08-02 15:00:41 +03:00
		 
	
		
			
			
			
			
			
			2024-11-17 13:31:24 -08:00
		 
	
		
			
			
			
			
			
			2025-08-28 11:34:01 +02:00
		 
	
		
			
			
			
			
			
			2025-08-22 15:05:43 -05:00
		 
	
		
			
			
			
			
			
			2025-08-17 11:54:53 +08:00
		 
	
		
			
			
			
			
			
			2025-07-11 17:31:30 +02:00
		 
	
		
			
			
			
			
			
			2025-07-10 13:34:58 +01:00
		 
	
		
			
			
			
			
			
			2025-08-23 12:01:38 -07:00
		 
	
		
			
			
			
			
			
			2025-08-17 11:54:53 +08:00
		 
	
		
			
			
			
			
			
			2025-02-23 07:51:12 -08:00
		 
	
		
			
			
			
			
			
			2025-03-31 16:51:18 +01:00
		 
	
		
			
			
			
			
			
			2025-07-28 22:00:25 -04:00
		 
	
		
			
			
			
			
			
			2024-10-21 11:32:06 +01:00
		 
	
		
			
			
			
			
			
			2025-08-28 11:34:01 +02:00
		 
	
		
			
			
			
			
			
			2025-06-06 15:36:48 +01:00
		 
	
		
			
			
			
			
			
			2025-09-04 07:16:47 +08:00
		 
	
		
			
			
			
			
			
			2025-08-28 11:34:01 +02:00
		 
	
		
			
			
			
			
			
			2025-05-10 14:42:48 -07:00
		 
	
		
			
			
			
			
			
			2025-06-03 06:36:44 -07:00
		 
	
		
			
			
			
			
			
			2025-07-08 05:21:09 -07:00
		 
	
		
			
			
			
			
			
			2025-08-28 11:34:01 +02:00
		 
	
		
			
			
			
			
			
			2025-01-27 16:37:50 +00:00
		 
	
		
			
			
			
			
			
			2025-07-22 17:40:24 -07:00
		 
	
		
			
			
			
			
			
			2025-07-10 21:50:46 -04:00
		 
	
		
			
			
			
			
			
			2025-08-28 11:34:01 +02:00
		 
	
		
			
			
			
			
			
			2025-08-31 14:09:12 -07:00
		 
	
		
			
			
			
			
			
			2025-07-28 22:00:25 -04:00
		 
	
		
			
			
			
			
			
			2025-09-07 14:42:09 -07:00
		 
	
		
			
			
			
			
			
			2025-08-24 22:17:34 -04:00
		 
	
		
			
			
			
			
			
			2024-02-03 16:53:41 +01:00
		 
	
		
			
			
			
			
			
			2025-08-24 23:43:48 +00:00
		 
	
		
			
			
			
			
			
			2025-02-10 03:04:01 -08:00
		 
	
		
			
			
			
			
			
			2025-07-28 22:00:25 -04:00
		 
	
		
			
			
			
			
			
			2025-08-03 07:45:49 -07:00
		 
	
		
			
			
			
			
			
			2025-08-19 06:21:32 -07:00
		 
	
		
			
			
			
			
			
			2025-08-22 15:05:43 -05:00
		 
	
		
			
			
			
			
			
			2025-07-12 20:54:22 -07:00
		 
	
		
			
			
			
			
			
			2025-06-14 17:24:36 +02:00
		 
	
		
			
			
			
			
			
			2025-06-18 03:20:18 -07:00
		 
	
		
			
			
			
			
			
			2025-01-27 16:37:50 +00:00
		 
	
		
			
			
			
			
			
			2025-07-23 20:03:30 -07:00