diff --git a/src/vs/workbench/api/browser/mainThreadComments.ts b/src/vs/workbench/api/browser/mainThreadComments.ts index df7790d8e3a..2f9c24b6da1 100644 --- a/src/vs/workbench/api/browser/mainThreadComments.ts +++ b/src/vs/workbench/api/browser/mainThreadComments.ts @@ -25,8 +25,6 @@ import { PanelRegistry, Extensions as PanelExtensions, PanelDescriptor } from 'v import { IRange, Range } from 'vs/editor/common/core/range'; import { Emitter, Event } from 'vs/base/common/event'; import { CancellationToken } from 'vs/base/common/cancellation'; -import { IContextKey } from 'vs/platform/contextkey/common/contextkey'; -import { CommentContextKeys } from 'vs/workbench/contrib/comments/common/commentContextKeys'; export class MainThreadDocumentCommentProvider implements modes.DocumentCommentProvider { private readonly _proxy: ExtHostCommentsShape; @@ -450,13 +448,8 @@ export class MainThreadComments extends Disposable implements MainThreadComments private _handlers = new Map(); private _commentControllers = new Map(); - private _activeCommentThread?: MainThreadCommentThread; - private _input?: modes.CommentInput; private _openPanelListener: IDisposable | null; - private _commentThreadEmpty: IContextKey; - private _commentEmpty: IContextKey; - constructor( extHostContext: IExtHostContext, @IEditorService private readonly _editorService: IEditorService, @@ -469,35 +462,6 @@ export class MainThreadComments extends Disposable implements MainThreadComments this._disposables = []; this._activeCommentThreadDisposables = []; this._proxy = extHostContext.getProxy(ExtHostContext.ExtHostComments); - - this._commentThreadEmpty = CommentContextKeys.commentThreadIsEmpty.bindTo(_commentService.contextKeyService); - this._commentEmpty = CommentContextKeys.commentIsEmpty.bindTo(_commentService.contextKeyService); - this._commentThreadEmpty.set(true); - this._commentEmpty.set(true); - - this._disposables.push(this._commentService.onDidChangeActiveCommentThread(async thread => { - let handle = (thread as MainThreadCommentThread).controllerHandle; - let controller = this._commentControllers.get(handle); - - if (!controller) { - return; - } - - this._activeCommentThreadDisposables = dispose(this._activeCommentThreadDisposables); - this._activeCommentThread = thread as MainThreadCommentThread; - controller.activeCommentThread = this._activeCommentThread; - - this._commentThreadEmpty.set(controller.activeCommentThread.comments!.length === 0); - - this._activeCommentThreadDisposables.push(this._activeCommentThread.onDidChangeInput(input => { // todo, dispose - this._input = input; - this._proxy.$onCommentWidgetInputChange(handle, URI.parse(this._activeCommentThread!.resource), this._activeCommentThread!.range, this._input ? this._input.value : undefined); - this._commentEmpty.set(this._input ? true : this._input!.value.length === 0); - })); - - await this._proxy.$onActiveCommentThreadChange(controller.handle, controller.activeCommentThread.commentThreadHandle); - await this._proxy.$onCommentWidgetInputChange(controller.handle, URI.parse(this._activeCommentThread!.resource), this._activeCommentThread.range, this._input ? this._input.value : undefined); - })); } $registerCommentController(handle: number, id: string, label: string): void { diff --git a/src/vs/workbench/api/common/extHost.protocol.ts b/src/vs/workbench/api/common/extHost.protocol.ts index 609c00305cf..b32a1fd51ee 100644 --- a/src/vs/workbench/api/common/extHost.protocol.ts +++ b/src/vs/workbench/api/common/extHost.protocol.ts @@ -1212,7 +1212,6 @@ export interface ExtHostCommentsShape { $createNewCommentThread(handle: number, document: UriComponents, range: IRange, text: string): Promise; $createCommentThreadTemplate(commentControllerHandle: number, uriComponents: UriComponents, range: IRange): void; $onCommentWidgetInputChange(commentControllerHandle: number, document: UriComponents, range: IRange, input: string | undefined): Promise; - $onActiveCommentThreadChange(commentControllerHandle: number, threadHandle: number | undefined): Promise; $provideCommentingRanges(commentControllerHandle: number, uriComponents: UriComponents, token: CancellationToken): Promise; $checkStaticContribution(commentControllerHandle: number): Promise; $provideReactionGroup(commentControllerHandle: number): Promise; diff --git a/src/vs/workbench/api/common/extHostComments.ts b/src/vs/workbench/api/common/extHostComments.ts index 3182fb118d0..225cd2b2753 100644 --- a/src/vs/workbench/api/common/extHostComments.ts +++ b/src/vs/workbench/api/common/extHostComments.ts @@ -126,17 +126,6 @@ export class ExtHostComments implements ExtHostCommentsShape { return Promise.resolve(commentControllerHandle); } - $onActiveCommentThreadChange(commentControllerHandle: number, threadHandle: number): Promise { - const commentController = this._commentControllers.get(commentControllerHandle); - - if (!commentController) { - return Promise.resolve(undefined); - } - - commentController.$onActiveCommentThreadChange(threadHandle); - return Promise.resolve(threadHandle); - } - $provideCommentingRanges(commentControllerHandle: number, uriComponents: UriComponents, token: CancellationToken): Promise { const commentController = this._commentControllers.get(commentControllerHandle); @@ -644,15 +633,6 @@ class ExtHostCommentController implements vscode.CommentController { } public inputBox: ExtHostCommentInputBox | undefined; - private _activeCommentThread: ExtHostCommentThread | undefined; - - public get activeCommentThread(): ExtHostCommentThread | undefined { - if (this._activeCommentThread && this._activeCommentThread.isDisposed) { - this._activeCommentThread = undefined; - } - - return this._activeCommentThread; - } public activeCommentingRange?: vscode.Range; @@ -716,10 +696,6 @@ class ExtHostCommentController implements vscode.CommentController { } } - $onActiveCommentThreadChange(threadHandle: number) { - this._activeCommentThread = this.getCommentThread(threadHandle); - } - getCommentThread(handle: number) { return this._threads.get(handle); } diff --git a/src/vs/workbench/contrib/comments/browser/commentNode.ts b/src/vs/workbench/contrib/comments/browser/commentNode.ts index 1e5b13762f7..2bc22702044 100644 --- a/src/vs/workbench/contrib/comments/browser/commentNode.ts +++ b/src/vs/workbench/contrib/comments/browser/commentNode.ts @@ -403,14 +403,14 @@ export class CommentNode extends Disposable { uri: this._commentEditor.getModel()!.uri, value: this.comment.body.value }; - this.commentService.setActiveCommentThread(commentThread); + this.commentService.onDidChangeActiveCommentThread(commentThread); this._commentEditorDisposables.push(this._commentEditor.onDidFocusEditorWidget(() => { commentThread.input = { uri: this._commentEditor!.getModel()!.uri, value: this.comment.body.value }; - this.commentService.setActiveCommentThread(commentThread); + this.commentService.onDidChangeActiveCommentThread(commentThread); })); this._commentEditorDisposables.push(this._commentEditor.onDidChangeModelContent(e => { @@ -462,7 +462,7 @@ export class CommentNode extends Disposable { uri: this._commentEditor.getModel()!.uri, value: newBody }; - this.commentService.setActiveCommentThread(commentThread); + this.commentService.onDidChangeActiveCommentThread(commentThread); let commandId = this.comment.editCommand.id; let args = this.comment.editCommand.arguments || []; @@ -500,7 +500,6 @@ export class CommentNode extends Disposable { if (result.confirmed) { try { if (this.comment.deleteCommand) { - this.commentService.setActiveCommentThread(this.commentThread as modes.CommentThread2); let commandId = this.comment.deleteCommand.id; let args = this.comment.deleteCommand.arguments || []; diff --git a/src/vs/workbench/contrib/comments/browser/commentService.ts b/src/vs/workbench/contrib/comments/browser/commentService.ts index bcfe26b9316..6a25b32ae2c 100644 --- a/src/vs/workbench/contrib/comments/browser/commentService.ts +++ b/src/vs/workbench/contrib/comments/browser/commentService.ts @@ -15,8 +15,8 @@ import { assign } from 'vs/base/common/objects'; import { ICommentThreadChangedEvent } from 'vs/workbench/contrib/comments/common/commentModel'; import { MainThreadCommentController } from 'vs/workbench/api/browser/mainThreadComments'; import { CommentMenus } from 'vs/workbench/contrib/comments/browser/commentMenus'; -import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey'; -import { IContext } from 'vs/base/parts/quickopen/browser/quickOpenModel'; +import { IContextKeyService, IContextKey } from 'vs/platform/contextkey/common/contextkey'; +import { CommentContextKeys } from 'vs/workbench/contrib/comments/common/commentContextKeys'; export const ICommentService = createDecorator('commentService'); @@ -40,9 +40,7 @@ export interface ICommentService { readonly onDidSetResourceCommentInfos: Event; readonly onDidSetAllCommentThreads: Event; readonly onDidUpdateCommentThreads: Event; - readonly onDidChangeActiveCommentThread: Event; readonly onDidChangeActiveCommentingRange: Event<{ range: Range, commentingRangesInfo: CommentingRanges }>; - readonly onDidChangeInput: Event; readonly onDidSetDataProvider: Event; readonly onDidDeleteDataProvider: Event; readonly contextKeyService: IContextKeyService; @@ -72,8 +70,7 @@ export interface ICommentService { deleteReaction(owner: string, resource: URI, comment: Comment, reaction: CommentReaction): Promise; getReactionGroup(owner: string): CommentReaction[] | undefined; toggleReaction(owner: string, resource: URI, thread: CommentThread2, comment: Comment, reaction: CommentReaction): Promise; - setActiveCommentThread(commentThread: CommentThread | null): void; - setInput(input: string): void; + onDidChangeActiveCommentThread(commentThread: CommentThread | null): void; } export class CommentService extends Disposable implements ICommentService { @@ -94,11 +91,6 @@ export class CommentService extends Disposable implements ICommentService { private readonly _onDidUpdateCommentThreads: Emitter = this._register(new Emitter()); readonly onDidUpdateCommentThreads: Event = this._onDidUpdateCommentThreads.event; - private readonly _onDidChangeActiveCommentThread = this._register(new Emitter()); - readonly onDidChangeActiveCommentThread: Event = this._onDidChangeActiveCommentThread.event; - - private readonly _onDidChangeInput: Emitter = this._register(new Emitter()); - readonly onDidChangeInput: Event = this._onDidChangeInput.event; private readonly _onDidChangeActiveCommentingRange: Emitter<{ range: Range, commentingRangesInfo: CommentingRanges @@ -112,6 +104,9 @@ export class CommentService extends Disposable implements ICommentService { private _commentControls = new Map(); private _commentMenus = new Map(); + + private _activeThreadIsEmpty: IContextKey; + contextKeyService: IContextKeyService; constructor( @@ -120,14 +115,11 @@ export class CommentService extends Disposable implements ICommentService { ) { super(); this.contextKeyService = contextKeyService.createScoped(); + this._activeThreadIsEmpty = CommentContextKeys.commentThreadIsEmpty.bindTo(this.contextKeyService); } - setActiveCommentThread(commentThread: CommentThread | null) { - this._onDidChangeActiveCommentThread.fire(commentThread); - } - - setInput(input: string) { - this._onDidChangeInput.fire(input); + onDidChangeActiveCommentThread(commentThread: CommentThread | null) { + this._activeThreadIsEmpty.set(!!commentThread && !!commentThread.comments && !!commentThread.comments.length); } setDocumentComments(resource: URI, commentInfos: ICommentInfo[]): void { diff --git a/src/vs/workbench/contrib/comments/browser/commentThreadWidget.ts b/src/vs/workbench/contrib/comments/browser/commentThreadWidget.ts index f337ccca2d1..79640fe0665 100644 --- a/src/vs/workbench/contrib/comments/browser/commentThreadWidget.ts +++ b/src/vs/workbench/contrib/comments/browser/commentThreadWidget.ts @@ -199,7 +199,7 @@ export class ReviewZoneWidget extends ZoneWidget implements ICommentThreadWidget container.appendChild(this._bodyElement); dom.addDisposableListener(this._bodyElement, dom.EventType.FOCUS_IN, e => { - this.commentService.setActiveCommentThread(this._commentThread); + this.commentService.onDidChangeActiveCommentThread(this._commentThread); }); } @@ -243,7 +243,7 @@ export class ReviewZoneWidget extends ZoneWidget implements ICommentThreadWidget } else { const deleteCommand = (this._commentThread as modes.CommentThread2).deleteCommand; if (deleteCommand) { - this.commentService.setActiveCommentThread(this._commentThread); + this.commentService.onDidChangeActiveCommentThread(this._commentThread); return this.commandService.executeCommand(deleteCommand.id, ...(deleteCommand.arguments || [])); } else if (this._commentEditor.getValue() === '') { this.dispose(); @@ -475,7 +475,7 @@ export class ReviewZoneWidget extends ZoneWidget implements ICommentThreadWidget uri: this._commentEditor.getModel()!.uri, value: this._commentEditor.getValue() }; - this.commentService.setActiveCommentThread(this._commentThread); + this.commentService.onDidChangeActiveCommentThread(this._commentThread); })); this._commentThreadDisposables.push(this._commentEditor.getModel()!.onDidChangeContent(() => { @@ -687,7 +687,7 @@ export class ReviewZoneWidget extends ZoneWidget implements ICommentThreadWidget uri: this._commentEditor.getModel()!.uri, value: this._commentEditor.getValue() }; - this.commentService.setActiveCommentThread(this._commentThread); + this.commentService.onDidChangeActiveCommentThread(this._commentThread); await this.commandService.executeCommand(acceptInputCommand.id, ...(acceptInputCommand.arguments || [])); })); @@ -712,7 +712,7 @@ export class ReviewZoneWidget extends ZoneWidget implements ICommentThreadWidget uri: this._commentEditor.getModel()!.uri, value: this._commentEditor.getValue() }; - this.commentService.setActiveCommentThread(this._commentThread); + this.commentService.onDidChangeActiveCommentThread(this._commentThread); await this.commandService.executeCommand(command.id, ...(command.arguments || [])); })); }); @@ -783,7 +783,7 @@ export class ReviewZoneWidget extends ZoneWidget implements ICommentThreadWidget uri: this._commentEditor.getModel()!.uri, value: this._commentEditor.getValue() }; - this.commentService.setActiveCommentThread(this._commentThread); + this.commentService.onDidChangeActiveCommentThread(this._commentThread); let commandId = commentThread.acceptInputCommand.id; let args = commentThread.acceptInputCommand.arguments || []; diff --git a/src/vs/workbench/contrib/comments/browser/simpleCommentEditor.ts b/src/vs/workbench/contrib/comments/browser/simpleCommentEditor.ts index f158e3f3294..f30b5f16a29 100644 --- a/src/vs/workbench/contrib/comments/browser/simpleCommentEditor.ts +++ b/src/vs/workbench/contrib/comments/browser/simpleCommentEditor.ts @@ -22,6 +22,7 @@ import { INotificationService } from 'vs/platform/notification/common/notificati import { IAccessibilityService } from 'vs/platform/accessibility/common/accessibility'; import { ICodeEditor } from 'vs/editor/browser/editorBrowser'; import { ICommentThreadWidget } from 'vs/workbench/contrib/comments/common/commentThreadWidget'; +import { CommentContextKeys } from 'vs/workbench/contrib/comments/common/commentContextKeys'; export const ctxCommentEditorFocused = new RawContextKey('commentEditorFocused', false); @@ -30,6 +31,7 @@ export class SimpleCommentEditor extends CodeEditorWidget { private _parentEditor: ICodeEditor; private _parentThread: ICommentThreadWidget; private _commentEditorFocused: IContextKey; + private _commentEditorEmpty: IContextKey; constructor( domElement: HTMLElement, @@ -57,10 +59,16 @@ export class SimpleCommentEditor extends CodeEditorWidget { super(domElement, options, codeEditorWidgetOptions, instantiationService, codeEditorService, commandService, contextKeyService, themeService, notificationService, accessibilityService); this._commentEditorFocused = ctxCommentEditorFocused.bindTo(this._contextKeyService); + this._commentEditorEmpty = CommentContextKeys.commentIsEmpty.bindTo(this._contextKeyService); this._parentEditor = parentEditor; this._parentThread = parentThread; - this._register(this.onDidFocusEditorWidget(_ => this._commentEditorFocused.set(true))); + this._register(this.onDidFocusEditorWidget(_ => { + this._commentEditorFocused.set(true); + this._commentEditorEmpty.set(!this.getValue()); + })); + + this._register(this.onDidChangeModelContent(e => this._commentEditorEmpty.set(!this.getValue()))); this._register(this.onDidBlurEditorWidget(_ => this._commentEditorFocused.reset())); } diff --git a/src/vs/workbench/contrib/comments/common/commentContextKeys.ts b/src/vs/workbench/contrib/comments/common/commentContextKeys.ts index b58660a19cc..c4af337d789 100644 --- a/src/vs/workbench/contrib/comments/common/commentContextKeys.ts +++ b/src/vs/workbench/contrib/comments/common/commentContextKeys.ts @@ -3,7 +3,7 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -import { ContextKeyExpr, RawContextKey } from 'vs/platform/contextkey/common/contextkey'; +import { RawContextKey } from 'vs/platform/contextkey/common/contextkey'; export namespace CommentContextKeys { /**