diff --git a/extensions/git-extended/src/review/reviewMode.ts b/extensions/git-extended/src/review/reviewMode.ts index 41bf6822913..fda563252f2 100644 --- a/extensions/git-extended/src/review/reviewMode.ts +++ b/extensions/git-extended/src/review/reviewMode.ts @@ -214,6 +214,9 @@ export class ReviewMode implements vscode.DecorationProvider { // No old threads match this thread, it is new if (matchingCommentThread.length === 0) { added.push(thread); + if (thread.resource.scheme === 'file') { + thread.collapsibleState = vscode.CommentThreadCollapsibleState.Collapsed; + } } // Check if comment has been updated @@ -267,7 +270,7 @@ export class ReviewMode implements vscode.DecorationProvider { return Promise.resolve(null); } - private commentsToCommentThreads(comments: Comment[]): vscode.CommentThread[] { + private commentsToCommentThreads(comments: Comment[], collapsibleState: vscode.CommentThreadCollapsibleState = vscode.CommentThreadCollapsibleState.Expanded): vscode.CommentThread[] { if (!comments || !comments.length) { return []; } @@ -297,6 +300,7 @@ export class ReviewMode implements vscode.DecorationProvider { gravatar: comment.user.avatar_url }; }), + collapsibleState: collapsibleState, reply: this._reply }); } @@ -361,7 +365,7 @@ export class ReviewMode implements vscode.DecorationProvider { } return { - threads: this.commentsToCommentThreads(matchingComments), + threads: this.commentsToCommentThreads(matchingComments, document.uri.scheme === 'file' ? vscode.CommentThreadCollapsibleState.Collapsed : vscode.CommentThreadCollapsibleState.Expanded), commentingRanges: ranges, reply: this._reply }; diff --git a/src/vs/editor/common/modes.ts b/src/vs/editor/common/modes.ts index e52dc256ec6..20c106667a6 100644 --- a/src/vs/editor/common/modes.ts +++ b/src/vs/editor/common/modes.ts @@ -944,12 +944,24 @@ export interface CommentInfo { reply?: Command; } +export enum CommentThreadCollapsibleState { + /** + * Determines an item is collapsed + */ + Collapsed = 0, + /** + * Determines an item is expanded + */ + Expanded = 1 +} + export interface CommentThread { - readonly threadId: string; - readonly resource: string; - readonly range: IRange; - readonly comments: Comment[]; - readonly reply: Command; + threadId: string; + resource: string; + range: IRange; + comments: Comment[]; + collapsibleState?: CommentThreadCollapsibleState; + reply?: Command; } export interface NewCommentAction { diff --git a/src/vs/editor/standalone/browser/standaloneLanguages.ts b/src/vs/editor/standalone/browser/standaloneLanguages.ts index c0eec9275ac..e3f74519604 100644 --- a/src/vs/editor/standalone/browser/standaloneLanguages.ts +++ b/src/vs/editor/standalone/browser/standaloneLanguages.ts @@ -793,6 +793,7 @@ export function createMonacoLanguagesAPI(): typeof monaco.languages { CompletionItemKind: CompletionItemKind, SymbolKind: modes.SymbolKind, IndentAction: IndentAction, - SuggestTriggerKind: modes.SuggestTriggerKind + SuggestTriggerKind: modes.SuggestTriggerKind, + CommentThreadCollapsibleState: modes.CommentThreadCollapsibleState }; } diff --git a/src/vs/monaco.d.ts b/src/vs/monaco.d.ts index 94ec028e521..fce9dddf1a9 100644 --- a/src/vs/monaco.d.ts +++ b/src/vs/monaco.d.ts @@ -5035,12 +5035,24 @@ declare namespace monaco.languages { reply?: Command; } + export enum CommentThreadCollapsibleState { + /** + * Determines an item is collapsed + */ + Collapsed = 0, + /** + * Determines an item is expanded + */ + Expanded = 1, + } + export interface CommentThread { - readonly threadId: string; - readonly resource: string; - readonly range: IRange; - readonly comments: Comment[]; - readonly reply: Command; + threadId: string; + resource: string; + range: IRange; + comments: Comment[]; + collapsibleState?: CommentThreadCollapsibleState; + reply?: Command; } export interface NewCommentAction { diff --git a/src/vs/vscode.proposed.d.ts b/src/vs/vscode.proposed.d.ts index fa0a8afc25f..bffc6b40294 100644 --- a/src/vs/vscode.proposed.d.ts +++ b/src/vs/vscode.proposed.d.ts @@ -776,11 +776,23 @@ declare module 'vscode' { reply?: Command; } + export enum CommentThreadCollapsibleState { + /** + * Determines an item is collapsed + */ + Collapsed = 0, + /** + * Determines an item is expanded + */ + Expanded = 1 + } + interface CommentThread { threadId: string; resource: Uri; range: Range; comments: Comment[]; + collapsibleState?: CommentThreadCollapsibleState; reply?: Command; } diff --git a/src/vs/workbench/api/electron-browser/mainThreadComments.ts b/src/vs/workbench/api/electron-browser/mainThreadComments.ts index d5020a8e37f..919a4fbddb9 100644 --- a/src/vs/workbench/api/electron-browser/mainThreadComments.ts +++ b/src/vs/workbench/api/electron-browser/mainThreadComments.ts @@ -47,6 +47,10 @@ export class MainThreadComments extends Disposable implements MainThreadComments return; } + if (!outerEditor.getModel()) { + return; + } + const outerEditorURI = outerEditor.getModel().uri; this.provideComments(outerEditorURI).then(commentInfos => { this._commentService.setComments(outerEditorURI, commentInfos); diff --git a/src/vs/workbench/api/node/extHost.api.impl.ts b/src/vs/workbench/api/node/extHost.api.impl.ts index fb249f99481..7961f1aad94 100644 --- a/src/vs/workbench/api/node/extHost.api.impl.ts +++ b/src/vs/workbench/api/node/extHost.api.impl.ts @@ -686,7 +686,9 @@ export function createApiFactory( FileType: extHostTypes.FileType, FoldingRangeList: extHostTypes.FoldingRangeList, FoldingRange: extHostTypes.FoldingRange, - FoldingRangeType: extHostTypes.FoldingRangeType + FoldingRangeType: extHostTypes.FoldingRangeType, + + CommentThreadCollapsibleState: extHostTypes.CommentThreadCollapsibleState }; }; } diff --git a/src/vs/workbench/api/node/extHostComments.ts b/src/vs/workbench/api/node/extHostComments.ts index 570e7b19376..8ebbf34b5aa 100644 --- a/src/vs/workbench/api/node/extHostComments.ts +++ b/src/vs/workbench/api/node/extHostComments.ts @@ -103,6 +103,7 @@ function convertCommentThread(vscodeCommentThread: vscode.CommentThread, command resource: vscodeCommentThread.resource.toString(), range: extHostTypeConverter.fromRange(vscodeCommentThread.range), comments: vscodeCommentThread.comments.map(convertComment), + collapsibleState: vscodeCommentThread.collapsibleState, reply: vscodeCommentThread.reply ? commandsConverter.toInternal(vscodeCommentThread.reply) : null }; } diff --git a/src/vs/workbench/api/node/extHostTypes.ts b/src/vs/workbench/api/node/extHostTypes.ts index def9661a41d..5298e7c06b5 100644 --- a/src/vs/workbench/api/node/extHostTypes.ts +++ b/src/vs/workbench/api/node/extHostTypes.ts @@ -1868,3 +1868,15 @@ export enum FoldingRangeType { } //#endregion + + +export enum CommentThreadCollapsibleState { + /** + * Determines an item is collapsed + */ + Collapsed = 0, + /** + * Determines an item is expanded + */ + Expanded = 1 +} \ No newline at end of file diff --git a/src/vs/workbench/parts/comments/electron-browser/commentsEditorContribution.ts b/src/vs/workbench/parts/comments/electron-browser/commentsEditorContribution.ts index 8797d4ad3aa..5b8adb82f50 100644 --- a/src/vs/workbench/parts/comments/electron-browser/commentsEditorContribution.ts +++ b/src/vs/workbench/parts/comments/electron-browser/commentsEditorContribution.ts @@ -102,6 +102,9 @@ export class CommentNode { } } +const EXPAND_ACTION_CLASS = 'expand-review-action octicon octicon-chevron-down'; +const COLLAPSE_ACTION_CLASS = 'expand-review-action octicon octicon-chevron-up'; + export class ReviewZoneWidget extends ZoneWidget { private _headElement: HTMLElement; protected _primaryHeading: HTMLElement; @@ -113,7 +116,7 @@ export class ReviewZoneWidget extends ZoneWidget { private _commentElements: CommentNode[]; private _resizeObserver: any; private _onDidClose = new Emitter(); - private _isCollapsed = true; + private _isCollapsed; private _toggleAction: Action; private _commentThread: modes.CommentThread; public get commentThread(): modes.CommentThread { @@ -139,6 +142,7 @@ export class ReviewZoneWidget extends ZoneWidget { this._owner = owner; this._commentThread = commentThread; this._replyCommand = replyCommand; + this._isCollapsed = commentThread.collapsibleState !== modes.CommentThreadCollapsibleState.Expanded; this.create(); this.themeService.onThemeChange(this._applyTheme, this); } @@ -183,15 +187,15 @@ export class ReviewZoneWidget extends ZoneWidget { this._actionbarWidget = new ActionBar(actionsContainer.getHTMLElement(), {}); this._disposables.push(this._actionbarWidget); - this._toggleAction = new Action('review.expand', nls.localize('label.expand', "Expand"), 'expand-review-action octicon octicon-chevron-down', true, () => { + this._toggleAction = new Action('review.expand', nls.localize('label.expand', "Expand"), this._isCollapsed ? EXPAND_ACTION_CLASS : COLLAPSE_ACTION_CLASS, true, () => { if (this._isCollapsed) { this._bodyElement.style.display = 'block'; - this._toggleAction.class = 'expand-review-action octicon octicon-chevron-up'; + this._toggleAction.class = COLLAPSE_ACTION_CLASS; this._isCollapsed = false; } else { this._bodyElement.style.display = 'none'; - this._toggleAction.class = 'expand-review-action octicon octicon-chevron-down'; + this._toggleAction.class = EXPAND_ACTION_CLASS; this._isCollapsed = true; } return null; @@ -270,7 +274,7 @@ export class ReviewZoneWidget extends ZoneWidget { this._headElement.style.height = `${headHeight}px`; this._headElement.style.lineHeight = this._headElement.style.height; - this._bodyElement.style.display = 'none'; + this._bodyElement.style.display = this._isCollapsed ? 'none' : 'block'; this._commentsElement = $('div.comments-container').appendTo(this._bodyElement).getHTMLElement(); this._commentElements = []; for (let i = 0; i < this._commentThread.comments.length; i++) {