From b98a5ad0288babb92f36cdbe69eee3a40d7f8af5 Mon Sep 17 00:00:00 2001 From: rebornix Date: Thu, 21 Feb 2019 17:03:26 -0800 Subject: [PATCH] register comments panel when there is comment control registered --- src/vs/editor/common/modes.ts | 8 ++-- src/vs/vscode.proposed.d.ts | 5 ++- .../electron-browser/mainThreadComments.ts | 45 +++++++++++++++---- 3 files changed, 44 insertions(+), 14 deletions(-) diff --git a/src/vs/editor/common/modes.ts b/src/vs/editor/common/modes.ts index de27cba80c8..6af7984b5fd 100644 --- a/src/vs/editor/common/modes.ts +++ b/src/vs/editor/common/modes.ts @@ -1318,22 +1318,22 @@ export interface CommentThreadChangedEvent { /** * Added comment threads. */ - readonly added: CommentThread[]; + readonly added: (CommentThread | CommentThread2)[]; /** * Removed comment threads. */ - readonly removed: CommentThread[]; + readonly removed: (CommentThread | CommentThread2)[]; /** * Changed comment threads. */ - readonly changed: CommentThread[]; + readonly changed: (CommentThread | CommentThread2)[]; /** * changed draft mode. */ - readonly draftMode: DraftMode; + readonly draftMode?: DraftMode; } /** diff --git a/src/vs/vscode.proposed.d.ts b/src/vs/vscode.proposed.d.ts index 1b3eb561ded..7b14b267ed2 100644 --- a/src/vs/vscode.proposed.d.ts +++ b/src/vs/vscode.proposed.d.ts @@ -793,6 +793,7 @@ declare module 'vscode' { * Whether the thread should be collapsed or expanded when opening the document. Defaults to Collapsed. */ collapsibleState?: CommentThreadCollapsibleState; + dispose?(): void; } /** @@ -956,8 +957,8 @@ declare module 'vscode' { readonly id: string; readonly label: string; /** - * The active (focused) comment widget. - */ + * The active (focused) comment widget. + */ readonly widget?: CommentWidget; createCommentThread(id: string, resource: Uri, range: Range, comments: Comment[], acceptInputCommands: Command[], collapsibleState?: CommentThreadCollapsibleState): CommentThread; dispose(): void; diff --git a/src/vs/workbench/api/electron-browser/mainThreadComments.ts b/src/vs/workbench/api/electron-browser/mainThreadComments.ts index 587d8c162fa..cd7fc02cf5d 100644 --- a/src/vs/workbench/api/electron-browser/mainThreadComments.ts +++ b/src/vs/workbench/api/electron-browser/mainThreadComments.ts @@ -165,6 +165,7 @@ export class MainThreadCommentControl { private _threads: Map = new Map(); constructor( private _proxy: ExtHostCommentsShape, + private _commentService: ICommentService, private _handle: number, private _id: string, private _label: string @@ -184,12 +185,26 @@ export class MainThreadCommentControl { ); this._threads.set(commentThreadHandle, thread); + this._commentService.updateComments(`${this.handle}`, { + added: [thread], + removed: [], + changed: [], + draftMode: modes.DraftMode.NotSupported + }); return thread; } deleteCommentThread(commentThreadHandle: number) { let thread = this._threads.get(commentThreadHandle); + this._threads.delete(commentThreadHandle); + + this._commentService.updateComments(`${this.handle}`, { + added: [], + removed: [thread], + changed: [], + draftMode: modes.DraftMode.NotSupported + }); thread.dispose(); } @@ -284,9 +299,15 @@ export class MainThreadComments extends Disposable implements MainThreadComments } $registerCommentControl(handle: number, id: string, label: string): void { - const provider = new MainThreadCommentControl(this._proxy, handle, id, label); + const provider = new MainThreadCommentControl(this._proxy, this._commentService, handle, id, label); this._commentService.registerCommentControl(String(handle), provider); this._commentControls.set(handle, provider); + + const commentsPanelAlreadyConstructed = this._panelService.getPanels().some(panel => panel.id === COMMENTS_PANEL_ID); + if (!commentsPanelAlreadyConstructed) { + this.registerPanel(commentsPanelAlreadyConstructed); + } + this._commentService.setWorkspaceComments(String(handle), []); } $createCommentThread(handle: number, commentThreadHandle: number, threadId: string, resource: UriComponents, range: IRange, comments: modes.Comment[], commands: modes.Command[], collapseState: modes.CommentThreadCollapsibleState): modes.CommentThread2 | undefined { @@ -350,6 +371,18 @@ export class MainThreadComments extends Disposable implements MainThreadComments this._commentService.registerDataProvider(providerId, handler); } + private registerPanel(commentsPanelAlreadyConstructed: boolean) { + if (!commentsPanelAlreadyConstructed) { + Registry.as(PanelExtensions.Panels).registerPanel(new PanelDescriptor( + CommentsPanel, + COMMENTS_PANEL_ID, + COMMENTS_PANEL_TITLE, + 'commentsPanel', + 10 + )); + } + } + /** * If the comments panel has never been opened, the constructor for it has not yet run so it has * no listeners for comment threads being set or updated. Listen for the panel opening for the @@ -383,13 +416,9 @@ export class MainThreadComments extends Disposable implements MainThreadComments this._handlers.set(handle, providerId); const commentsPanelAlreadyConstructed = this._panelService.getPanels().some(panel => panel.id === COMMENTS_PANEL_ID); - Registry.as(PanelExtensions.Panels).registerPanel(new PanelDescriptor( - CommentsPanel, - COMMENTS_PANEL_ID, - COMMENTS_PANEL_TITLE, - 'commentsPanel', - 10 - )); + if (!commentsPanelAlreadyConstructed) { + this.registerPanel(commentsPanelAlreadyConstructed); + } const openPanel = this._configurationService.getValue('comments').openPanel; -- GitLab