-
-
Notifications
You must be signed in to change notification settings - Fork 690
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
pynvim.api.nvim.NvimError: b'Index out of bounds' #1041
Comments
too little information to reproduce the problem. When does this happen? What is your vimrc? How do you trigger the traceback? |
This happens because the vim object that's injected in the python context does not behave like the Neovim vim object does. Iterating through the buffer in Ultisnips fails, while it succeeds using the Neovim API (outside of the Ultisnips conext). This call fails for line in snip.buffer:
vim.command(f"echom '{line}'") This call succeeds: for line in snip.buffer[0:-1]:
vim.command(f"echom '{line}'") Snippet globals
Snippet
Error log
|
I worked around this by using the vim buffer directly and tricking the Ultisnips wrapper that throws errors when you touch the vim buffer Add the following code at the end of your python snippet helper snip.buffer._change_tick = int(vim.eval("b:changedtick")) |
@danihodovic So this is Neovim only then? I cannot help then. This issue was closed due to it only affecting 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. |
Yeah and that's understandable. For future reference the workaround I use is to modify vim buffer object directly. Using a decorator to bypass the error Ultisnips throws when modifying the buffer directly def bypass_ultisnips_error(func):
def wrapper(*args, **kwargs):
result = func(*args, **kwargs)
snip.buffer._change_tick = int(vim.eval("b:changedtick"))
return result
return wrapper Usage @bypass_ultisnips_error
def clean_imports():
buffer = vim.current.buffer
# modify buffer An example snippet with Python post_jump post_jump "clean_imports()"
snippet mysnippet "class S(serializers.Serializer)"
endsnippet |
This is easy to reproduce. Edit ~/.vim/pythonx/test.py and paste: import vim
import UltiSnips.vim_helper as helper
def dump(b):
for line in b:
print(line.upper())
# This works fine in both nvim and vim.
dump(vim.current.buffer)
# In nvim, the iteration fails with "pynvim.api.common.NvimError: Index out of bounds"
dump(helper.VimBuffer()) Run
Seems like Ah, seems this was reported long ago but not fixed portably: neovim/pynvim#128 |
Fix SirVer#1041: iterating over snip.buffer fails in neovim. Use __iter__() to defer iteration of a buffer to the underlying object. Test * Run this code in neovim and vim: import vim import UltiSnips.vim_helper as helper def dump(b): for line in b: print(line.upper()) # This works fine in both nvim and vim. dump(vim.current.buffer) # In nvim, the iteration previously failed with "pynvim.api.common.NvimError: Index out of bounds" dump(helper.VimBuffer())
Fix SirVer#1041: iterating over snip.buffer fails in neovim. Use __iter__() to defer iteration of a buffer to the underlying object. Test * Run this code in neovim and vim: import vim import UltiSnips.vim_helper as helper def dump(b): for line in b: print(line.upper()) # This works fine in both nvim and vim. dump(vim.current.buffer) # In nvim, the iteration previously failed with "pynvim.api.common.NvimError: Index out of bounds" dump(helper.VimBuffer())
Following is the full stack trace:
The text was updated successfully, but these errors were encountered: