Skip to content

Commit

Permalink
auto: do not create anonymous snippet
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bhcleek committed Nov 19, 2023
1 parent 1401b57 commit b5785d3
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions autoload/go/auto.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b5785d3

Please sign in to comment.