ultisnips icon indicating copy to clipboard operation
ultisnips copied to clipboard

Strange behavior when autoexpand option finds a bracket

Open lygamac opened this issue 4 years ago • 8 comments

Here's the code in the snippets:

snippet \begin "begin{arg}" bA
\\begin\{${1}}
${0:${VISUAL}}
\\end\{$1}
endsnippet

And therefore, when I type \begin at the start of the line, the following code is expected. (Note that I represents the cursor location):

\begin{I}

\end{}

However, I got this:

\beginI}

\end{}

The open bracket disappears being escaped or not. But if the auto-expand option is disabled and expanded with tab, the bracket still appears:

\begin{I}

\end{}

What I tried:

When having the following code:

\begin}I

And by deleting the closing brackets (so the auto-expand option is triggered, without tab), I still get the opening bracket:

\begin{I}

\end{}

Change the snippet to either of the case below:

snippet \begin "begin{arg}" bA
\\begin\{ ${1}}
${0:${VISUAL}}
\\end\{$1}
endsnippet
snippet \begin "begin{arg}" bA
\\begin\{}${1}
${0:${VISUAL}}
\\end\{$1}
endsnippet

Gives:

\begin{ I}

\end{}
\begin{}I

\end{}

Respectively


Conclusion: The auto-expand option omits a bracket if the last trigger word is typed and the cursor location is just next to the opening brackets

OS: Arch Linux 5.6.11
vim version: NeoVim 0.4.3
Python 3 version inside vim: Python 3.8.2
UltiSnips version: Master branch git as May 5th 2020

The problem seems to be a compatibility issue with YouCompleateMe

lygamac avatar May 10 '20 08:05 lygamac

I have the same problem, for example:

snippet ilger "polyglossia -> inline german" i
\\textgerman{$1} $0
endsnippet

works (manually pressing the tab key) but:

snippet ilger "polyglossia -> inline german" iA
\\textgerman{$1} $0
endsnippet

yields ilger}

OS: Win10 x64 v1909
Vim: GVim v8.2.318
Python: 3.8.2
UltiSnips: updated today (13.05.2020.)

EDIT: Adding {} between { and $1 "solves" the problem (at least in LaTeX) :

snippet ilger "polyglossia -> inline german" iA
\\textgerman{{}$1} $0
endsnippet

i.e. you would get something like this (.tex source file) : This is some text.{}Hier ist ein deutscher Satz. but in the output (pdf file), the {} would be ignored.

Whitebeard0 avatar May 13 '20 14:05 Whitebeard0

@Whitebeard0 It works but lacks aesthetic. I found a better solution for this problem, it's to use coc-snippets, compatible with UltiSnips snippets, and the current bug isn't present.

But unfortunately, coc-snippets is unable to run the python commands that some snippets used.

It supposed to support gvim too, you can check it out here: https://github.com/neoclide/coc.nvim https://github.com/neoclide/coc-snippets

lygamac avatar May 14 '20 19:05 lygamac

The problem seems to occur when the snippet trigger is longer than 2 characters.

The following example works:

snippet ig "description" iA
\\textgerman{$1} $0
endsnippet

but replacing the trigger ig with igr or ilger (example above) breaks the snippet.

Also, if I replace the trigger \begin with a two-character trigger, for example bg, the example from @lygamac also works:

snippet bg "begin{arg}" bA
\\begin\{${1}}
${0:${VISUAL}}
\\end\{$1}
endsnippet

Whitebeard0 avatar May 19 '20 13:05 Whitebeard0

This bug is really wired and annoying.

sillybun avatar May 22 '20 03:05 sillybun

I managed to fix my problem by making the snippet a regular expression i.e.

snippet "ilger" "polyglossia -> inline german" irA
\\textgerman{$1} $0
endsnippet

but that does not solve the example from the original post.

@lygamac Does the following work for you? (the trigger is \beginnn instead of \begin)

snippet \beginnn "begin{arg}" bA
\\begin{${1}}
${0:${VISUAL}}
\\end{$1}
endsnippet

Whitebeard0 avatar May 22 '20 15:05 Whitebeard0

@Whitebeard0 No luck, with YCM it still fails to get the bracket. When using any other complete engines it works without problem.

lygamac avatar May 25 '20 13:05 lygamac

@lygamac Is this behavior not a bug of ultisnips but of YCM?

sillybun avatar May 25 '20 15:05 sillybun

@sillybun It's seems to be a compatibility (or, rarely, performance) issue and I cannot confirm you which one.

lygamac avatar May 25 '20 16:05 lygamac