autoload/lsp/diag.vim | 21 ++++++++++++++++++--- doc/lsp.txt | 1 + diff --git a/autoload/lsp/diag.vim b/autoload/lsp/diag.vim index d21e21d2fb783418582d4f4fcaa56d97b5769a87..3919ef49b5fdf812ea73fb6f7cb25778dfd919f4 100644 --- a/autoload/lsp/diag.vim +++ b/autoload/lsp/diag.vim @@ -28,9 +28,16 @@ bnr->bufload() # Remove all the existing diagnostic signs sign_unplace('LSPDiag', {buffer: bnr}) - if has('patch-9.0.1157') && opt.lspOptions.showDiagWithVirtualText + if has('patch-9.0.1157') && opt.lspOptions.showDiagWithVirtualText && opt.lspOptions.autoHighlightDiags # Remove all virtual text prop_remove({type: 'LspDiagVirtualText', bufnr: bnr, all: true}) + endif + + # remove add virtual text in all bufs if auto highlight digs off + if !opt.lspOptions.autoHighlightDiags + for binfo in getbufinfo({bufloaded: true}) + prop_remove({type: 'LspDiagVirtualText', bufnr: binfo.bufnr, all: true}) + endfor endif if !lspserver.diagsMap->has_key(bnr) || @@ -48,7 +55,7 @@ signs->add({id: 0, buffer: bnr, group: 'LSPDiag', lnum: lnum, name: DiagSevToSignName(diag.severity)}) - if has('patch-9.0.1157') && opt.lspOptions.showDiagWithVirtualText + if has('patch-9.0.1157') && opt.lspOptions.showDiagWithVirtualText && opt.lspOptions.autoHighlightDiags prop_add( lnum, 0, { bufnr: bnr, type: 'LspDiagVirtualText', @@ -397,9 +404,17 @@ enddef # Disable the LSP diagnostics highlighting in all the buffers export def DiagsHighlightDisable() + # turn off all diags highlight + opt.lspOptions.autoHighlightDiags = false + # refresh for removing diagnostic virtual text + for binfo in getbufinfo({bufloaded: true}) + var lspserver: dict = buf.BufLspServerGet(binfo.bufnr) + if !lspserver->empty() && lspserver.running + DiagsRefreshSigns(lspserver, binfo.bufnr) + endif + endfor # Remove all the existing diagnostic signs in all the buffers sign_unplace('LSPDiag') - opt.lspOptions.autoHighlightDiags = false enddef # Enable the LSP diagnostics highlighting diff --git a/doc/lsp.txt b/doc/lsp.txt index da139ce504b298af0cf3da827fc1f621bbce5f81..c43e3135e82ff31a62bdcd6597c3b299ab64e761 100644 --- a/doc/lsp.txt +++ b/doc/lsp.txt @@ -336,6 +336,7 @@ hint text is displayed as a virtual text. Needs Vim version 9.0.0178 or later. showDiagWithVirtualText |Boolean| option. Show diagnostic messages text from the language server with virtual text. By default this is set to false. + Needs autoHighlightDiags == true Needs Vim version 9.0.1157 or later. diagVirtualTextHL |String| option. The highlight group used for a diagnostics virtual text.