diff --git a/package.json b/package.json index 24cad7f446..403ce48f4b 100644 --- a/package.json +++ b/package.json @@ -360,11 +360,13 @@ "type": "string", "enum": [ "expandUnresolved", - "collapseAll" + "collapseAll", + "collapsePreexisting" ], "enumDescriptions": [ "%githubPullRequests.commentExpandState.expandUnresolved%", - "%githubPullRequests.commentExpandState.collapseAll%" + "%githubPullRequests.commentExpandState.collapseAll%", + "%githubPullRequests.commentExpandState.collapsePreexisting%" ], "default": "expandUnresolved", "description": "%githubPullRequests.commentExpandState.description%" diff --git a/package.nls.json b/package.nls.json index c0a249eca3..0dbff8f8d9 100644 --- a/package.nls.json +++ b/package.nls.json @@ -51,6 +51,7 @@ "githubPullRequests.commentExpandState.description": "Controls whether comments are expanded when a document with comments is opened. Requires a reload to take effect for comments that have already been added.", "githubPullRequests.commentExpandState.expandUnresolved": "All unresolved comments will be expanded.", "githubPullRequests.commentExpandState.collapseAll": "All comments will be collapsed.", + "githubPullRequests.commentExpandState.collapsePreexisting": "Only pre-existing comments will be collapsed. Newly added comments will remain expanded.", "githubPullRequests.useReviewMode.description": "Choose which pull request states will use review mode. \"Open\" pull requests will always use review mode. Setting to \"auto\" will use review mode for open, closed, and merged pull requests in web, but only open pull requests on desktop.", "githubPullRequests.useReviewMode.merged": "Use review mode for merged pull requests.", "githubPullRequests.useReviewMode.closed": "Use review mode for closed pull requests. Merged pull requests are not considered \"closed\".", diff --git a/src/github/utils.ts b/src/github/utils.ts index 19f3e6c934..29d4c41900 100644 --- a/src/github/utils.ts +++ b/src/github/utils.ts @@ -153,15 +153,22 @@ function isResolvedToResolvedState(isResolved: boolean) { export const COMMENT_EXPAND_STATE_SETTING = 'commentExpandState'; export const COMMENT_EXPAND_STATE_COLLAPSE_VALUE = 'collapseAll'; +export const COMMENT_EXPAND_STATE_COLLAPSE_PREEXISTING_VALUE = 'collapsePreexisting'; export const COMMENT_EXPAND_STATE_EXPAND_VALUE = 'expandUnresolved'; -export function getCommentCollapsibleState(thread: IReviewThread, expand?: boolean, currentUser?: string) { +export function getCommentCollapsibleState(thread: IReviewThread, expand?: boolean, currentUser?: string, isNewlyAdded?: boolean) { + const config = vscode.workspace.getConfiguration(PR_SETTINGS_NAMESPACE)?.get(COMMENT_EXPAND_STATE_SETTING); const isFromCurrent = (currentUser && (thread.comments[thread.comments.length - 1].user?.login === currentUser)); const isJustSuggestion = thread.comments.length === 1 && thread.comments[0].body.startsWith('```suggestion') && thread.comments[0].body.endsWith('```'); + + // When collapsePreexisting is set, keep newly added comments expanded + if (config === COMMENT_EXPAND_STATE_COLLAPSE_PREEXISTING_VALUE && isNewlyAdded && !isJustSuggestion) { + return vscode.CommentThreadCollapsibleState.Expanded; + } + if (thread.isResolved || (!thread.isOutdated && isFromCurrent && !isJustSuggestion)) { return vscode.CommentThreadCollapsibleState.Collapsed; } if (expand === undefined) { - const config = vscode.workspace.getConfiguration(PR_SETTINGS_NAMESPACE)?.get(COMMENT_EXPAND_STATE_SETTING); expand = config === COMMENT_EXPAND_STATE_EXPAND_VALUE; } return expand @@ -169,7 +176,7 @@ export function getCommentCollapsibleState(thread: IReviewThread, expand?: boole } -export function updateThreadWithRange(context: vscode.ExtensionContext, vscodeThread: GHPRCommentThread, reviewThread: IReviewThread, githubRepositories?: GitHubRepository[], expand?: boolean) { +export function updateThreadWithRange(context: vscode.ExtensionContext, vscodeThread: GHPRCommentThread, reviewThread: IReviewThread, githubRepositories?: GitHubRepository[], expand?: boolean, isNewlyAdded?: boolean) { if (!vscodeThread.range) { return; } @@ -178,13 +185,13 @@ export function updateThreadWithRange(context: vscode.ExtensionContext, vscodeTh if (editor.document.uri.toString() === vscodeThread.uri.toString()) { const endLine = editor.document.lineAt(vscodeThread.range.end.line); const range = new vscode.Range(vscodeThread.range.start.line, 0, vscodeThread.range.end.line, endLine.text.length); - updateThread(context, vscodeThread, reviewThread, githubRepositories, expand, range); + updateThread(context, vscodeThread, reviewThread, githubRepositories, expand, range, undefined, isNewlyAdded); break; } } } -export function updateThread(context: vscode.ExtensionContext, vscodeThread: GHPRCommentThread, reviewThread: IReviewThread, githubRepositories?: GitHubRepository[], expand?: boolean, range?: vscode.Range) { +export function updateThread(context: vscode.ExtensionContext, vscodeThread: GHPRCommentThread, reviewThread: IReviewThread, githubRepositories?: GitHubRepository[], expand?: boolean, range?: vscode.Range, currentUser?: string, isNewlyAdded?: boolean) { if (reviewThread.viewerCanResolve && !reviewThread.isResolved) { vscodeThread.contextValue = 'canResolve'; } else if (reviewThread.viewerCanUnresolve && reviewThread.isResolved) { @@ -203,7 +210,7 @@ export function updateThread(context: vscode.ExtensionContext, vscodeThread: GHP applicability: newApplicabilityState }; } - vscodeThread.collapsibleState = getCommentCollapsibleState(reviewThread, expand); + vscodeThread.collapsibleState = getCommentCollapsibleState(reviewThread, expand, currentUser, isNewlyAdded); if (range) { vscodeThread.range = range; } diff --git a/src/view/pullRequestCommentController.ts b/src/view/pullRequestCommentController.ts index e60677266d..0d1e718313 100644 --- a/src/view/pullRequestCommentController.ts +++ b/src/view/pullRequestCommentController.ts @@ -241,7 +241,7 @@ export class PullRequestCommentController extends CommentControllerBase implemen newThread = this._pendingCommentThreadAdds[index]; newThread.gitHubThreadId = thread.id; newThread.comments = thread.comments.map(c => new GHPRComment(this._context, c, newThread!, this._githubRepositories)); - updateThreadWithRange(this._context, newThread, thread, this._githubRepositories); + updateThreadWithRange(this._context, newThread, thread, this._githubRepositories, undefined, true); this._pendingCommentThreadAdds.splice(index, 1); } else { const openPREditors = await this.getPREditors(vscode.window.visibleTextEditors); diff --git a/src/view/reviewCommentController.ts b/src/view/reviewCommentController.ts index 4c4c7fe090..9aee06e00a 100644 --- a/src/view/reviewCommentController.ts +++ b/src/view/reviewCommentController.ts @@ -297,7 +297,7 @@ export class ReviewCommentController extends CommentControllerBase implements Co newThread = this._pendingCommentThreadAdds[index]; newThread.gitHubThreadId = thread.id; newThread.comments = thread.comments.map(c => new GHPRComment(this._context, c, newThread, githubRepositories)); - updateThreadWithRange(this._context, newThread, thread, githubRepositories); + updateThreadWithRange(this._context, newThread, thread, githubRepositories, undefined, true); this._pendingCommentThreadAdds.splice(index, 1); } else { const fullPath = nodePath.join(this._repository.rootUri.path, path).replace(/\\/g, '/');