: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()
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
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
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*
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:
*: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
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*