]> Sergey Matveev's repositories - vim-lsp.git/commitdiff
Adds option to align diagnostics virtual text
authorberggeist <24396556+berggeist@users.noreply.github.com>
Sun, 16 Apr 2023 16:19:46 +0000 (18:19 +0200)
committerberggeist <24396556+berggeist@users.noreply.github.com>
Sun, 16 Apr 2023 16:19:46 +0000 (18:19 +0200)
autoload/lsp/diag.vim
autoload/lsp/options.vim
doc/lsp.txt

index 1d28a40e0d00200cf94cd4adb89663a855fdbbc2..dd1b422d134618955b4afad92cef2d4e0a471082 100644 (file)
@@ -116,6 +116,19 @@ def DiagSevToInlineHLName(severity: number): string
   return typeMap[severity - 1]
 enddef
 
+def DiagSevToSymbolText(severity: number): string
+  var typeMap: list<string> = [
+    opt.lspOptions.diagSignErrorText,
+    opt.lspOptions.diagSignWarningText,
+    opt.lspOptions.diagSignInfoText,
+    opt.lspOptions.diagSignHintText
+  ]
+  if severity > 4
+    return opt.lspOptions.diagSignHintText
+  endif
+  return typeMap[severity - 1]
+enddef
+
 # Refresh the placed diagnostics in buffer 'bnr'
 # This inline signs, inline props, and virtual text diagnostics
 def DiagsRefresh(bnr: number)
@@ -141,6 +154,24 @@ def DiagsRefresh(bnr: number)
     return
   endif
 
+  # Initialize default/fallback properties for diagnostic virtual text:
+  var diag_align: string = 'above'
+  var diag_wrap: string = 'truncate'
+  var diag_symbol: string = '┌─'
+  var diag_padding: number = 0
+
+  if opt.lspOptions.diagVirtualTextAlign ==? 'below'
+    diag_align = 'below'
+    diag_wrap = 'truncate'
+    diag_symbol = '└─'
+    diag_padding = 0
+  elseif opt.lspOptions.diagVirtualTextAlign ==? 'after'
+    diag_align = 'after'
+    diag_wrap = 'wrap'
+    diag_symbol = 'E>'
+    diag_padding = 3
+  endif
+
   var signs: list<dict<any>> = []
   var diags: list<dict<any>> = diagsMap[bnr].sortedDiagnostics
   for diag in diags
@@ -162,14 +193,24 @@ def DiagsRefresh(bnr: number)
       endif
 
       if opt.lspOptions.showDiagWithVirtualText
+
         var padding = diag.range.start.character
         if padding > 0
           padding = strdisplaywidth(getline(diag.range.start.line + 1)[ : diag.range.start.character - 1])
         endif
+
+        var symbol = diag_symbol
+
+        if diag_align ==? 'after'
+          padding = diag_padding
+          symbol = DiagSevToSymbolText(diag.severity)
+        endif
+
         prop_add(lnum, 0, {bufnr: bnr,
                            type: 'LspDiagVirtualText',
-                           text: $'┌─ {diag.message}',
-                           text_align: 'above',
+                           text: $'{symbol} {diag.message}',
+                           text_align: diag_align,
+                           text_wrap: diag_wrap,
                            text_padding_left: padding})
       endif
     catch /E966\|E964/ # Invalid lnum | Invalid col
index 3a6e75331247201daffea579f6d55476f90a120c..ef708ee09dcc3cc2a57fd9d7bf72263498a23ae6 100644 (file)
@@ -37,6 +37,9 @@ export var lspOptions: dict<any> = {
   # If a snippet plugin is going to apply the text edits, then set this to
   # false to avoid applying the text edits twice.
   completionTextEdit: true,
+  # Alignment of virtual diagnostic text, when showDiagWithVirtualText is true
+  # Allowed values: 'above' | 'below' | 'after' (default is 'above')
+  diagVirtualTextAlign: 'above',
   # instead of the signature
   noDiagHoverOnLine: true,
   # Suppress adding a new line on completion selection with <CR>
index c472668eee0e96b9806331b3ac0ccb09b2b6ef25..0446b1db2a5bfc09b350eb5645f5a1c61012df69 100644 (file)
@@ -416,6 +416,11 @@ diagSignInfoText        |String| option. Change diag sign text for info
                                                *lsp-opt-diagSignWarningText*
 diagSignWarningText     |String| option. Change diag sign text for warnings
                         By default 'W>',
+                                               *lsp-opt-diagVirtualTextAlign*
+diagVirtualTextAlign   |String| option.   Alignment of diagnostics messages
+                       if |lsp-opt-showDiagWithVirtualText| is set to true. 
+                       Allowed values are 'above', 'below' or 'after'
+                       By default this is set to 'above',
                                                *lsp-opt-echoSignature*
 echoSignature          |Boolean| option.  In insert mode, echo the current
                        symbol signature instead of showing it in a popup.