Skip to content

Add review thread diff to our GitHub comments viewer#2352

Merged
Kobzol merged 4 commits intorust-lang:masterfrom
Urgau:gh-comments-review-thread-diff
Mar 25, 2026
Merged

Add review thread diff to our GitHub comments viewer#2352
Kobzol merged 4 commits intorust-lang:masterfrom
Urgau:gh-comments-review-thread-diff

Conversation

@Urgau
Copy link
Copy Markdown
Member

@Urgau Urgau commented Mar 23, 2026

Current our GitHub comments viewer doesn't display the associated diff of each review thread. This PR aims to fix that by retrieving the "diff hunk" from GitHub GraphQL query and displaying the relevant lines.

Asked in #triagebot > moving "view all comments" forward @ 💬.

image

cc @steffahn

@Urgau Urgau requested a review from Kobzol March 23, 2026 20:52
@steffahn
Copy link
Copy Markdown
Member

steffahn commented Mar 23, 2026

Github seems to have a logic where for non-ranged line selections, the 3 previous lines (unless they don't exist, e.g. at start of file) are also shown. Compare LHS GitHub’s native way of displaying it vs. RHS this PR:
Bildschirmfoto_20260324_000840

For diffs with both a + and a - it looks to be 2 previous lines:

Bildschirmfoto_20260324_002116

In this case, the - is missing completely (there’s probably some subtle difference in what line or side or so the review actually applies to), and the github rendering seems to always up these to be 4 lines

Bildschirmfoto_20260324_003133

(on rust#153997)


As further test cases, there’s a 3-line selection here (shows as only 3 lines), and a first-line-of-file case here.

@steffahn
Copy link
Copy Markdown
Member

there’s probably some subtle difference in what line or side or so the review actually applies to

Oh I see it: the case where the - wasn’t visible is actually due to shifted line numbers. Your filter currently only creates a single range of line numbers and treats old lines and new lines the same (i.e. filtering with the same range).

Comment thread src/gh_comments.rs
Comment on lines -21 to +23
GitHubIssueState, GitHubIssueStateReason, GitHubIssueWithComments, GitHubReviewState,
GitHubSimplifiedAuthor,
GitHubGraphQlComment, GitHubGraphQlReactionGroup, GitHubGraphQlReview,
GitHubGraphQlReviewThread, GitHubGraphQlReviewThreadComment, GitHubIssueState,
GitHubIssueStateReason, GitHubIssueWithComments, GitHubReviewState, GitHubSimplifiedAuthor,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review comment only used used as a test case in and by itself

Comment thread src/gh_comments.rs Outdated
Comment on lines +21 to +23
GitHubGraphQlComment, GitHubGraphQlReactionGroup, GitHubGraphQlReview,
GitHubGraphQlReviewThread, GitHubGraphQlReviewThreadComment, GitHubIssueState,
GitHubIssueStateReason, GitHubIssueWithComments, GitHubReviewState, GitHubSimplifiedAuthor,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Second review comment only used used as a test case in and by itself (different range)

@steffahn
Copy link
Copy Markdown
Member

Uhhh… these 2 ranges of my above review comments (from “-21” to ”+23” vs “+21” to “+23”) look relatively identical, considering only the currently used information of

    start_line: Option<usize>,
    end_line: Option<usize>,

in the code 😅
both printing

Some(21), Some(23)
Some(21), Some(23)

if I debug-print the thing.

@steffahn
Copy link
Copy Markdown
Member

Ah!! We have diffSide and startDiffSide in the API!

Comment thread src/gh_comments.rs
.sum::<usize>();
.sum::<usize>()
+ issue_with_comments.review_threads.as_ref().map_or(0, |rt| {
rt.nodes
Copy link
Copy Markdown
Member

@steffahn steffahn Mar 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

View changes since this review

Another test review comment.

Comment thread src/gh_comments.rs
.sum::<usize>()
+ issue_with_comments.review_threads.as_ref().map_or(0, |rt| {
rt.nodes
.iter()
Copy link
Copy Markdown
Member

@steffahn steffahn Mar 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

View changes since this review

Yet another test review comment.

@steffahn
Copy link
Copy Markdown
Member

I'm currently implementing a fix for the whole logic :-)

@steffahn
Copy link
Copy Markdown
Member

(feel free to include my commit 8d919c8 with Urgau#1)

Example screenshot of this thread itself with that fix:
Bildschirmfoto_20260324_042008


Another still remaining relevant bug then is that the current display seems to be collapsing spaces. This probably just needs an element (or style) that makes it behave like pre or something like that.

@Urgau Urgau force-pushed the gh-comments-review-thread-diff branch from cee34de to 9d99903 Compare March 24, 2026 17:56
@Urgau
Copy link
Copy Markdown
Member Author

Urgau commented Mar 24, 2026

Thanks you very much @steffahn!

I saw in the GraphQl documentation startDiffSide and diffSide fields but I couldn't figure out what they did, glad you were able to figure it out.

Another still remaining relevant bug then is that the current display seems to be collapsing spaces. This probably just needs an element (or style) that makes it behave like pre or something like that.

I was using white-space: preserve-spaces, but it's a bit too experimental (only implemented in Firefox atm). Switched to pre-wrap.

@Urgau Urgau force-pushed the gh-comments-review-thread-diff branch from 9d99903 to 56205c4 Compare March 24, 2026 18:07
@steffahn
Copy link
Copy Markdown
Member

Switched to pre-wrap.

That appears to be fixing it :-)

@Urgau
Copy link
Copy Markdown
Member Author

Urgau commented Mar 24, 2026

@steffahn
Copy link
Copy Markdown
Member

steffahn commented Mar 24, 2026

FYI, the enum DiffLineRange is also made with the idea in mind that we might want to add these annotations eventually, to make that really straightforward.

Bildschirmfoto_20260324_191728
enum DiffLineRange {
    Single(ChangeLineNumber), // doesn't display any annotation
    Range {
        start: ChangeLineNumber, // displays with "Comment on
        end: ChangeLineNumber,   // lines … to …" annotation
    },
}

enum ChangeLineNumber {
    Removed(usize), // red number with `-`
    Added(usize),   // green mumber with `+`
}

@Urgau
Copy link
Copy Markdown
Member Author

Urgau commented Mar 24, 2026

FYI, the enum DiffLineRange is also made with the idea in mind that we might want to add these annotations eventually, to make that really straightforward.

Interesting, I personally look at those annotations and I don't see how they are useful, but if you think they are useful, we can add them later.

Comment thread src/gh_comments.rs
utils::{immutable_headers, is_known_and_public_repo},
};

pub const STYLE_URL: &str = "/gh-comments/style@0.0.4.css";
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another test case, pointing to a "removed" line

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test reply

Comment thread src/gh_comments/style.css
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test comment on whole file

@Kobzol
Copy link
Copy Markdown
Member

Kobzol commented Mar 25, 2026

After hovering on a resolved/hidden review thread comment, it would be nice to change the cursor to pointer and underline the text, so make it clear that you can click on it, right now it looks like read-only text, but it actually expands once you click on it.

Otherwise looks great. Though I think we're well past a point where a templating engine would really come in handy 😅

@Urgau Urgau force-pushed the gh-comments-review-thread-diff branch from 56205c4 to 9571ec6 Compare March 25, 2026 17:32
@Urgau
Copy link
Copy Markdown
Member Author

Urgau commented Mar 25, 2026

Good point on the header not changing the cursor on hover, it's fixed.

Copy link
Copy Markdown
Member

@Kobzol Kobzol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Kobzol Kobzol added this pull request to the merge queue Mar 25, 2026
Merged via the queue into rust-lang:master with commit d51d1ea Mar 25, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants