Skip to content

Commit 906c3cd

Browse files
committed
Comment thread range improvements
1 parent 0d44403 commit 906c3cd

File tree

3 files changed

+18
-20
lines changed

3 files changed

+18
-20
lines changed

src/github/utils.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,15 @@ export interface CommentReactionHandler {
3636
toggleReaction(comment: vscode.Comment, reaction: vscode.CommentReaction): Promise<void>;
3737
}
3838

39+
export function threadRange(startLine: number, endLine: number, endCharacter?: number): vscode.Range {
40+
if ((startLine !== endLine) && (endCharacter === undefined)) {
41+
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 {
43+
endCharacter = 0;
44+
}
45+
return new vscode.Range(startLine, 0, endLine, endCharacter);
46+
}
47+
3948
export function createVSCodeCommentThreadForReviewThread(
4049
uri: vscode.Uri,
4150
range: vscode.Range,

src/view/pullRequestCommentController.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { PullRequestOverviewPanel } from '../github/pullRequestOverview';
1919
import {
2020
CommentReactionHandler,
2121
createVSCodeCommentThreadForReviewThread,
22+
threadRange,
2223
updateCommentReviewState,
2324
updateCommentThreadLabel,
2425
updateThread,
@@ -169,10 +170,8 @@ export class PullRequestCommentController implements CommentHandler, CommentReac
169170
&& (thread.endLine !== null),
170171
)
171172
.map(thread => {
172-
const range = new vscode.Range(
173-
new vscode.Position(thread.startLine - 1, 0),
174-
new vscode.Position(thread.endLine - 1, 0),
175-
);
173+
const endLine = thread.endLine - 1;
174+
const range = threadRange(thread.startLine - 1, endLine, editor.document.lineAt(endLine).range.end.character);
176175

177176
return createVSCodeCommentThreadForReviewThread(
178177
editor.document.uri,
@@ -260,10 +259,8 @@ export class PullRequestCommentController implements CommentHandler, CommentReac
260259
});
261260

262261
if (matchingEditor) {
263-
const range = new vscode.Range(
264-
new vscode.Position(thread.startLine - 1, 0),
265-
new vscode.Position(thread.endLine - 1, 0),
266-
);
262+
const endLine = thread.endLine - 1;
263+
const range = threadRange(thread.startLine - 1, endLine, matchingEditor.document.lineAt(endLine).range.end.character);
267264

268265
newThread = createVSCodeCommentThreadForReviewThread(
269266
matchingEditor.document.uri,

src/view/reviewCommentController.ts

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { PullRequestOverviewPanel } from '../github/pullRequestOverview';
2121
import {
2222
CommentReactionHandler,
2323
createVSCodeCommentThreadForReviewThread,
24+
threadRange,
2425
updateCommentReviewState,
2526
updateCommentThreadLabel,
2627
updateThread,
@@ -99,11 +100,7 @@ export class ReviewCommentController
99100
this._repository.rootUri,
100101
);
101102

102-
const range = new vscode.Range(
103-
new vscode.Position(thread.originalStartLine - 1, 0),
104-
new vscode.Position(thread.originalEndLine - 1, 0),
105-
);
106-
103+
const range = threadRange(thread.originalStartLine - 1, thread.originalEndLine - 1);
107104
return createVSCodeCommentThreadForReviewThread(reviewUri, range, thread, this._commentController);
108105
}
109106

@@ -128,8 +125,7 @@ export class ReviewCommentController
128125
endLine = mapOldPositionToNew(localDiff, endLine);
129126
}
130127

131-
const range = new vscode.Range(new vscode.Position(startLine - 1, 0), new vscode.Position(endLine - 1, 0));
132-
128+
const range = threadRange(startLine - 1, endLine - 1);
133129
return createVSCodeCommentThreadForReviewThread(uri, range, thread, this._commentController);
134130
}
135131

@@ -155,11 +151,7 @@ export class ReviewCommentController
155151
this._repository.rootUri,
156152
);
157153

158-
const range = new vscode.Range(
159-
new vscode.Position(thread.startLine - 1, 0),
160-
new vscode.Position(thread.endLine - 1, 0),
161-
);
162-
154+
const range = threadRange(thread.startLine - 1, thread.endLine - 1);
163155
return createVSCodeCommentThreadForReviewThread(reviewUri, range, thread, this._commentController);
164156
}
165157

0 commit comments

Comments
 (0)