autoload/lsp/diag.vim | 35 ++++++++++++++++++++++++++++++----- autoload/lsp/options.vim | 6 +++--- doc/lsp.txt | 20 +++++++++++++++----- diff --git a/autoload/lsp/diag.vim b/autoload/lsp/diag.vim index 6afe3e2454cc0181d77c3e43f88e3a2ebe8a1799..bd871660b20d2e4b2e82fc2d18e7b5041ae3be88 100644 --- a/autoload/lsp/diag.vim +++ b/autoload/lsp/diag.vim @@ -199,6 +199,33 @@ :lopen enddef +# Display the message of 'diag' in a popup window right below the position in +# the diagnostic message. +def ShowDiagInPopup(diag: dict) + 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) var bnr: number = bufnr() @@ -208,12 +235,10 @@ if diag->empty() 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 diff --git a/autoload/lsp/options.vim b/autoload/lsp/options.vim index cf81bfca05a68759442d272394273a06c1c92c3d..8e98643269052d99d50eacc80b4be0fa5683ac7e 100644 --- a/autoload/lsp/options.vim +++ b/autoload/lsp/options.vim @@ -32,10 +32,10 @@ # instead of the signature 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 diff --git a/doc/lsp.txt b/doc/lsp.txt index 44f4a35c517f2cb71ecd34f4a1ba7549285f3c16..751c77ad13d1025f63d1ba6af7c3bbcdfd2623c5 100644 --- a/doc/lsp.txt +++ b/doc/lsp.txt @@ -2,7 +2,7 @@ *lsp.txt* Language Server Protocol (LSP) Plugin for Vim9 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,10 +262,12 @@ the mouse is over the line instead of the signature. 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 @@ -395,7 +397,10 @@ the current cursor position. *: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 @@ -666,6 +671,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*