From 2a514165ef3eff79ff56ae5498ed013b41e315df Mon Sep 17 00:00:00 2001 From: Alex Ross Date: Thu, 16 Feb 2023 15:01:53 +0100 Subject: [PATCH] Add doc info to comments context keys (#174576) Fixes https://github.com/microsoft/vscode-docs/issues/6052 --- .../contrib/comments/browser/commentNode.ts | 6 +++++- .../comments/browser/commentThreadWidget.ts | 6 +++--- .../comments/common/commentContextKeys.ts | 20 ++++++++++++++++--- 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/src/vs/workbench/contrib/comments/browser/commentNode.ts b/src/vs/workbench/contrib/comments/browser/commentNode.ts index 87a32fe2123bbb..f8414f2b54ed31 100644 --- a/src/vs/workbench/contrib/comments/browser/commentNode.ts +++ b/src/vs/workbench/contrib/comments/browser/commentNode.ts @@ -44,6 +44,7 @@ import { CommentMenus } from 'vs/workbench/contrib/comments/browser/commentMenus import { Scrollable, ScrollbarVisibility } from 'vs/base/common/scrollable'; import { SmoothScrollableElement } from 'vs/base/browser/ui/scrollbar/scrollableElement'; import { DomEmitter } from 'vs/base/browser/event'; +import { CommentContextKeys } from 'vs/workbench/contrib/comments/common/commentContextKeys'; export class CommentNode extends Disposable { private _domNode: HTMLElement; @@ -104,7 +105,10 @@ 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._commentContextValue = CommentContextKeys.commentContext.bindTo(this._contextKeyService); + if (this.comment.contextValue) { + this._commentContextValue.set(this.comment.contextValue); + } this._commentMenus = this.commentService.getCommentMenus(this.owner); this._domNode.tabIndex = -1; diff --git a/src/vs/workbench/contrib/comments/browser/commentThreadWidget.ts b/src/vs/workbench/contrib/comments/browser/commentThreadWidget.ts index 370a60796b9739..7c9a90a09b558b 100644 --- a/src/vs/workbench/contrib/comments/browser/commentThreadWidget.ts +++ b/src/vs/workbench/contrib/comments/browser/commentThreadWidget.ts @@ -105,13 +105,13 @@ export class CommentThreadWidget extends this._styleElement = dom.createStyleSheet(this.container); - this._commentThreadContextValue = this._contextKeyService.createKey('commentThread', undefined); + this._commentThreadContextValue = CommentContextKeys.commentThreadContext.bindTo(this._contextKeyService); this._commentThreadContextValue.set(_commentThread.contextValue); - const commentControllerKey = this._contextKeyService.createKey('commentController', undefined); + const commentControllerKey = CommentContextKeys.commentControllerContext.bindTo(this._contextKeyService); const controller = this.commentService.getCommentController(this._owner); - if (controller) { + if (controller?.contextValue) { commentControllerKey.set(controller.contextValue); } diff --git a/src/vs/workbench/contrib/comments/common/commentContextKeys.ts b/src/vs/workbench/contrib/comments/common/commentContextKeys.ts index 3593481d5ca9be..c4b32556b316c5 100644 --- a/src/vs/workbench/contrib/comments/common/commentContextKeys.ts +++ b/src/vs/workbench/contrib/comments/common/commentContextKeys.ts @@ -3,15 +3,29 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ +import * as nls from 'vs/nls'; import { RawContextKey } from 'vs/platform/contextkey/common/contextkey'; + export namespace CommentContextKeys { /** * A context key that is set when the comment thread has no comments. */ - export const commentThreadIsEmpty = new RawContextKey('commentThreadIsEmpty', false); + export const commentThreadIsEmpty = new RawContextKey('commentThreadIsEmpty', false, { type: 'boolean', description: nls.localize('commentThreadIsEmpty', "Set when the comment thread has no comments") }); /** * A context key that is set when the comment has no input. */ - export const commentIsEmpty = new RawContextKey('commentIsEmpty', false); -} \ No newline at end of file + export const commentIsEmpty = new RawContextKey('commentIsEmpty', false, { type: 'boolean', description: nls.localize('commentIsEmpty', "Set when the comment has no input") }); + /** + * The context value of the comment. + */ + export const commentContext = new RawContextKey('comment', undefined, { type: 'string', description: nls.localize('comment', "The context value of the comment") }); + /** + * The context value of the comment thread. + */ + export const commentThreadContext = new RawContextKey('commentThread', undefined, { type: 'string', description: nls.localize('commentThread', "The context value of the comment thread") }); + /** + * The comment controller id associated with a comment thread. + */ + export const commentControllerContext = new RawContextKey('commentController', undefined, { type: 'string', description: nls.localize('commentController', "The comment controller id associated with a comment thread") }); +}