From fdcb549003e49a48f5846911f25afaa4b2bef42d Mon Sep 17 00:00:00 2001 From: Oleksiy Hryshchenko Date: Tue, 28 Mar 2023 12:22:57 +0300 Subject: [PATCH] connect digs virtual text display with autoHighlightDiags option --- autoload/lsp/diag.vim | 21 ++++++++++++++++++--- doc/lsp.txt | 1 + 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/autoload/lsp/diag.vim b/autoload/lsp/diag.vim index d21e21d..3919ef4 100644 --- a/autoload/lsp/diag.vim +++ b/autoload/lsp/diag.vim @@ -28,11 +28,18 @@ def DiagsRefreshSigns(lspserver: dict, bnr: number) # 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) || lspserver.diagsMap[bnr].sortedDiagnostics->empty() return @@ -48,7 +55,7 @@ def DiagsRefreshSigns(lspserver: dict, bnr: number) 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 da139ce..c43e313 100644 --- a/doc/lsp.txt +++ b/doc/lsp.txt @@ -336,6 +336,7 @@ showInlayHints |Boolean| option. Show inlay hints from the language 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. -- 2.48.1