diff --git a/src/vs/editor/common/modes.ts b/src/vs/editor/common/modes.ts index d6ec3a832a8..90833069146 100644 --- a/src/vs/editor/common/modes.ts +++ b/src/vs/editor/common/modes.ts @@ -1288,6 +1288,7 @@ export interface CommentThread2 { resource: string | null; range: IRange; label: string; + contextValue: string | undefined; comments: Comment[] | undefined; onDidChangeComments: Event; collapsibleState?: CommentThreadCollapsibleState; @@ -1326,6 +1327,7 @@ export interface CommentThread { collapsibleState?: CommentThreadCollapsibleState; reply?: Command; isDisposed?: boolean; + contextValue?: string; } /** @@ -1364,6 +1366,7 @@ export interface Comment { readonly body: IMarkdownString; readonly userName: string; readonly userIconPath?: string; + readonly contextValue?: string; readonly canEdit?: boolean; readonly canDelete?: boolean; readonly selectCommand?: Command; diff --git a/src/vs/workbench/api/browser/mainThreadComments.ts b/src/vs/workbench/api/browser/mainThreadComments.ts index 2f9c24b6da1..3371106e1a5 100644 --- a/src/vs/workbench/api/browser/mainThreadComments.ts +++ b/src/vs/workbench/api/browser/mainThreadComments.ts @@ -106,6 +106,16 @@ export class MainThreadCommentThread implements modes.CommentThread2 { this._onDidChangeLabel.fire(this._label); } + private _contextValue: string | undefined; + + get contextValue(): string | undefined { + return this._contextValue; + } + + set contextValue(context: string | undefined) { + this._contextValue = context; + } + private _onDidChangeLabel = new Emitter(); get onDidChangeLabel(): Event { return this._onDidChangeLabel.event; } @@ -204,6 +214,7 @@ export class MainThreadCommentThread implements modes.CommentThread2 { batchUpdate( range: IRange, label: string, + contextValue: string | undefined, comments: modes.Comment[], acceptInputCommand: modes.Command | undefined, additionalCommands: modes.Command[], @@ -211,6 +222,7 @@ export class MainThreadCommentThread implements modes.CommentThread2 { collapsibleState: modes.CommentThreadCollapsibleState) { this._range = range; this._label = label; + this._contextValue = contextValue; this._comments = comments; this._acceptInputCommand = acceptInputCommand; this._additionalCommands = additionalCommands; @@ -323,13 +335,14 @@ export class MainThreadCommentController { resource: UriComponents, range: IRange, label: string, + contextValue: string | undefined, comments: modes.Comment[], acceptInputCommand: modes.Command | undefined, additionalCommands: modes.Command[], deleteCommand: modes.Command | undefined, collapsibleState: modes.CommentThreadCollapsibleState): void { let thread = this.getKnownThread(commentThreadHandle); - thread.batchUpdate(range, label, comments, acceptInputCommand, additionalCommands, deleteCommand, collapsibleState); + thread.batchUpdate(range, label, contextValue, comments, acceptInputCommand, additionalCommands, deleteCommand, collapsibleState); this._commentService.updateComments(this._uniqueId, { added: [], @@ -521,6 +534,7 @@ export class MainThreadComments extends Disposable implements MainThreadComments resource: UriComponents, range: IRange, label: string, + contextValue: string | undefined, comments: modes.Comment[], acceptInputCommand: modes.Command | undefined, additionalCommands: modes.Command[], @@ -532,7 +546,7 @@ export class MainThreadComments extends Disposable implements MainThreadComments return undefined; } - return provider.updateCommentThread(commentThreadHandle, threadId, resource, range, label, comments, acceptInputCommand, additionalCommands, deleteCommand, collapsibleState); + return provider.updateCommentThread(commentThreadHandle, threadId, resource, range, label, contextValue, comments, acceptInputCommand, additionalCommands, deleteCommand, collapsibleState); } $deleteCommentThread(handle: number, commentThreadHandle: number) { diff --git a/src/vs/workbench/api/common/extHost.protocol.ts b/src/vs/workbench/api/common/extHost.protocol.ts index b32a1fd51ee..afad2ca86e6 100644 --- a/src/vs/workbench/api/common/extHost.protocol.ts +++ b/src/vs/workbench/api/common/extHost.protocol.ts @@ -138,7 +138,7 @@ export interface MainThreadCommentsShape extends IDisposable { $unregisterCommentController(handle: number): void; $updateCommentControllerFeatures(handle: number, features: CommentProviderFeatures): void; $createCommentThread(handle: number, commentThreadHandle: number, threadId: string, resource: UriComponents, range: IRange): modes.CommentThread2 | undefined; - $updateCommentThread(handle: number, commentThreadHandle: number, threadId: string, resource: UriComponents, range: IRange, label: string, comments: modes.Comment[], acceptInputCommand: modes.Command | undefined, additionalCommands: modes.Command[], deleteCommand: modes.Command | undefined, collapseState: modes.CommentThreadCollapsibleState): void; + $updateCommentThread(handle: number, commentThreadHandle: number, threadId: string, resource: UriComponents, range: IRange, label: string, contextValue: string | undefined, comments: modes.Comment[], acceptInputCommand: modes.Command | undefined, additionalCommands: modes.Command[], deleteCommand: modes.Command | undefined, collapseState: modes.CommentThreadCollapsibleState): void; $deleteCommentThread(handle: number, commentThreadHandle: number): void; $setInputValue(handle: number, input: string): void; $registerDocumentCommentProvider(handle: number, features: CommentProviderFeatures): void; diff --git a/src/vs/workbench/api/common/extHostComments.ts b/src/vs/workbench/api/common/extHostComments.ts index de6aa82e298..fb783e83775 100644 --- a/src/vs/workbench/api/common/extHostComments.ts +++ b/src/vs/workbench/api/common/extHostComments.ts @@ -496,6 +496,17 @@ export class ExtHostCommentThread implements vscode.CommentThread { this._onDidUpdateCommentThread.fire(); } + private _contextValue: string | undefined; + + get contextValue(): string | undefined { + return this._contextValue; + } + + set contextValue(context: string | undefined) { + this._contextValue = context; + this._onDidUpdateCommentThread.fire(); + } + get comments(): vscode.Comment[] { return this._comments; } @@ -592,6 +603,7 @@ export class ExtHostCommentThread implements vscode.CommentThread { eventuallyUpdateCommentThread(): void { const commentThreadRange = extHostTypeConverter.Range.from(this._range); const label = this.label; + const contextValue = this.contextValue; const comments = this._comments.map(cmt => { return convertToModeComment2(this, this._commentController, cmt, this._commandsConverter, this._commentsMap); }); const acceptInputCommand = this._acceptInputCommand ? this._commandsConverter.toInternal(this._acceptInputCommand) : undefined; const additionalCommands = this._additionalCommands ? this._additionalCommands.map(x => this._commandsConverter.toInternal(x)) : []; @@ -605,6 +617,7 @@ export class ExtHostCommentThread implements vscode.CommentThread { this._uri, commentThreadRange, label, + contextValue, comments, acceptInputCommand, additionalCommands, @@ -851,6 +864,7 @@ function convertToModeComment2(thread: ExtHostCommentThread, commentController: return { commentId: vscodeComment.id || vscodeComment.commentId, mode: vscodeComment.mode, + contextValue: vscodeComment.contextValue, uniqueIdInThread: commentUniqueId, body: extHostTypeConverter.MarkdownString.from(vscodeComment.body), userName: vscodeComment.author ? vscodeComment.author.name : vscodeComment.userName, diff --git a/src/vs/workbench/contrib/comments/browser/commentMenus.ts b/src/vs/workbench/contrib/comments/browser/commentMenus.ts index d6b7767814b..3d83ab86f0c 100644 --- a/src/vs/workbench/contrib/comments/browser/commentMenus.ts +++ b/src/vs/workbench/contrib/comments/browser/commentMenus.ts @@ -42,6 +42,7 @@ export class CommentMenus implements IDisposable { private getMenu(menuId: MenuId, contextKeyService: IContextKeyService): IMenu { const menu = this.menuService.createMenu(menuId, contextKeyService); + const primary: IAction[] = []; const secondary: IAction[] = []; const result = { primary, secondary }; diff --git a/src/vs/workbench/contrib/comments/browser/commentNode.ts b/src/vs/workbench/contrib/comments/browser/commentNode.ts index 139b9b867ea..8d9cfdc2585 100644 --- a/src/vs/workbench/contrib/comments/browser/commentNode.ts +++ b/src/vs/workbench/contrib/comments/browser/commentNode.ts @@ -38,7 +38,7 @@ import { ICommentThreadWidget } from 'vs/workbench/contrib/comments/common/comme import { MenuItemAction } from 'vs/platform/actions/common/actions'; import { ContextAwareMenuEntryActionViewItem } from 'vs/platform/actions/browser/menuEntryActionViewItem'; import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding'; -import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey'; +import { IContextKeyService, IContextKey } from 'vs/platform/contextkey/common/contextkey'; import { CommentFormActions } from 'vs/workbench/contrib/comments/browser/commentFormActions'; const UPDATE_COMMENT_LABEL = nls.localize('label.updateComment', "Update comment"); @@ -63,6 +63,7 @@ export class CommentNode extends Disposable { private _errorEditingContainer: HTMLElement; private _isPendingLabel: HTMLElement; private _contextKeyService: IContextKeyService; + private _commentContextValue: IContextKey; private _deleteAction: Action; protected actionRunner?: IActionRunner; @@ -101,6 +102,8 @@ export class CommentNode extends Disposable { this._domNode = dom.$('div.review-comment'); this._contextKeyService = contextKeyService.createScoped(this._domNode); + this._commentContextValue = this._contextKeyService.createKey('comment', comment.contextValue); + this._domNode.tabIndex = 0; const avatar = dom.append(this._domNode, dom.$('div.avatar-container')); if (comment.userIconPath) { @@ -689,6 +692,12 @@ export class CommentNode extends Disposable { if (this.comment.commentReactions && this.comment.commentReactions.length) { this.createReactionsContainer(this._commentDetailsContainer); } + + if (this.comment.contextValue) { + this._commentContextValue.set(this.comment.contextValue); + } else { + this._commentContextValue.reset(); + } } focus() { diff --git a/src/vs/workbench/contrib/comments/browser/commentThreadWidget.ts b/src/vs/workbench/contrib/comments/browser/commentThreadWidget.ts index 40153cc1c80..d9a4fb60eac 100644 --- a/src/vs/workbench/contrib/comments/browser/commentThreadWidget.ts +++ b/src/vs/workbench/contrib/comments/browser/commentThreadWidget.ts @@ -81,6 +81,7 @@ export class ReviewZoneWidget extends ZoneWidget implements ICommentThreadWidget private _error: HTMLElement; private _contextKeyService: IContextKeyService; private _threadIsEmpty: IContextKey; + private _commentThreadContextValue: IContextKey; private _commentEditorIsEmpty: IContextKey; private _commentFormActions: CommentFormActions; @@ -123,6 +124,7 @@ export class ReviewZoneWidget extends ZoneWidget implements ICommentThreadWidget this._contextKeyService = contextKeyService.createScoped(this.domNode); this._threadIsEmpty = CommentContextKeys.commentThreadIsEmpty.bindTo(this._contextKeyService); this._threadIsEmpty.set(!_commentThread.comments || !_commentThread.comments.length); + this._commentThreadContextValue = contextKeyService.createKey('commentThread', _commentThread.contextValue); this._resizeObserver = null; this._isExpanded = _commentThread.collapsibleState ? _commentThread.collapsibleState === modes.CommentThreadCollapsibleState.Expanded : undefined; @@ -381,6 +383,12 @@ export class ReviewZoneWidget extends ZoneWidget implements ICommentThreadWidget this.hide(); } } + + if (this._commentThread.contextValue) { + this._commentThreadContextValue.set(this._commentThread.contextValue); + } else { + this._commentThreadContextValue.reset(); + } } updateDraftMode(draftMode: modes.DraftMode | undefined) {