Skip to content

Commit

Permalink
Implement #108: highlight diff lines accepting comments
Browse files Browse the repository at this point in the history
  • Loading branch information
pwntester committed Mar 27, 2021
1 parent 0c9c152 commit 6ee8741
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
16 changes: 10 additions & 6 deletions lua/octo/reviews.lua
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ function M.diff_changes_qf_entry(target)
local repo = qf.context.pull_request_repo
local number = qf.context.pull_request_number

-- calculate valid ranges
-- calculate valid comment ranges
local valid_left_ranges = {}
local valid_right_ranges = {}
local valid_hunks = {}
Expand Down Expand Up @@ -141,7 +141,7 @@ function M.diff_changes_qf_entry(target)
bufname = left_bufname,
content_bufnr = left_bufnr,
hunks = valid_hunks,
ranges = valid_left_ranges,
comment_ranges = valid_left_ranges,
alt_win = right_win
})

Expand Down Expand Up @@ -172,7 +172,7 @@ function M.diff_changes_qf_entry(target)
bufname = right_bufname,
content_bufnr = right_bufnr,
hunks = valid_hunks,
ranges = valid_right_ranges,
comment_ranges = valid_right_ranges,
alt_win = left_win
})

Expand Down Expand Up @@ -251,9 +251,9 @@ function M.add_review_comment(isSuggestion)
local bufnr = api.nvim_get_current_buf()
local status, props = pcall(api.nvim_buf_get_var, bufnr, "OctoDiffProps")
if status and props then
-- check we are in a valid range
-- check we are in a valid comment range
local diff_hunk
for i, range in ipairs(props.ranges) do
for i, range in ipairs(props.comment_ranges) do
if range[1] <= line1 and range[2] >= line2 then
diff_hunk = props.hunks[i]
break
Expand Down Expand Up @@ -1099,7 +1099,6 @@ function M.show_comment()
if not status or not props then
return
end

local comments = vim.tbl_values(_review_comments)
local cursor = api.nvim_win_get_cursor(0)
for _, comment in ipairs(comments) do
Expand All @@ -1114,6 +1113,11 @@ function M.place_comment_signs()
signs.unplace(bufnr)
local status, props = pcall(api.nvim_buf_get_var, bufnr, "OctoDiffProps")
if status and props then
for _, range in ipairs(props.comment_ranges) do
for line = range[1], range[2] do
signs.place("octo_comment_range", bufnr, line - 1)
end
end
local comments = vim.tbl_values(_review_comments)
for _, comment in ipairs(comments) do
if M.is_comment_placed_in_buffer(comment, bufnr) then
Expand Down
2 changes: 1 addition & 1 deletion lua/octo/window.lua
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ function M.create_comment_popup(win, comment)
local border_width = 1
local padding = 1
local body = vim.list_extend(header, vim.split(comment.body, "\n"))
local height = math.min(2*border_width + strlen(body), vim.fn.winheight(win))
local height = math.min(2*border_width + #body, vim.fn.winheight(win))

local preview_bufnr = api.nvim_create_buf(false, true)
api.nvim_buf_set_lines(preview_bufnr, 0, -1, false, body)
Expand Down
5 changes: 4 additions & 1 deletion plugin/octo.vim
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ au CursorHold octo://* lua require'octo'.on_cursor_hold()
augroup END

" sign definitions
sign define octo_comment text=❯ texthl=OctoNvimCommentLine linehl=OctoNvimCommentLine
sign define octo_comment text=❯ texthl=OctoNvimCommentSign linehl=OctoNvimCommentLine
sign define octo_comment_range text=│ texthl=OctoNvimCommentRangeLine
sign define octo_clean_block_start text=┌ linehl=OctoNvimEditable
sign define octo_clean_block_end text=└ linehl=OctoNvimEditable
sign define octo_dirty_block_start text=┌ texthl=OctoNvimDirty linehl=OctoNvimEditable
Expand Down Expand Up @@ -94,6 +95,8 @@ highlight default link OctoNvimDetailsLabel Title
highlight default link OctoNvimDetailsValue Identifier
highlight default link OctoNvimMissingDetails Comment
highlight default link OctoNvimCommentLine Visual
highlight default link OctoNvimCommentSign OctoNvimYellow
highlight default link OctoNvimCommentRangeLine OctoNvimYellow
highlight default link OctoNvimEditable NormalFloat
highlight default link OctoNvimBubble NormalFloat
highlight default link OctoNvimUser OctoNvimBubble
Expand Down

0 comments on commit 6ee8741

Please sign in to comment.