autoload/lsp/lspserver.vim | 22 +++++++++++++++++++++- autoload/lsp/options.vim | 4 +++- doc/lsp.txt | 31 +++++++++++++++++-------------- diff --git a/autoload/lsp/lspserver.vim b/autoload/lsp/lspserver.vim index de7b22cc67bb2cac4becf76632952730aa74eacb..101c03faeca70c21307867471e927b204fae809e 100644 --- a/autoload/lsp/lspserver.vim +++ b/autoload/lsp/lspserver.vim @@ -127,7 +127,7 @@ completion: { completionItem: { documentationFormat: ['plaintext', 'markdown'], resolveSupport: {properties: ['detail', 'documentation']}, - snippetSupport: false + snippetSupport: opt.lspOptions.snippetSupport }, completionItemKind: {valueSet: range(1, 25)} }, @@ -545,6 +545,21 @@ endif return kindMap[kind] enddef +# Remove all the snippet placeholders from 'str' and return the value. +# Based on a similar function in the vim-lsp plugin. +def MakeValidWord(str_arg: string): string + var str = substitute(str_arg, '\$[0-9]\+\|\${\%(\\.\|[^}]\)\+}', '', 'g') + str = substitute(str, '\\\(.\)', '\1', 'g') + var valid = matchstr(str, '^[^"'' (<{\[\t\r\n]\+') + if empty(valid) + return str + endif + if valid =~# ':$' + return valid[: -2] + endif + return valid +enddef + # process the 'textDocument/completion' reply from the LSP server # Result: CompletionItem[] | CompletionList | null def CompletionReply(lspserver: dict, cItems: any) @@ -568,6 +583,11 @@ elseif item->has_key('insertText') d.word = item.insertText else d.word = item.label + endif + if item->get('insertTextFormat', 1) == 2 + # snippet completion. Needs a snippet plugin to expand the snippet. + # Remove all the snippet placeholders + d.word = MakeValidWord(d.word) endif d.abbr = item.label d.dup = 1 diff --git a/autoload/lsp/options.vim b/autoload/lsp/options.vim index 5308e83c0482d7754f34c2bcf62da0dd1a193599..35dd4af7780401e716e7612df738c38883f1da5d 100644 --- a/autoload/lsp/options.vim +++ b/autoload/lsp/options.vim @@ -37,7 +37,9 @@ showDiagInPopup: true, # Don't print message when a configured language server is missing. ignoreMissingServer: false, # Use a floating menu to show the code action menu instead of asking for input - usePopupInCodeAction: false + usePopupInCodeAction: false, + # enable snippet completion support + snippetSupport: false } # set LSP options from user provided options diff --git a/doc/lsp.txt b/doc/lsp.txt index 71bbdc6b67a87a7ecd54239865b9c5ee88a87aac..007e684fd033bbdf624ed2de5bf3af71aad0b83d 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 26, 2022 +Last change: Oct 30, 2022 ============================================================================== *lsp-license* @@ -238,40 +238,43 @@ 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. autoPopulateDiags Automatically populate the location list with diagnostics from the LSP server. By default this is set to false. +echoSignature In insert mode, echo the current symbol signature + instead of showing it in a popup. By default this is + set to false. +ignoreMissingServer Do not print a missing language server executable. + By default this is set to false. keepFocusInReferences Focus on the location list window after LspShowReferences. By default this is set to false. +noDiagHoverOnLine Suppress diagnostic hover from appearing when + the mouse is over the line instead of the signature. + By default this is set to true. noNewlineInCompletion Suppress adding a new line on completion selection with . By default this is set to false. -outlineWinSize Outline window size, by default this is 20. outlineOnRight Open the outline window on the right side, by default this is false. -noDiagHoverOnLine Suppress diagnostic hover from appearing when - 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. +outlineWinSize Outline window size, by default this is 20. 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. +showDiagOnStatusLine Show a diagnostic message on a status line. + 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. +snippetSupport Enable snippet completion support. Need a snippet + completion plugin like vim-vsnip. By default this is + set to false. usePopupInCodeAction When using the |:LspCodeAction| command to display the code action for the current line, use a popup menu instead of echoing. - By default this is set to false. -ignoreMissingServer Do not print a missing language server executable. By default this is set to false. For example, to disable the automatic placement of signs for the LSP