From: Yegappan Lakshmanan Date: Sun, 30 Oct 2022 18:48:04 +0000 (-0700) Subject: Add support for snippet completion. Tested using the vim-vsnip plugin X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=b09afad1cd6e9396f470ab3084b9bc71efe07c33;p=vim-lsp.git Add support for snippet completion. Tested using the vim-vsnip plugin --- diff --git a/autoload/lsp/lspserver.vim b/autoload/lsp/lspserver.vim index de7b22c..101c03f 100644 --- a/autoload/lsp/lspserver.vim +++ b/autoload/lsp/lspserver.vim @@ -127,7 +127,7 @@ def InitServer(lspserver: dict) completionItem: { documentationFormat: ['plaintext', 'markdown'], resolveSupport: {properties: ['detail', 'documentation']}, - snippetSupport: false + snippetSupport: opt.lspOptions.snippetSupport }, completionItemKind: {valueSet: range(1, 25)} }, @@ -545,6 +545,21 @@ def LspCompleteItemKindChar(kind: number): string 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) @@ -569,6 +584,11 @@ def CompletionReply(lspserver: dict, cItems: any) 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 if item->has_key('kind') diff --git a/autoload/lsp/options.vim b/autoload/lsp/options.vim index 5308e83..35dd4af 100644 --- a/autoload/lsp/options.vim +++ b/autoload/lsp/options.vim @@ -37,7 +37,9 @@ export var lspOptions: dict = { # 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 71bbdc6..007e684 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 26, 2022 +Last change: Oct 30, 2022 ============================================================================== *lsp-license* @@ -238,41 +238,44 @@ autoComplete In insert mode, automatically complete the current 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 diagnostic messages, you can add the following line to your .vimrc file: