Skip to content

Commit 469e2e1

Browse files
authored
Merge pull request #19 from Stebalien/steb/comment-fringe
Add fringe icons for comments
2 parents 7c2ce9d + c1c28f4 commit 469e2e1

File tree

3 files changed

+64
-8
lines changed

3 files changed

+64
-8
lines changed

pr-review-common.el

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,17 @@
144144
"Face used for reaction emojis."
145145
:group 'pr-review)
146146

147+
(defface pr-review-fringe-comment-pending
148+
'((t :inherit warning))
149+
"Face used for fringe icons for pending comments.")
150+
151+
(defface pr-review-fringe-comment-open
152+
'((t :inherit font-lock-constant-face))
153+
"Face used for fringe icons for open comments.")
154+
155+
(defface pr-review-fringe-comment-resolved
156+
'((t :inherit shadow))
157+
"Face used for fringe icons for resolved comments.")
147158

148159
;; section classes
149160
(defclass pr-review--review-section (magit-section)

pr-review-render.el

Lines changed: 50 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@
4040
:type 'integer
4141
:group 'pr-review)
4242

43+
(defcustom pr-review-fringe-icons t
44+
"Display icons in the fringe indicating PR-review comments."
45+
:type 'boolean
46+
:group 'pr-review)
47+
4348
(defun pr-review--format-timestamp (str)
4449
"Convert and format timestamp STR from json."
4550
(concat
@@ -308,6 +313,30 @@ return t on success."
308313
(goto-char (prop-match-beginning match))
309314
t))
310315

316+
317+
(define-fringe-bitmap 'pr-review-comment
318+
[#b0000000000000000
319+
#b0000000000000000
320+
#b0000000000000000
321+
#b0000000000000000
322+
#b0000000000000000
323+
#b0111111111111100
324+
#b1111111111111110
325+
#b1111111111111110
326+
#b1110000000011110
327+
#b1111111111111110
328+
#b1111111111111110
329+
#b1110000011111110
330+
#b1111111111111110
331+
#b1111111111111110
332+
#b1111111111111110
333+
#b0111111111111100
334+
#b0000000011111000
335+
#b0000000001111000
336+
#b0000000000111000
337+
#b0000000000011000]
338+
nil 16 'center)
339+
311340
(defun pr-review--insert-in-diff-pending-review-thread (pending-review-thread &optional allow-fallback)
312341
"Insert a pending review thread inside the diff for PENDING-REVIEW-THREAD.
313342
If ALLOW-FALLBACK is non-nil, when the line for the thread cannot be found.
@@ -319,12 +348,18 @@ It will be inserted at the beginning."
319348
allow-fallback)
320349
(forward-line)
321350
(setq beg (point))
322-
(insert (propertize (concat "> PENDING comment for "
323-
(if .startLine
324-
(format "%s:%s to %s:%s" .startSide .startLine .side .line)
325-
(format "%s:%s" .side .line))
326-
"\n")
327-
'face 'pr-review-in-diff-pending-begin-face))
351+
(insert (apply #'propertize
352+
(concat "> PENDING comment for "
353+
(if .startLine
354+
(format "%s:%s to %s:%s" .startSide .startLine .side .line)
355+
(format "%s:%s" .side .line))
356+
"\n")
357+
'face 'pr-review-in-diff-pending-begin-face
358+
(when pr-review-fringe-icons
359+
(list 'line-prefix
360+
(propertize " " 'display '(left-fringe
361+
pr-review-comment
362+
pr-review-fringe-comment-pending))))))
328363
(pr-review--insert-fontified .body 'gfm-mode nil
329364
'pr-review-in-diff-pending-body-face)
330365
(insert (propertize " \n" 'face 'pr-review-in-diff-pending-end-face))
@@ -345,7 +380,8 @@ It will be inserted at the beginning."
345380
.path .diffSide .line)
346381
(forward-line)
347382
(insert
348-
(propertize
383+
(apply
384+
#'propertize
349385
(concat (format "> %s comments from " (length .comments.nodes))
350386
(string-join
351387
(seq-uniq
@@ -358,7 +394,13 @@ It will be inserted at the beginning."
358394
'face 'pr-review-in-diff-thread-title-face
359395
'pr-review-eldoc-content (let-alist (car .comments.nodes)
360396
(concat (pr-review--propertize-username .author.login)
361-
": " .body))))
397+
": " .body))
398+
(when pr-review-fringe-icons
399+
(list 'line-prefix
400+
(propertize " " 'display `(left-fringe pr-review-comment
401+
(if .isResolved
402+
pr-review-fringe-comment-resolved
403+
pr-review-fringe-comment-open)))))))
362404
(insert-button
363405
"Go to thread"
364406
'face 'pr-review-button-face

pr-review.el

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,9 @@ Which means that all sections are collapsed."
139139
pr-review--commit-section
140140
pr-review--description-section
141141
pr-review--event-section))
142+
(when pr-review-fringe-icons
143+
(unless (and left-fringe-width (>= left-fringe-width 16))
144+
(setq left-fringe-width 16)))
142145
(add-to-list 'kill-buffer-query-functions 'pr-review--confirm-kill-buffer)
143146
(add-hook 'eldoc-documentation-functions #'pr-review--eldoc-function nil t)
144147
(eldoc-mode))

0 commit comments

Comments
 (0)