Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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%"
Expand Down
1 change: 1 addition & 0 deletions package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -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\".",
Expand Down
19 changes: 13 additions & 6 deletions src/github/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,23 +153,30 @@ 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
? vscode.CommentThreadCollapsibleState.Expanded : vscode.CommentThreadCollapsibleState.Collapsed;
}


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;
}
Expand All @@ -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) {
Expand All @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/view/pullRequestCommentController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/view/reviewCommentController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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, '/');
Expand Down