Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a setting to collapse comments on resolve #192864

Merged
merged 1 commit into from
Sep 13, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 20 additions & 8 deletions src/vs/workbench/contrib/comments/browser/commentThreadWidget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ import { ICellRange } from 'vs/workbench/contrib/notebook/common/notebookRange';
import { FontInfo } from 'vs/editor/common/config/fontInfo';
import { IContextMenuService } from 'vs/platform/contextview/browser/contextView';
import { registerNavigableContainer } from 'vs/workbench/browser/actions/widgetNavigationCommands';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { COMMENTS_SECTION, ICommentsConfiguration } from 'vs/workbench/contrib/comments/common/commentsConfiguration';

export const COMMENTEDITOR_DECORATION_KEY = 'commenteditordecoration';

Expand All @@ -46,6 +48,8 @@ export class CommentThreadWidget<T extends IRange | ICellRange = IRange> extends
private _onDidResize = new Emitter<dom.Dimension>();
onDidResize = this._onDidResize.event;

private _commentThreadState: languages.CommentThreadState | undefined;

get commentThread() {
return this._commentThread;
}
Expand All @@ -55,7 +59,7 @@ export class CommentThreadWidget<T extends IRange | ICellRange = IRange> extends
private _owner: string,
private _parentResourceUri: URI,
private _contextKeyService: IContextKeyService,
private _scopedInstatiationService: IInstantiationService,
private _scopedInstantiationService: IInstantiationService,
private _commentThread: languages.CommentThread<T>,
private _pendingComment: string | undefined,
private _pendingEdits: { [key: number]: string } | undefined,
Expand All @@ -66,7 +70,8 @@ export class CommentThreadWidget<T extends IRange | ICellRange = IRange> extends
collapse: () => void;
},
@ICommentService private commentService: ICommentService,
@IContextMenuService contextMenuService: IContextMenuService
@IContextMenuService contextMenuService: IContextMenuService,
@IConfigurationService private configurationService: IConfigurationService
) {
super();

Expand All @@ -83,7 +88,7 @@ export class CommentThreadWidget<T extends IRange | ICellRange = IRange> extends
this._commentMenus,
this._commentThread,
this._contextKeyService,
this._scopedInstatiationService,
this._scopedInstantiationService,
contextMenuService
);

Expand All @@ -107,15 +112,15 @@ export class CommentThreadWidget<T extends IRange | ICellRange = IRange> extends
}
}));

this._body = this._scopedInstatiationService.createInstance(
this._body = this._scopedInstantiationService.createInstance(
CommentThreadBody,
this._owner,
this._parentResourceUri,
bodyElement,
this._markdownOptions,
this._commentThread,
this._pendingEdits,
this._scopedInstatiationService,
this._scopedInstantiationService,
this
) as unknown as CommentThreadBody<T>;
this._register(this._body);
Expand Down Expand Up @@ -170,6 +175,9 @@ export class CommentThreadWidget<T extends IRange | ICellRange = IRange> extends
}

updateCommentThread(commentThread: languages.CommentThread<T>) {
const shouldCollapse = (this._commentThread.collapsibleState === languages.CommentThreadCollapsibleState.Expanded) && (this._commentThreadState === languages.CommentThreadState.Unresolved)
&& (commentThread.state === languages.CommentThreadState.Resolved);
this._commentThreadState = commentThread.state;
this._commentThread = commentThread;
dispose(this._commentThreadDisposables);
this._commentThreadDisposables = [];
Expand All @@ -185,6 +193,10 @@ export class CommentThreadWidget<T extends IRange | ICellRange = IRange> extends
} else {
this._commentThreadContextValue.reset();
}

if (shouldCollapse && this.configurationService.getValue<ICommentsConfiguration>(COMMENTS_SECTION).collapseOnResolve) {
this.collapse();
}
}

display(lineHeight: number) {
Expand Down Expand Up @@ -243,12 +255,12 @@ export class CommentThreadWidget<T extends IRange | ICellRange = IRange> extends
}

private _createCommentForm() {
this._commentReply = this._scopedInstatiationService.createInstance(
this._commentReply = this._scopedInstantiationService.createInstance(
CommentReply,
this._owner,
this._body.container,
this._commentThread,
this._scopedInstatiationService,
this._scopedInstantiationService,
this._contextKeyService,
this._commentMenus,
this._commentOptions,
Expand All @@ -261,7 +273,7 @@ export class CommentThreadWidget<T extends IRange | ICellRange = IRange> extends
}

private _createAdditionalActions() {
this._additionalActions = this._scopedInstatiationService.createInstance(
this._additionalActions = this._scopedInstantiationService.createInstance(
CommentThreadAdditionalActions,
this._body.container,
this._commentThread,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ Registry.as<IConfigurationRegistry>(ConfigurationExtensions.Configuration).regis
type: 'boolean',
default: true,
description: nls.localize('comments.maxHeight', "Controls whether the comments widget scrolls or expands.")
},
'comments.collapseOnResolve': {
type: 'boolean',
default: true,
description: nls.localize('collapseOnResolve', "Controls whether the comment thread should collapse when the thread is resolved.")
}
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export interface ICommentsConfiguration {
useRelativeTime: boolean;
visible: boolean;
maxHeight: boolean;
collapseOnResolve: boolean;
}

export const COMMENTS_SECTION = 'comments';