Skip to content

Commit 2392dfe

Browse files
Copilotalexr00
andcommitted
Add collapsePreexisting setting to keep newly created comments expanded
Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com>
1 parent 2c3c61e commit 2392dfe

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
lines changed

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -353,11 +353,13 @@
353353
"type": "string",
354354
"enum": [
355355
"expandUnresolved",
356-
"collapseAll"
356+
"collapseAll",
357+
"collapsePreexisting"
357358
],
358359
"enumDescriptions": [
359360
"%githubPullRequests.commentExpandState.expandUnresolved%",
360-
"%githubPullRequests.commentExpandState.collapseAll%"
361+
"%githubPullRequests.commentExpandState.collapseAll%",
362+
"%githubPullRequests.commentExpandState.collapsePreexisting%"
361363
],
362364
"default": "expandUnresolved",
363365
"description": "%githubPullRequests.commentExpandState.description%"

package.nls.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
"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.",
5050
"githubPullRequests.commentExpandState.expandUnresolved": "All unresolved comments will be expanded.",
5151
"githubPullRequests.commentExpandState.collapseAll": "All comments will be collapsed",
52+
"githubPullRequests.commentExpandState.collapsePreexisting": "Only pre-existing comments will be collapsed. Comments you just created will remain expanded.",
5253
"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.",
5354
"githubPullRequests.useReviewMode.merged": "Use review mode for merged pull requests.",
5455
"githubPullRequests.useReviewMode.closed": "Use review mode for closed pull requests. Merged pull requests are not considered \"closed\".",

src/github/utils.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -152,20 +152,22 @@ function isResolvedToResolvedState(isResolved: boolean) {
152152

153153
export const COMMENT_EXPAND_STATE_SETTING = 'commentExpandState';
154154
export const COMMENT_EXPAND_STATE_COLLAPSE_VALUE = 'collapseAll';
155+
export const COMMENT_EXPAND_STATE_COLLAPSE_PREEXISTING_VALUE = 'collapsePreexisting';
155156
export const COMMENT_EXPAND_STATE_EXPAND_VALUE = 'expandUnresolved';
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) {
157+
export function getCommentCollapsibleState(thread: IReviewThread, expand?: boolean, currentUser?: string) {
158+
const config = vscode.workspace.getConfiguration(PR_SETTINGS_NAMESPACE)?.get(COMMENT_EXPAND_STATE_SETTING);
159+
const isFromCurrent = (currentUser && (thread.comments[thread.comments.length - 1].user?.login === currentUser));
160+
const isJustSuggestion = thread.comments.length === 1 && thread.comments[0].body.startsWith('```suggestion') && thread.comments[0].body.endsWith('```');
161+
162+
// When collapsePreexisting is set, keep newly created comments from the current user expanded
163+
if (config === COMMENT_EXPAND_STATE_COLLAPSE_PREEXISTING_VALUE && !thread.isOutdated && isFromCurrent && !isJustSuggestion) {
159164
return vscode.CommentThreadCollapsibleState.Expanded;
160165
}
161166

162-
const isFromCurrent = (currentUser && (thread.comments[thread.comments.length - 1].user?.login === currentUser));
163-
const isJustSuggestion = thread.comments.length === 1 && thread.comments[0].body.startsWith('```suggestion') && thread.comments[0].body.endsWith('```');
164167
if (thread.isResolved || (!thread.isOutdated && isFromCurrent && !isJustSuggestion)) {
165168
return vscode.CommentThreadCollapsibleState.Collapsed;
166169
}
167170
if (expand === undefined) {
168-
const config = vscode.workspace.getConfiguration(PR_SETTINGS_NAMESPACE)?.get(COMMENT_EXPAND_STATE_SETTING);
169171
expand = config === COMMENT_EXPAND_STATE_EXPAND_VALUE;
170172
}
171173
return expand

0 commit comments

Comments
 (0)