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 attempting to view review comments #314

Closed DexterShepherd closed 2 years ago

DexterShepherd commented 2 years ago

Hello, thanks for the great plugin!

Issue Description

Type: bug report

Describe what happened (or what feature you want)

I see this error when moving the cursor over an inline comment in a PR.

Error detected while processing CursorMoved Autocommands for "*":
Error executing lua callback: ...nvim/plugged/octo.nvim/lua/octo/reviews/thread-panel.lua:99: bad argument #6 to 'format' (number expected, got userdata)
stack traceback:
        [C]: in function 'format'
        ...nvim/plugged/octo.nvim/lua/octo/reviews/thread-panel.lua:99: in function 'create_thread_buffer'
        ...nvim/plugged/octo.nvim/lua/octo/reviews/thread-panel.lua:64: in function 'show_review_threads'
        ...local/share/nvim/plugged/octo.nvim/lua/octo/autocmds.lua:42: in function <...local/share/nvim/plugged/octo.nvim/lua/octo/autocmds.lua:41>v

Describe what you expected to happen

To be able to view PR comments

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

  1. :Octo review start
  2. Place cursor over a line in the diff containing a review comment

I've reprod this with multiple pull requests / repos.

Tell us your environment

macos 12.4 nvim 0.7.2

Anything else we need to know?

Screen Shot 2022-07-30 at 1 03 05 PM

Minimal init.vim

call plug#begin(stdpath('data') . '/plugged')

" octo start
Plug 'nvim-lua/plenary.nvim'
Plug 'nvim-telescope/telescope.nvim', { 'branch': '0.1.x' }
Plug 'kyazdani42/nvim-web-devicons'
Plug 'pwntester/octo.nvim'
Plug 'nvim-treesitter/nvim-treesitter', {'do': ':TSUpdate'}
" octo stop

call plug#end()

lua << EOF
  require"octo".setup()
  require'nvim-web-devicons'.setup {
   -- your personnal icons can go here (to override)
   -- you can specify color or cterm_color instead of specifying both of them
   -- DevIcon will be appended to `name`
   -- globally enable default icons (default to false)
   -- will get overriden by `get_icons` option
   default = true;
  }
EOF
aaronhallaert commented 2 years ago

Had the same issue found the following by printing the threads[1] table:

... ["originalStartLine"] = vim.NIL, ["line"] = 13,["originalLine"] = 13,["startLine"] = 13, ...

So for some comments originalStartLine is vim.NIL

Currently fixed it locally by overriding the line value

-- octo.nvim/lua/octo/reviews/thread-panel.lua
function M.create_thread_buffer(threads, repo, number, side, path)
  local current_review = require("octo.reviews").get_current_review()
  if not vim.startswith(path, "/") then
    path = "/" .. path
  end

  local line = threads[1].originalStartLine
  if line == vim.NIL then
    line = threads[1].startLine
  end