From 3cece7ce04a8fdb285142a0d40c6c36341dd064c Mon Sep 17 00:00:00 2001 From: Yegappan Lakshmanan Date: Wed, 26 Oct 2022 07:23:58 -0700 Subject: [PATCH] Use a popup window by default to display the diag message when using the LspDiagCurrent command --- autoload/lsp/diag.vim | 35 ++++++++++++++++++++++++++++++----- autoload/lsp/options.vim | 6 +++--- doc/lsp.txt | 20 +++++++++++++++----- 3 files changed, 48 insertions(+), 13 deletions(-) diff --git a/autoload/lsp/diag.vim b/autoload/lsp/diag.vim index 6afe3e2..bd87166 100644 --- a/autoload/lsp/diag.vim +++ b/autoload/lsp/diag.vim @@ -199,6 +199,33 @@ export def ShowAllDiags(lspserver: dict): void :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 @@ export def ShowCurrentDiag(lspserver: dict) 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 cf81bfc..8e98643 100644 --- a/autoload/lsp/options.vim +++ b/autoload/lsp/options.vim @@ -32,10 +32,10 @@ export var lspOptions: dict = { 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 44f4a35..751c77a 100644 --- a/doc/lsp.txt +++ b/doc/lsp.txt @@ -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* -- 2.48.1