if has_key(lspitem, 'textEdit')
let snippet = lspitem.textEdit.newText
let snippet_trigger = lspitem.textEdit.newText
let cur_text = cur_text[: -1-len(snippet_trigger)]
return [cur_text, snippet, {'lspitem': has_lspitem}]
elseif get(lspitem, 'insertTextFormat', -1) == 2
let snippet = lspitem.insertText
let snippet_trigger = lspitem.insertText
let cur_text = cur_text[: -1-len(snippet_trigger)]
return [cur_text, snippet, {'lspitem': has_lspitem}]
endif
That solves the first issue.
There is also a second. according to the LSP documentation, $0 defines the final tab stop:
* A snippet can define tab stops and placeholders with `$1`, `$2`
* and `${3:foo}`. `$0` defines the final tab stop, it defaults to
* the end of the snippet. Placeholders with equal identifiers are linked,
* that is typing in one will update others too.
if has_key(lspitem, 'textEdit')
let snippet = lspitem.textEdit.newText
let snippet = substitute(snippet, '\$\(\d\+\)', '${\1}', 'g')
let snippet = substitute(snippet, "'", "''", 'g')
let snippet_trigger = lspitem.textEdit.newText
let cur_text = cur_text[: -1-len(snippet_trigger)]
return [cur_text, snippet, {'lspitem': has_lspitem}]
and the completion with expanding snippets works correctly. All $0, $1, etc. will be replaced by version with braces.
Do you think it is possible to fix it that way? Or maybe you have another idea?
I encountered two issues with expanding a snippet from one of the LSP servers (rust-analyzer). At first, according to the documentation (https://microsoft.github.io/language-server-protocol/specification#textDocument_completion) there are at least two ways to find what was completed:
insertText
field, but according to the documentation:textEdit
field is also possible. The rust-analyzer follows the other latter way, hence, I receive an error thatinsertText
is not in a dictionary here: https://github.com/Shougo/neosnippet.vim/blob/master/autoload/neosnippet/mappings.vim#L188 . The solution, I think would be to add checking iftextEdit
exists:That solves the first issue. There is also a second. according to the LSP documentation,
$0
defines the final tab stop:and when completion is done I receive this:
where
axis
andindex
are correct, but some garbage left at the end. Probably because the snippet ends with$0
. Based on some other solution (https://github.com/thomasfaingnaert/vim-lsp-neosnippet/blob/master/autoload/lsp_neosnippet.vim), I modified the above code in the following way:and the completion with expanding snippets works correctly. All
$0
,$1
, etc. will be replaced by version with braces. Do you think it is possible to fix it that way? Or maybe you have another idea?edit: fix bug in the last snippet.