]> Sergey Matveev's repositories - vim-lsp.git/commitdiff
add diagnostic messages display with virtual text and pointer
authorOleksiy Hryshchenko <greeschenko@gmail.com>
Mon, 27 Mar 2023 11:27:09 +0000 (14:27 +0300)
committerOleksiy Hryshchenko <greeschenko@gmail.com>
Mon, 27 Mar 2023 11:27:09 +0000 (14:27 +0300)
autoload/lsp/diag.vim
autoload/lsp/lsp.vim
autoload/lsp/options.vim
doc/lsp.txt

index 9f5d641dc73fad7771c8b771549592eddeb1dbcd..7e50fe40fe6f18e7ad784367ec15677696ffe3ec 100644 (file)
@@ -27,6 +27,11 @@ def DiagsRefreshSigns(lspserver: dict<any>, 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<any>, 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()
index c6fc4b23733b4b955bbdedc2658f3efc3f36caad..1cfb4697631fc532bbe7bf1e5f7506ad59ea6ae7 100644 (file)
@@ -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
index 3d3440fca205c3860c9addb64772c99eb0afdadd..33cbffa32c0437711831039739847b6627a278c3 100644 (file)
@@ -36,6 +36,8 @@ export var lspOptions: dict<any> = {
   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
index bb41fd9f4269e5fa202f124a6f6d2d1abc473eca..39fb8c3304d8d58155d6e61ab0e0b4a5378a0a27 100644 (file)
@@ -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.