From d74f373afa0419507221fdb0f04be5476e0734f1 Mon Sep 17 00:00:00 2001 From: Yegappan Lakshmanan Date: Sun, 14 Nov 2021 18:38:33 -0800 Subject: [PATCH] Add missing lspoptions.vim and add an option for auto highlighting LSP diagnostics --- autoload/buf.vim | 6 ++++++ autoload/handlers.vim | 2 +- autoload/lspoptions.vim | 18 ++++++++++++++++++ doc/lsp.txt | 27 ++++++++++++++++++++++++++- 4 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 autoload/lspoptions.vim diff --git a/autoload/buf.vim b/autoload/buf.vim index fb2309c..92ab8a4 100644 --- a/autoload/buf.vim +++ b/autoload/buf.vim @@ -1,5 +1,7 @@ vim9script +import lspOptions from './lspoptions.vim' + def s:lspDiagSevToSignName(severity: number): string var typeMap: list = ['LspDiagError', 'LspDiagWarning', 'LspDiagInfo', 'LspDiagHint'] @@ -12,6 +14,10 @@ enddef # New LSP diagnostic messages received from the server for a file. # Update the signs placed in the buffer for this file export def LspDiagsUpdated(lspserver: dict, bnr: number) + if !lspOptions.autoHighlightDiags + return + endif + if bnr == -1 || !lspserver.diagsMap->has_key(bnr) return endif diff --git a/autoload/handlers.vim b/autoload/handlers.vim index 5cf9d12..0c78342 100644 --- a/autoload/handlers.vim +++ b/autoload/handlers.vim @@ -140,7 +140,7 @@ def s:processSignaturehelpReply(lspserver: dict, req: dict, reply: dic startcol = text->stridx(label) endif endif - if lspOptions.showSignature + if lspOptions.echoSignature echon "\r\r" echon '' echon strpart(text, 0, startcol) diff --git a/autoload/lspoptions.vim b/autoload/lspoptions.vim new file mode 100644 index 0000000..ab7daa0 --- /dev/null +++ b/autoload/lspoptions.vim @@ -0,0 +1,18 @@ +vim9script + +# LSP plugin options +# User can override these by calling the lsp#setOptions() function. +export var lspOptions: dict = { + # In insert mode, complete the current symbol automatically + # Otherwise, use omni-completion + autoComplete: true, + # In normal mode, highlight the current symbol automatically + autoHighlight: false, + # In insert mode, show the current symbol signature automatically + showSignature: true, + # In insert mode, echo the current symbol signature in the status line + # instead of showing it in a popup + echoSignature: false, + # Automatically highlight diagnostics messages from LSP server + autoHighlightDiags: true +} diff --git a/doc/lsp.txt b/doc/lsp.txt index 5246d99..6e60664 100644 --- a/doc/lsp.txt +++ b/doc/lsp.txt @@ -2,7 +2,7 @@ Author: Yegappan Lakshmanan (yegappan AT yahoo DOT com) For Vim version 8.2.2342 and above -Last change: Nov 13, 2021 +Last change: Nov 14, 2021 ============================================================================== *lsp-license* @@ -172,6 +172,31 @@ To add a LSP server, the following information is needed: The LSP servers are added using the lsp#addServer() function. This function accepts a list of LSP servers with the above information. + *lsp-options* +Some of the LSP plugin features can be enabled or disabled by using the +lsp#setOptions() function. This function accepts a dictionary argument with the +following optional items: + + autoComplete In insert mode, automatically complete the current + symbol. Otherwise use omni-completion. By default this + is set to true. + autoHighlight In normal mode, automatically highlight all the + occurrences of the symbol under the cursor. By default + this is set to false. + showSignature In insert mode, automatically show the current symbol + signature in a popup. By default this is set to true. + echoSignature In insert mode, echo the current symbol signature + instead of showing it in a popup. By default this is + set to false. + autoHighlightDiags Automatically place signs on the lines with a + diagnostic message from the LSP server. By default + this is set to true. + +For example, to disable the automatic placement of signs for the LSP +diagnostic messages, you can add the following line to your .vimrc file: + + call lsp#setOptions({'autoHighlightDiags': v:false}) + ============================================================================== 5. Commands *lsp-commands* -- 2.48.1