pwntester / octo.nvim

Edit and review GitHub issues and pull requests from the comfort of your favorite editor
MIT License
2.24k stars 124 forks source link

fix(file-entry): ignore possible extmark out of bounds error #522

Closed Danthewaann closed 3 months ago

Danthewaann commented 3 months ago

Describe what this PR does / why we need it

Fixes a bug where attempting to review a specific commit fails if the comment contains comments due to us attempting to add an extmark to a line that is out of bounds, which results in the following error:

Error executing vim.schedule lua callback: ...hare/nvim/lazy/octo.nvim/lua/octo/reviews/file-entry.lua:394: Invalid 'line': out of range
stack traceback:
        [C]: in function 'nvim_buf_set_extmark'
        ...hare/nvim/lazy/octo.nvim/lua/octo/reviews/file-entry.lua:394: in function 'place_signs'
        ...hare/nvim/lazy/octo.nvim/lua/octo/reviews/file-entry.lua:266: in function 'load_buffers'
        ...al/share/nvim/lazy/octo.nvim/lua/octo/reviews/layout.lua:116: in function 'set_file'
        ...al/share/nvim/lazy/octo.nvim/lua/octo/reviews/layout.lua:136: in function 'update_files'
        ...ocal/share/nvim/lazy/octo.nvim/lua/octo/reviews/init.lua:120: in function 'callback'
        ...hare/nvim/lazy/octo.nvim/lua/octo/model/pull-request.lua:137: in function 'cb'
        ...ck/.local/share/nvim/lazy/octo.nvim/lua/octo/gh/init.lua:160: in function ''
        vim/_editor.lua: in function <vim/_editor.lua:0>

In this case we can ignore this error to be able to at least view the changes in the commit.

Also this PR fixes duplicate extmarks for comments that was getting printed when a comment thread contained more than 1 comment:

Before:

image

After:

image

Does this pull request fix one issue?

https://github.com/pwntester/octo.nvim/issues/440

Describe how you did it

Added strict = false to the vim.api.nvim_buf_set_extmark call opts to ignore possible line out of bounds errors.

Describe how to verify it

Attempt to review a commit that contains comments before this change to ensure it throws the error described above. Then attempt to review a commit that contains comments with this change applied and verify that you can review to commit changes without any errors being raised.

Special notes for reviews

pwntester commented 3 months ago

Thanks!