From 1e886973eb5dc832761f9074c89dee51ecb04d4a Mon Sep 17 00:00:00 2001 From: Oleksiy Hryshchenko Date: Mon, 27 Mar 2023 14:27:09 +0300 Subject: [PATCH] add diagnostic messages display with virtual text and pointer --- autoload/lsp/diag.vim | 14 ++++++++++++++ autoload/lsp/lsp.vim | 7 +++++++ autoload/lsp/options.vim | 2 ++ doc/lsp.txt | 3 +++ 4 files changed, 26 insertions(+) diff --git a/autoload/lsp/diag.vim b/autoload/lsp/diag.vim index 9f5d641..7e50fe4 100644 --- a/autoload/lsp/diag.vim +++ b/autoload/lsp/diag.vim @@ -27,6 +27,11 @@ 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 + # Remove all virtual text + prop_remove({type: 'LspDiagVirtualText', bufnr: bnr, all: true}) + endif + if !lspserver.diagsMap->has_key(bnr) || lspserver.diagsMap[bnr].sortedDiagnostics->empty() return @@ -41,6 +46,15 @@ def DiagsRefreshSigns(lspserver: dict, bnr: number) signs->add({id: 0, buffer: bnr, group: 'LSPDiag', lnum: lnum, name: DiagSevToSignName(diag.severity)}) + + 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 signs->sign_placelist() diff --git a/autoload/lsp/lsp.vim b/autoload/lsp/lsp.vim index c6fc4b2..1cfb469 100644 --- a/autoload/lsp/lsp.vim +++ b/autoload/lsp/lsp.vim @@ -46,6 +46,13 @@ def LspInitOnce() 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: 'LineNr'}]) + endif + prop_type_add('LspDiagVirtualText', {highlight: 'LspDiagVirtualText', override: true}) + endif + inlayhints.InitOnce() :set ballooneval balloonevalterm diff --git a/autoload/lsp/options.vim b/autoload/lsp/options.vim index 3d3440f..33cbffa 100644 --- a/autoload/lsp/options.vim +++ b/autoload/lsp/options.vim @@ -36,6 +36,8 @@ export var lspOptions: dict = { showDiagInPopup: true, # Default diagnostic highlight on lines diagLineHL: 'DiffAdd', + # Show a diagnostic messages with virtual text + showDiagWithVirtualText: false, # Don't print message when a configured language server is missing. ignoreMissingServer: false, # Use a floating menu to show the code action menu instead of asking for input diff --git a/doc/lsp.txt b/doc/lsp.txt index bb41fd9..39fb8c3 100644 --- a/doc/lsp.txt +++ b/doc/lsp.txt @@ -334,6 +334,9 @@ 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 Vim version 9.0.1157 or later. 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