Skip to content

Commit 2292dc9

Browse files
committed
Fix thread range issues with partial lines
Fixes #3496
1 parent 7fa7cbf commit 2292dc9

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

src/github/utils.ts

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export interface CommentReactionHandler {
3939
export function threadRange(startLine: number, endLine: number, endCharacter?: number): vscode.Range {
4040
if ((startLine !== endLine) && (endCharacter === undefined)) {
4141
endCharacter = 300; // 300 is a "large" number that will select a lot of the line since don't know anything about the line length
42-
} else {
42+
} else if (!endCharacter) {
4343
endCharacter = 0;
4444
}
4545
return new vscode.Range(startLine, 0, endLine, endCharacter);
@@ -89,7 +89,20 @@ export function getCommentCollapsibleState(isResolved: boolean, expand?: boolean
8989
? vscode.CommentThreadCollapsibleState.Expanded : vscode.CommentThreadCollapsibleState.Collapsed;
9090
}
9191

92-
export function updateThread(vscodeThread: GHPRCommentThread, reviewThread: IReviewThread, expand?: boolean) {
92+
93+
export function updateThreadWithRange(vscodeThread: GHPRCommentThread, reviewThread: IReviewThread, expand?: boolean) {
94+
const editors = vscode.window.visibleTextEditors;
95+
for (let editor of editors) {
96+
if (editor.document.uri.toString() === vscodeThread.uri.toString()) {
97+
const endLine = editor.document.lineAt(vscodeThread.range.end.line);
98+
const range = new vscode.Range(vscodeThread.range.start.line, 0, vscodeThread.range.end.line, endLine.text.length);
99+
updateThread(vscodeThread, reviewThread, expand, range);
100+
break;
101+
}
102+
}
103+
}
104+
105+
export function updateThread(vscodeThread: GHPRCommentThread, reviewThread: IReviewThread, expand?: boolean, range?: vscode.Range) {
93106
if (reviewThread.viewerCanResolve && !reviewThread.isResolved) {
94107
vscodeThread.contextValue = 'canResolve';
95108
} else if (reviewThread.viewerCanUnresolve && reviewThread.isResolved) {
@@ -101,7 +114,9 @@ export function updateThread(vscodeThread: GHPRCommentThread, reviewThread: IRev
101114
vscodeThread.state = newResolvedState;
102115
}
103116
vscodeThread.collapsibleState = getCommentCollapsibleState(reviewThread.isResolved, expand);
104-
117+
if (range) {
118+
vscodeThread.range = range;
119+
}
105120
vscodeThread.comments = reviewThread.comments.map(c => new GHPRComment(c, vscodeThread));
106121
updateCommentThreadLabel(vscodeThread);
107122
}

src/view/pullRequestCommentController.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {
2323
updateCommentReviewState,
2424
updateCommentThreadLabel,
2525
updateThread,
26+
updateThreadWithRange,
2627
} from '../github/utils';
2728

2829
export class PullRequestCommentController implements CommentHandler, CommentReactionHandler {
@@ -247,6 +248,7 @@ export class PullRequestCommentController implements CommentHandler, CommentReac
247248
newThread = this._pendingCommentThreadAdds[index];
248249
newThread.gitHubThreadId = thread.id;
249250
newThread.comments = thread.comments.map(c => new GHPRComment(c, newThread!));
251+
updateThreadWithRange(newThread, thread);
250252
this._pendingCommentThreadAdds.splice(index, 1);
251253
} else {
252254
const openPREditors = this.getPREditors(vscode.window.visibleTextEditors);

src/view/reviewCommentController.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import {
2525
updateCommentReviewState,
2626
updateCommentThreadLabel,
2727
updateThread,
28+
updateThreadWithRange,
2829
} from '../github/utils';
2930
import { ReviewManager } from './reviewManager';
3031
import { ReviewModel } from './reviewModel';
@@ -238,7 +239,7 @@ export class ReviewCommentController
238239
newThread = this._pendingCommentThreadAdds[index];
239240
newThread.gitHubThreadId = thread.id;
240241
newThread.comments = thread.comments.map(c => new GHPRComment(c, newThread));
241-
updateThread(newThread, thread);
242+
updateThreadWithRange(newThread, thread);
242243
this._pendingCommentThreadAdds.splice(index, 1);
243244
} else {
244245
const fullPath = nodePath.join(this._repository.rootUri.path, path).replace(/\\/g, '/');

0 commit comments

Comments
 (0)