@@ -518,13 +518,16 @@ require('lazy').setup({
518518 -- When you move your cursor, the highlights will be cleared (the second autocommand).
519519 local client = vim .lsp .get_client_by_id (event .data .client_id )
520520 if client and client .server_capabilities .documentHighlightProvider then
521+ local highlight_augroup = vim .api .nvim_create_augroup (' kickstart-lsp-highlight' , { clear = false })
521522 vim .api .nvim_create_autocmd ({ ' CursorHold' , ' CursorHoldI' }, {
522523 buffer = event .buf ,
524+ group = highlight_augroup ,
523525 callback = vim .lsp .buf .document_highlight ,
524526 })
525527
526528 vim .api .nvim_create_autocmd ({ ' CursorMoved' , ' CursorMovedI' }, {
527529 buffer = event .buf ,
530+ group = highlight_augroup ,
528531 callback = vim .lsp .buf .clear_references ,
529532 })
530533 end
@@ -535,12 +538,20 @@ require('lazy').setup({
535538 -- This may be unwanted, since they displace some of your code
536539 if client and client .server_capabilities .inlayHintProvider and vim .lsp .inlay_hint then
537540 map (' <leader>th' , function ()
538- vim .lsp .inlay_hint .enable (0 , not vim .lsp .inlay_hint .is_enabled ())
541+ vim .lsp .inlay_hint .enable (not vim .lsp .inlay_hint .is_enabled ())
539542 end , ' [T]oggle Inlay [H]ints' )
540543 end
541544 end ,
542545 })
543546
547+ vim .api .nvim_create_autocmd (' LspDetach' , {
548+ group = vim .api .nvim_create_augroup (' kickstart-lsp-detach' , { clear = true }),
549+ callback = function (event )
550+ vim .lsp .buf .clear_references ()
551+ vim .api .nvim_clear_autocmds { group = ' kickstart-lsp-highlight' , buffer = event .buf }
552+ end ,
553+ })
554+
544555 -- LSP servers and clients are able to communicate to each other what features they support.
545556 -- By default, Neovim doesn't support everything that is in the LSP specification.
546557 -- When you add nvim-cmp, luasnip, etc. Neovim now has *more* capabilities.
0 commit comments