From b5785d36f08b7097f5dd9734a484717accd981c5 Mon Sep 17 00:00:00 2001 From: Billie Cleek Date: Sun, 19 Nov 2023 08:53:00 -0800 Subject: [PATCH] auto: do not create anonymous snippet Do not create an anonymous snippet if there are no placeholders, because there is no point in creating the snippet in that case and doing so breaks Ultisnip navigation when the previous completion had placeholders. Fixes #3601 --- autoload/go/auto.vim | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/autoload/go/auto.vim b/autoload/go/auto.vim index 0a2162e609..756c929066 100644 --- a/autoload/go/auto.vim +++ b/autoload/go/auto.vim @@ -35,6 +35,15 @@ function! s:ExpandSnippet() abort " the snippet may have a '{\}' in it. For UltiSnips, that should be spelled " \{}. fmt.Printf is such a snippet that can be used to demonstrate. let l:snippet = substitute(v:completed_item.word, '{\\}', '\{}', 'g') + + " If there are no placeholders in the returned text, then do not expand + " the snippet, because Ultisnip does not support nested snippets, and the + " user may already be in an expanded snippet. While this isn't foolproof, + " because there may be placeholders in the snippet, it at least solves the + " simple case. + if stridx(l:snippet, '$') == -1 + return + endif call UltiSnips#Anon(l:snippet, v:completed_item.word, '', 'i') " elseif l:engine is 'neosnippet' " " TODO(bc): make the anonymous expansion for neosnippet work