Skip to content

Commit 2c3c61e

Browse files
Copilotalexr00
andcommitted
Changes before error encountered
Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com>
1 parent 7ba270a commit 2c3c61e

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

src/github/utils.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,12 @@ function isResolvedToResolvedState(isResolved: boolean) {
153153
export const COMMENT_EXPAND_STATE_SETTING = 'commentExpandState';
154154
export const COMMENT_EXPAND_STATE_COLLAPSE_VALUE = 'collapseAll';
155155
export const COMMENT_EXPAND_STATE_EXPAND_VALUE = 'expandUnresolved';
156-
export function getCommentCollapsibleState(thread: IReviewThread, expand?: boolean, currentUser?: string) {
156+
export function getCommentCollapsibleState(thread: IReviewThread, expand?: boolean, currentUser?: string, isJustCreated?: boolean) {
157+
// If the comment was just created, always expand it so the user can review what they wrote
158+
if (isJustCreated) {
159+
return vscode.CommentThreadCollapsibleState.Expanded;
160+
}
161+
157162
const isFromCurrent = (currentUser && (thread.comments[thread.comments.length - 1].user?.login === currentUser));
158163
const isJustSuggestion = thread.comments.length === 1 && thread.comments[0].body.startsWith('```suggestion') && thread.comments[0].body.endsWith('```');
159164
if (thread.isResolved || (!thread.isOutdated && isFromCurrent && !isJustSuggestion)) {
@@ -168,7 +173,7 @@ export function getCommentCollapsibleState(thread: IReviewThread, expand?: boole
168173
}
169174

170175

171-
export function updateThreadWithRange(context: vscode.ExtensionContext, vscodeThread: GHPRCommentThread, reviewThread: IReviewThread, githubRepositories?: GitHubRepository[], expand?: boolean) {
176+
export function updateThreadWithRange(context: vscode.ExtensionContext, vscodeThread: GHPRCommentThread, reviewThread: IReviewThread, githubRepositories?: GitHubRepository[], expand?: boolean, isJustCreated?: boolean) {
172177
if (!vscodeThread.range) {
173178
return;
174179
}
@@ -177,13 +182,13 @@ export function updateThreadWithRange(context: vscode.ExtensionContext, vscodeTh
177182
if (editor.document.uri.toString() === vscodeThread.uri.toString()) {
178183
const endLine = editor.document.lineAt(vscodeThread.range.end.line);
179184
const range = new vscode.Range(vscodeThread.range.start.line, 0, vscodeThread.range.end.line, endLine.text.length);
180-
updateThread(context, vscodeThread, reviewThread, githubRepositories, expand, range);
185+
updateThread(context, vscodeThread, reviewThread, githubRepositories, expand, range, isJustCreated);
181186
break;
182187
}
183188
}
184189
}
185190

186-
export function updateThread(context: vscode.ExtensionContext, vscodeThread: GHPRCommentThread, reviewThread: IReviewThread, githubRepositories?: GitHubRepository[], expand?: boolean, range?: vscode.Range) {
191+
export function updateThread(context: vscode.ExtensionContext, vscodeThread: GHPRCommentThread, reviewThread: IReviewThread, githubRepositories?: GitHubRepository[], expand?: boolean, range?: vscode.Range, isJustCreated?: boolean) {
187192
if (reviewThread.viewerCanResolve && !reviewThread.isResolved) {
188193
vscodeThread.contextValue = 'canResolve';
189194
} else if (reviewThread.viewerCanUnresolve && reviewThread.isResolved) {
@@ -202,7 +207,7 @@ export function updateThread(context: vscode.ExtensionContext, vscodeThread: GHP
202207
applicability: newApplicabilityState
203208
};
204209
}
205-
vscodeThread.collapsibleState = getCommentCollapsibleState(reviewThread, expand);
210+
vscodeThread.collapsibleState = getCommentCollapsibleState(reviewThread, expand, undefined, isJustCreated);
206211
if (range) {
207212
vscodeThread.range = range;
208213
}

src/view/pullRequestCommentController.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ export class PullRequestCommentController extends CommentControllerBase implemen
241241
newThread = this._pendingCommentThreadAdds[index];
242242
newThread.gitHubThreadId = thread.id;
243243
newThread.comments = thread.comments.map(c => new GHPRComment(this._context, c, newThread!, this._githubRepositories));
244-
updateThreadWithRange(this._context, newThread, thread, this._githubRepositories);
244+
updateThreadWithRange(this._context, newThread, thread, this._githubRepositories, undefined, true);
245245
this._pendingCommentThreadAdds.splice(index, 1);
246246
} else {
247247
const openPREditors = await this.getPREditors(vscode.window.visibleTextEditors);

src/view/reviewCommentController.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ export class ReviewCommentController extends CommentControllerBase implements Co
297297
newThread = this._pendingCommentThreadAdds[index];
298298
newThread.gitHubThreadId = thread.id;
299299
newThread.comments = thread.comments.map(c => new GHPRComment(this._context, c, newThread, githubRepositories));
300-
updateThreadWithRange(this._context, newThread, thread, githubRepositories);
300+
updateThreadWithRange(this._context, newThread, thread, githubRepositories, undefined, true);
301301
this._pendingCommentThreadAdds.splice(index, 1);
302302
} else {
303303
const fullPath = nodePath.join(this._repository.rootUri.path, path).replace(/\\/g, '/');

0 commit comments

Comments
 (0)