pwntester / octo.nvim

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

Error when using "next_comment" in PR view #275

Closed ldelossa closed 2 years ago

ldelossa commented 2 years ago

Issue Description

Type: bug report

Describe what happened (or what feature you want)

When using the navigation.next_comment method in the PR view an error is returned:

E5108: Error executing lua /home/louis/.config/nvim/after/octo.nvim/lua/octo/utils.lua:744: Expected Lua number                          
stack traceback:                                                                                                                         
        [C]: in function 'nvim_buf_get_extmarks'                                                                                         
        /home/louis/.config/nvim/after/octo.nvim/lua/octo/utils.lua:744: in function 'get_sorted_comment_lines'                          
        ...uis/.config/nvim/after/octo.nvim/lua/octo/navigation.lua:101: in function 'next_comment'                                      
        ...louis/.config/nvim/after/octo.nvim/lua/octo/mappings.lua:80: in function <...louis/.config/nvim/after/octo.nvim/lua/octo/mappi
ngs.lua:79>                                                                                                                              
        ...louis/.config/nvim/after/octo.nvim/lua/octo/mappings.lua:9: in function 'on_keypress'                                         
        [string ":lua"]:1: in main chunk 

Describe what you expected to happen

You open a PR and then use the navigation.next_comment method. It does not move to the next comment nor does it gracefully handle the error case.

How to reproduce it (as minimally and precisely as possible)

  1. Open PR
  2. Use next_commentfion
  3. see error

Tell us your environment

Fedora 35, Neovim nightly.

ldelossa commented 2 years ago

The ultimate issue here is the function M.get_sorted_lines is receiving a nil bufnr and it does not get checked.

The following diff seems to fix the issue. LMK if this looks correct

diff --git a/lua/octo/navigation.lua b/lua/octo/navigation.lua
index b01e2c8..888ad25 100644
--- a/lua/octo/navigation.lua
+++ b/lua/octo/navigation.lua
@@ -98,7 +98,7 @@ function M.next_comment()
   if buffer.kind then
     local cursor = vim.api.nvim_win_get_cursor(0)
     local current_line = cursor[1]
-    local lines = utils.get_sorted_comment_lines()
+    local lines = utils.get_sorted_comment_lines(bufnr)
     if not buffer:isReviewThread() then
       -- skil title and body
       lines = utils.tbl_slice(lines, 3, #lines)
@@ -131,7 +131,7 @@ function M.prev_comment()
   if buffer.kind then
     local cursor = vim.api.nvim_win_get_cursor(0)
     local current_line = cursor[1]
-    local lines = utils.get_sorted_comment_lines()
+    local lines = utils.get_sorted_comment_lines(bufnr)
     lines = utils.tbl_slice(lines, 3, #lines)
     if not lines or not current_line then
       return
pwntester commented 2 years ago

Thanks for reporting the issue and for the patch!

ldelossa commented 2 years ago

Anytime :)