Fix highlight errors when lsp crash or stop
It adds a check wether the client is still available before highlighting. If the client is not there anymore it returns `true` to unregister the autocommand This fix the `method textDocument/documentHighlight is not supported by any of the servers registered for the current buffer` errors when doing a LspRestart or the server crashes
This commit is contained in:
		
							parent
							
								
									f5c9fe8e15
								
							
						
					
					
						commit
						4d73020681
					
				
							
								
								
									
										15
									
								
								init.lua
								
								
								
								
							
							
						
						
									
										15
									
								
								init.lua
								
								
								
								
							|  | @ -516,12 +516,23 @@ require('lazy').setup({ | ||||||
|           if client and client.server_capabilities.documentHighlightProvider then |           if client and client.server_capabilities.documentHighlightProvider then | ||||||
|             vim.api.nvim_create_autocmd({ 'CursorHold', 'CursorHoldI' }, { |             vim.api.nvim_create_autocmd({ 'CursorHold', 'CursorHoldI' }, { | ||||||
|               buffer = event.buf, |               buffer = event.buf, | ||||||
|               callback = vim.lsp.buf.document_highlight, |               callback = function() | ||||||
|  |                 if not vim.lsp.get_client_by_id(event.data.client_id) then | ||||||
|  |                   vim.lsp.buf.clear_references() | ||||||
|  |                   return true | ||||||
|  |                 end | ||||||
|  |                 vim.lsp.buf.document_highlight() | ||||||
|  |               end, | ||||||
|             }) |             }) | ||||||
| 
 | 
 | ||||||
|             vim.api.nvim_create_autocmd({ 'CursorMoved', 'CursorMovedI' }, { |             vim.api.nvim_create_autocmd({ 'CursorMoved', 'CursorMovedI' }, { | ||||||
|               buffer = event.buf, |               buffer = event.buf, | ||||||
|               callback = vim.lsp.buf.clear_references, |               callback = function() | ||||||
|  |                 if not vim.lsp.get_client_by_id(event.data.client_id) then | ||||||
|  |                   return true | ||||||
|  |                 end | ||||||
|  |                 vim.lsp.buf.clear_references() | ||||||
|  |               end, | ||||||
|             }) |             }) | ||||||
|           end |           end | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue