SirVer / ultisnips

UltiSnips - The ultimate snippet solution for Vim. Send pull requests to SirVer/ultisnips!
GNU General Public License v3.0
7.55k stars 691 forks source link

Python interpolation not work #1537

Closed ZreXoc closed 1 year ago

ZreXoc commented 1 year ago

Expected behavior:

Python interpolation in my snippets should work as expected, and no error when running :UltiSnipsEdit!

Actual behavior: Any snippet with python not worked, though I have installed python and pynvim correctly.

And this is the output after running :UltiSnipsEdit!

Error detected while processing function UltiSnips#Edit[6]..provider#python3#Call:
line   18:
Error invoking 'python_execute' on channel 6 (python3-script-host):
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "C:\Users\zrex\AppData\Local\nvim-data\plugged\ultisnips\pythonx\UltiSnips\snippet_manager.py", line 913, in _file_to_edit
    return _select_and_create_file_to_edit(potentials)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\zrex\AppData\Local\nvim-data\plugged\ultisnips\pythonx\UltiSnips\snippet_manager.py", line 71, in _select_and_create_file_to_edit
    assert len(potentials) >= 1
           ^^^^^^^^^^^^^^^^^^^^
AssertionError

Steps to reproduce

  1. Installed UltiSnips and https://github.com/sillybun/zyt-snippet/tree/master(which contains several Latex snippets which not work)
  2. in a .tex file ,write:
    \begin{document}
    \begin{equation}
        bmat
    \end{equation}
    \end{document}
  3. press <tab> behind bmat, and nothing happends.

define of bmat is as follows in .../nvim-data/plugged/zyt-snippet/UltiSnips/mathtex.snippet (it's imported in tex.snippet):

context "math()"
snippet bmat "bmat" wm
\begin{bmatrix}${1:`!p
# add &
regex = r"(?<=\w)[ \t]+(?=\w)"
subst = r"\t&\t"
snip.rv = re.sub(regex, subst, snip.v.text, 0, re.MULTILINE)
# add \t\\\n
snip.rv = ("\t\\\\\n"+snip.mkline()).join([x.strip() for x in snip.rv.split("\n") if x])
# one line or multiple lines
if snip.v.text.count('\n') > 1:
    snip.rv = '\n' + snip.mkline() + snip.rv + '\n' + snip.mkline()
else:
    snip.rv = " " + snip.rv + " "
`}\end{bmatrix} $0
endsnippet

and snippet if doesn't work as well:

context "math()"
snippet if "if mbox and \iff" wA
`!p
if t[1] and t[1][0] == 'f':
    snip.rv = "\\if"
else:
    snip.rv = "\\mbox{if }"
`$1
endsnippet

btw, I installed coc-snippet, it doesn't support python, so I uninstalled it. I wonder if this has something to do with my problem.

SirVer commented 1 year ago

I cannot reproduce this with the information alone, please provide a fully reproducible example, ideally using the approach explained in https://github.com/SirVer/ultisnips/blob/master/CONTRIBUTING.md#reproducing-bugs or if not possible with a minimal vimrc and snippets files and an exact sequence of key strokes that trigger the bug.

Also disclaimer re Neovim and not core Vim.

Why is Neovim only best-effort?

UltiSnips maintenance is a lot of work. Reproducing bug reports is tedious, slow and error prone. The current maintainers have to limit their scope to provide a reasonable level of service to the community.

Neovim should work with any plugin that core vim works with. But in the past, Neovim support has been difficult for UltiSnips: It regularly had bugs that did not affect the core Vim distributions, i.e. Vim, gVim, MacVim, and Vim for Windows and its testing approach required a completely separate code path from core as well. Therefore, currently Neovim bugs are considered on a best effort basis.

UltiSnips is looking for an additional maintainer that is interested in bringing the Neovim level of service on par with core Vim. If you are interested in helping out, please reach out to SirVer.

ZreXoc commented 1 year ago

I tried to delete all related settings in vimrc and reinstall Ultisnips but it still not work. Sometimes the snippets work though I did nothing, which confuse me a lot, and I don't know which part I do wrong.