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

Some error in ci{ game #136

Open
deeperlearner opened this issue Apr 3, 2024 · 2 comments
Open

Some error in ci{ game #136

deeperlearner opened this issue Apr 3, 2024 · 2 comments

Comments

@deeperlearner
Copy link

The error come out sometimes in the ci{ game:

Error executing vim.schedule lua callback: ...pack/packer/start/vim-be-good/lua/vim-be-good/buffer.lua:103: Unexpected type
stack traceback:
        [C]: in function 'nvim_buf_set_lines'
        ...pack/packer/start/vim-be-good/lua/vim-be-good/buffer.lua:103: in function 'render'
        ...packer/start/vim-be-good/lua/vim-be-good/game-runner.lua:305: in function 'run'
        ...packer/start/vim-be-good/lua/vim-be-good/game-runner.lua:245: in function ''
        vim/_editor.lua: in function <vim/_editor.lua:0>

Neovim Version: v0.9.5

@MannyC
Copy link

MannyC commented Apr 3, 2024

I don't want to fix this because I don't know exactly how it was supposed to work, but this error is because the lines table being passed to nvim_buf_set_lines sometimes has something at the zeroth index. This has something to do with CiRound:Render interacting getRandomInsertionLocation but it's not clear to me how this was actually supposed to work (for instance I can't tell if gameLineCount is supposed to include the instructions or not, at 20 it's too low to include them but linesAfterInstructions = gameLineCount - #instructions seems to imply that they are included).

On the plus side I learned a little about Lua.

@roguecat0
Copy link

I replace the vim.api.nvim_buf_set_lines(self.bufh, idx, idx + #lines, false, lines) line with this small snippet that shifts by 1 if the table starts from 0.

    local new_lines = {}
    if lines[0] ~= nil then
        new_lines[#new_lines+1] = lines[0]
        for i=1,#lines do
            new_lines[#new_lines+1] = lines[i]
        end
    else
        new_lines = lines
    end
    vim.api.nvim_buf_set_lines(self.bufh, idx, idx + #new_lines, false, new_lines)

It's pretty dirty but it works.

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

No branches or pull requests

3 participants