Skip to content
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

Fix out of bounds NvimError: Add iter to VimBuffer #1562

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

idbrii
Copy link
Contributor

@idbrii idbrii commented Jan 6, 2025

Fix #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())

@idbrii
Copy link
Contributor Author

idbrii commented Jan 6, 2025

Draft because I don't know how to write or run tests. (I'm on Windows.)

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())
@idbrii
Copy link
Contributor Author

idbrii commented Jan 8, 2025

I couldn't figure out the tests, so I removed it from my PR. Here's my proposed test (just guessing how to specify the contents of the buffer):

class PythonCode_IterateBuffer(_VimTest):
    snippets = ("test", """Start `!p
        snip.rv = ""
        for line in snip.buffer:
            snip.rv += "x"
        ` End""")
    buffer = """a
        b
        c
        d
        """
    keys = "test" + EX
    wanted = "Start xxxx End"

The change is simple enough that it may not warrant the test.

@idbrii idbrii marked this pull request as ready for review January 8, 2025 05:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

pynvim.api.nvim.NvimError: b'Index out of bounds'
1 participant