]> Sergey Matveev's repositories - vim-lsp.git/commitdiff
Use a popup window by default to display the diag message when using the LspDiagCurre...
authorYegappan Lakshmanan <yegappan@yahoo.com>
Wed, 26 Oct 2022 14:23:58 +0000 (07:23 -0700)
committerYegappan Lakshmanan <yegappan@yahoo.com>
Wed, 26 Oct 2022 14:23:58 +0000 (07:23 -0700)
autoload/lsp/diag.vim
autoload/lsp/options.vim
doc/lsp.txt

index 6afe3e2454cc0181d77c3e43f88e3a2ebe8a1799..bd871660b20d2e4b2e82fc2d18e7b5041ae3be88 100644 (file)
@@ -199,6 +199,33 @@ export def ShowAllDiags(lspserver: dict<any>): void
   :lopen
 enddef
 
+# Display the message of 'diag' in a popup window right below the position in
+# the diagnostic message.
+def ShowDiagInPopup(diag: dict<any>)
+  var dlnum = diag.range.start.line + 1
+  var ltext = getline(dlnum)
+  var dlcol = byteidx(ltext, diag.range.start.character + 1)
+  if dlcol < 1
+    # The column is outside the last character in line.
+    dlcol = ltext->len() + 1
+  endif
+  var d = screenpos(0, dlnum, dlcol)
+  if d->empty()
+    # If the diag position cannot be converted to Vim lnum/col, then use
+    # the current cursor position
+    d = {row: line('.'), col: col('.')}
+  endif
+
+  # Display a popup right below the diagnostics position
+  var ppopts = {}
+  ppopts.pos = 'topleft'
+  ppopts.line = d.row + 1
+  ppopts.col = d.col
+  ppopts.moved = 'any'
+  ppopts.wrap = false
+  popup_create(diag.message->split("\n"), ppopts)
+enddef
+
 # Show the diagnostic message for the current line
 export def ShowCurrentDiag(lspserver: dict<any>)
   var bnr: number = bufnr()
@@ -208,12 +235,10 @@ export def ShowCurrentDiag(lspserver: dict<any>)
     util.WarnMsg('No diagnostic messages found for current line')
   else
     if opt.lspOptions.showDiagInPopup
-      popup_atcursor(
-        diag.message,
-        {
-          moved: 'any'
-        })
+      # Display the diagnostic message in a popup window.
+      ShowDiagInPopup(diag)
     else
+      # Display the diagnostic message in the status message area
       echo diag.message
     endif
   endif
index cf81bfca05a68759442d272394273a06c1c92c3d..8e98643269052d99d50eacc80b4be0fa5683ac7e 100644 (file)
@@ -32,10 +32,10 @@ export var lspOptions: dict<any> = {
   noDiagHoverOnLine: true,
   # Show a diagnostic message on a status line
   showDiagOnStatusLine: false,
-  # Don't print message when a configured language server is missing.
-  ignoreMissingServer: false,
   # Make diagnostics show in a popup instead of echoing
-  showDiagInPopup: false
+  showDiagInPopup: true,
+  # Don't print message when a configured language server is missing.
+  ignoreMissingServer: false
 }
 
 # set LSP options from user provided options
index 44f4a35c517f2cb71ecd34f4a1ba7549285f3c16..751c77ad13d1025f63d1ba6af7c3bbcdfd2623c5 100644 (file)
@@ -2,7 +2,7 @@
 
 Author: Yegappan Lakshmanan  (yegappan AT yahoo DOT com)
 For Vim version 9.0 and above
-Last change: Oct 24, 2022
+Last change: Oct 26, 2022
 
 ==============================================================================
                                                *lsp-license*
@@ -262,11 +262,13 @@ noDiagHoverOnLine Suppress diagnostic hover from appearing when
                        By default this is set to true.
 showDiagOnStatusLine   Show a diagnostic message on a status line.
                        By default this is set to false.
+showDiagInPopup                When using the |:LspDiagCurrent| command to display
+                       the diagnostic message for the current line, use a
+                       popup window to display the message instead of
+                       echoing in the status area.  By default this is set to
+                       true.
 ignoreMissingServer    Do not print a missing language server executable.
                        By default this is set to false.
-showDiagInPopup                Use a popup to display server diagnostics instead of
-                       echoing.
-                       By default this is set to false.
 
 For example, to disable the automatic placement of signs for the LSP
 diagnostic messages, you can add the following line to your .vimrc file:
@@ -395,7 +397,10 @@ diagnostic messages, you can add the following line to your .vimrc file:
 
                                                *:LspDiagCurrent*
 :LspDiagCurrent                Displays the diagnostic message (if any) for the
-                       current line.
+                       current line.  If the option 'showDiagInPopup' is set
+                       to v:true (default), then the message is displayed in
+                       a popup window.  Otherwise the message is displayed in
+                       the status message area.
 
                                                *:LspDiagHighlightEnable*
 :LspDiagHighlightEnable        Enable highlighting lines with a diagnostic message
@@ -667,6 +672,11 @@ To display the diagnostic message for the current line in the status area, you
 can set the 'showDiagOnStatusLine' option to v:true.  By default, this option
 is set to v:false.
 
+By default, the |:LspDiagCurrent| command displays the diagnostic message for
+the current line in a popup window.  To display the message in the status
+message area instead, you can set the 'showDiagInPopup' option to false.  By
+default this is set to true.
+
 ==============================================================================
 8. Autocommands                                                *lsp-autocmds*