Something went wrong. Try again.
Neovim plugin for working with Github pull request comments
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485---@class PrUi---@field win integer? -- win of the ui menu at startup---@field pr_data PrData?---@field fp_comments table<string, FpComments>? -- Map of filepath to array of comments summary---@field pr_comments table<string, Comment[]>? -- Map of filepath to array of comments---@field curr_rel_fp string?---@field curr_line integer?---@field first_line integer?local PrUi = {}
vim.api.nvim_set_hl(0, 'GhPrCommentBg', { bg = '#144212', fg = '#ffffff' }) -- dark green bg, white textlocal sep = ''
---Takes comments, wraps with useful data and puts it in pretty markdown---Does not apply the filepath headers---@param comments Comment[]---@return string[] bodieslocal function format_comments(comments) local utils = require('gh-pr-comments.utils') local bodies = {}
for _, c in ipairs(comments) do table.insert(bodies, sep) -- add user & datetime here table.insert( bodies, c.user_login .. '(' .. c.updated_at .. ') [L' .. c.original_line .. ']:' )
-- add diff local diff = utils.format_diff_hunk(c.diff_hunk) for _, line in pairs(diff) do table.insert(bodies, line) end
-- add comments local comment_msgs = utils.format_comments(c.body) for _, line in pairs(comment_msgs) do table.insert(bodies, line) end end table.insert(bodies, sep) return bodiesend
---Generates the contents for comments splitlocal function gen_pr_comments_content() local split_contents = {} for fp, comments in pairs(PrUi.pr_comments) do local fp_header = '# ' .. fp .. ': ' .. #comments .. ' comment(s)' table.insert(split_contents, sep) table.insert(split_contents, fp_header) for _, c in pairs(format_comments(comments)) do table.insert(split_contents, c) end end return split_contentsend
PrUi.create_split = function() local Split = require('nui.split') local event = require('nui.utils.autocmd').event
local split = Split { relative = 'editor', position = 'right', size = '40%', enter = false, }
vim.api.nvim_buf_set_lines(split.bufnr, 0, 0, true, gen_pr_comments_content()) -- mount/open the component split:mount() vim.api.nvim_set_option_value('filetype', 'markdown', { buf = split.bufnr }) vim.wo[split.winid].wrap = true vim.wo[split.winid].linebreak = true
-- unmount component when cursor leaves buffer split:on(event.BufLeave, function() split:unmount() end)end
return PrUi