From 02be767a82c15d12e82c61b209616e0fd91d72e9 Mon Sep 17 00:00:00 2001 From: Yegappan Lakshmanan Date: Tue, 28 Mar 2023 07:26:36 -0700 Subject: [PATCH] Move the diag sign and prop type definitions to a separate function --- autoload/lsp/diag.vim | 61 +++++++++++++++++++++++++++---------------- autoload/lsp/lsp.vim | 19 +------------- doc/lsp.txt | 14 +++++----- 3 files changed, 47 insertions(+), 47 deletions(-) diff --git a/autoload/lsp/diag.vim b/autoload/lsp/diag.vim index 1c33b8e..83ae122 100644 --- a/autoload/lsp/diag.vim +++ b/autoload/lsp/diag.vim @@ -6,6 +6,29 @@ import './options.vim' as opt import './buffer.vim' as buf import './util.vim' +# Initialize the signs and the text property type used for diagnostics. +export def InitOnce() + var lineHL: string = opt.lspOptions.diagLineHL + # Signs used for LSP diagnostics + sign_define([{name: 'LspDiagError', text: 'E>', texthl: 'ErrorMsg', + linehl: lineHL}, + {name: 'LspDiagWarning', text: 'W>', texthl: 'Search', + linehl: lineHL}, + {name: 'LspDiagInfo', text: 'I>', texthl: 'Pmenu', + linehl: lineHL}, + {name: 'LspDiagHint', text: 'H>', texthl: 'Question', + linehl: lineHL}]) + + if has('patch-9.0.1157') && opt.lspOptions.showDiagWithVirtualText + if !hlexists('LspDiagVirtualText') + hlset([{name: 'LspDiagVirtualText', + linksto: opt.lspOptions.diagVirtualTextHL}]) + endif + prop_type_add('LspDiagVirtualText', {highlight: 'LspDiagVirtualText', + override: true}) + endif +enddef + # Remove the diagnostics stored for buffer 'bnr' export def DiagRemoveFile(lspserver: dict, bnr: number) if lspserver.diagsMap->has_key(bnr) @@ -28,16 +51,9 @@ 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 && 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 + if has('patch-9.0.1157') && opt.lspOptions.showDiagWithVirtualText + # Remove all the existing virtual text + prop_remove({type: 'LspDiagVirtualText', bufnr: bnr, all: true}) endif if !lspserver.diagsMap->has_key(bnr) || @@ -55,13 +71,12 @@ def DiagsRefreshSigns(lspserver: dict, bnr: number) lnum: lnum, name: DiagSevToSignName(diag.severity)}) - if has('patch-9.0.1157') && opt.lspOptions.showDiagWithVirtualText && opt.lspOptions.autoHighlightDiags - prop_add( lnum, 0, { - bufnr: bnr, - type: 'LspDiagVirtualText', - text: '┌─ ' .. diag.message, - text_align: 'above', - text_padding_left: diag.range.start.character}) + if has('patch-9.0.1157') && opt.lspOptions.showDiagWithVirtualText + prop_add(lnum, 0, {bufnr: bnr, + type: 'LspDiagVirtualText', + text: $'┌─ {diag.message}', + text_align: 'above', + text_padding_left: diag.range.start.character}) endif endfor @@ -198,7 +213,7 @@ def DiagsUpdateLocList(lspserver: dict, bnr: number): bool var LspQfId: number = 0 if bnr->getbufvar('LspQfId', 0) != 0 && - getloclist(0, {id: b:LspQfId}).id == b:LspQfId + getloclist(0, {id: b:LspQfId}).id == b:LspQfId LspQfId = b:LspQfId endif @@ -418,13 +433,15 @@ enddef export def DiagsHighlightDisable() # turn off all diags highlight opt.lspOptions.autoHighlightDiags = false - # refresh for removing diagnostic virtual text + + # Remove the diganostics virtual text in all the buffers. for binfo in getbufinfo({bufloaded: true}) - var lspserver: dict = buf.BufLspServerGet(binfo.bufnr) - if !lspserver->empty() && lspserver.running - DiagsRefreshSigns(lspserver, binfo.bufnr) + if has('patch-9.0.1157') && opt.lspOptions.showDiagWithVirtualText + # Remove all virtual text + prop_remove({type: 'LspDiagVirtualText', bufnr: binfo.bufnr, all: true}) endif endfor + # Remove all the existing diagnostic signs in all the buffers sign_unplace('LSPDiag') enddef diff --git a/autoload/lsp/lsp.vim b/autoload/lsp/lsp.vim index 3a89f21..3a9eafb 100644 --- a/autoload/lsp/lsp.vim +++ b/autoload/lsp/lsp.vim @@ -31,28 +31,11 @@ var ftypeServerMap: dict> = {} var lspInitializedOnce = false def LspInitOnce() - var lineHL: string = opt.lspOptions.diagLineHL - # Signs used for LSP diagnostics - sign_define([{name: 'LspDiagError', text: 'E>', texthl: 'ErrorMsg', - linehl: lineHL}, - {name: 'LspDiagWarning', text: 'W>', texthl: 'Search', - linehl: lineHL}, - {name: 'LspDiagInfo', text: 'I>', texthl: 'Pmenu', - linehl: lineHL}, - {name: 'LspDiagHint', text: 'H>', texthl: 'Question', - linehl: lineHL}]) - prop_type_add('LspTextRef', {highlight: 'Search', override: true}) prop_type_add('LspReadRef', {highlight: 'DiffChange', override: true}) prop_type_add('LspWriteRef', {highlight: 'DiffDelete', override: true}) - if has('patch-9.0.1157') && opt.lspOptions.showDiagWithVirtualText - if !hlexists('LspDiagVirtualText') - hlset([{name: 'LspDiagVirtualText', linksto: opt.lspOptions.diagVirtualTextHL}]) - endif - prop_type_add('LspDiagVirtualText', {highlight: 'LspDiagVirtualText', override: true}) - endif - + diag.InitOnce() inlayhints.InitOnce() :set ballooneval balloonevalterm diff --git a/doc/lsp.txt b/doc/lsp.txt index c43e313..639ae12 100644 --- a/doc/lsp.txt +++ b/doc/lsp.txt @@ -334,13 +334,13 @@ showInlayHints |Boolean| option. Show inlay hints from the language server. By default this is set to false. The inlay 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. - By default uses "LineNr". +showDiagWithVirtualText |Boolean| option. Show diagnostic message text from + the language server with virtual text. By default + this is set to false. The "autoHighlightDiags" option + should be set to true. + Needs Vim version 9.0.1157 or later. +diagVirtualTextHL |String| option. The highlight group used for a + diagnostics virtual text. By default uses "LineNr". showSignature |Boolean| option. In insert mode, automatically show the current symbol signature in a popup. By default this is set to true. -- 2.48.1