diff --git a/extensions/git-extended/src/review/reviewMode.ts b/extensions/git-extended/src/review/reviewMode.ts index 41bf6822913429d0ed9e2ada872a67ec639c30fb..fda563252f207bea4c4bebd6d85210997257a5ce 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 e52dc256ec6dd6aadd1a481bbf1266b14a7190f1..20c106667a66be351849c8fb2b98b056149fe14a 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 c0eec9275ac34e5205a38c1dcf670e969624539b..e3f74519604d5011a5b9cd82a5f8fe24a4aa6c79 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 94ec028e5218ccdc7cf8f2343545dedd10104248..fce9dddf1a9739ecd3ee97b2490d299f45789d3c 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 fa0a8afc25f02e99fe78d33374d6d739bf29dddf..bffc6b40294e121ae247b39f31932a95f2f66a80 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 d5020a8e37f2de90a97ae134c79239ddfdbff041..919a4fbddb98fdfec70c72f1bf2dadf9db41c3b7 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 fb249f99481cc45aea42551d7b4fe3e933555b66..7961f1aad943bada5ce94e038b697741e612bdf0 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 570e7b1937661bf391a3fa27b66aed450567f4f1..8ebbf34b5aa814ed96c8af55f4aec4c2bf2221fb 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 def9661a41d58f13babb8cca8efdd9e2ce13de48..5298e7c06b5aa836851b23624d62cdeddd764dee 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 8797d4ad3aa6831d836c634799e787b924018d25..5b8adb82f505f67d8b2168ed5f8e2901b92edf1d 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++) {