From e42c30a2942c39cdaf17b854df532e628fd64f41 Mon Sep 17 00:00:00 2001 From: Peng Lyu Date: Mon, 4 Mar 2019 11:37:18 -0800 Subject: [PATCH] CommentController. --- src/vs/vscode.proposed.d.ts | 12 +++- .../electron-browser/mainThreadComments.ts | 52 +++++++------- src/vs/workbench/api/node/extHost.api.impl.ts | 4 +- src/vs/workbench/api/node/extHost.protocol.ts | 6 +- src/vs/workbench/api/node/extHostComments.ts | 70 +++++++++---------- .../electron-browser/commentService.ts | 8 +-- 6 files changed, 80 insertions(+), 72 deletions(-) diff --git a/src/vs/vscode.proposed.d.ts b/src/vs/vscode.proposed.d.ts index 71a4201a35f..9a662635b70 100644 --- a/src/vs/vscode.proposed.d.ts +++ b/src/vs/vscode.proposed.d.ts @@ -980,7 +980,7 @@ declare module 'vscode' { input: string; } - export interface CommentControl { + export interface CommentController { readonly id: string; readonly label: string; /** @@ -997,11 +997,19 @@ declare module 'vscode' { } namespace comment { - export function createCommentControl(id: string, label: string): CommentControl; + export function createCommentController(id: string, label: string): CommentController; } namespace workspace { + /** + * DEPRECATED + * Use vscode.comment.createCommentController instead. + */ export function registerDocumentCommentProvider(provider: DocumentCommentProvider): Disposable; + /** + * DEPRECATED + * Use vscode.comment.createCommentController instead and we don't differentiate document comments and workspace comments anymore. + */ export function registerWorkspaceCommentProvider(provider: WorkspaceCommentProvider): Disposable; } diff --git a/src/vs/workbench/api/electron-browser/mainThreadComments.ts b/src/vs/workbench/api/electron-browser/mainThreadComments.ts index 56032c8bd0e..2d5e9f9c61d 100644 --- a/src/vs/workbench/api/electron-browser/mainThreadComments.ts +++ b/src/vs/workbench/api/electron-browser/mainThreadComments.ts @@ -132,7 +132,7 @@ export class MainThreadCommentThread implements modes.CommentThread2 { constructor( public commentThreadHandle: number, - public control: MainThreadCommentControl, + public controller: MainThreadCommentController, public extensionId: string, public threadId: string, public resource: string, @@ -151,7 +151,7 @@ export class MainThreadCommentThread implements modes.CommentThread2 { toJSON(): any { return { $mid: 7, - commentControlHandle: this.control.handle, + commentControlHandle: this.controller.handle, commentThreadHandle: this.commentThreadHandle, }; } @@ -180,7 +180,7 @@ export class MainThreadCommentingRanges implements modes.CommentingRanges { constructor( public commentingRangesHandle: number, - public control: MainThreadCommentControl, + public controller: MainThreadCommentController, public resource: URI, private _ranges: IRange[], private _newCommentThreadCommand: modes.Command, @@ -192,7 +192,7 @@ export class MainThreadCommentingRanges implements modes.CommentingRanges { } } -export class MainThreadCommentControl { +export class MainThreadCommentController { get handle(): number { return this._handle; } @@ -352,7 +352,7 @@ export class MainThreadComments extends Disposable implements MainThreadComments private _documentProviders = new Map(); private _workspaceProviders = new Map(); private _handlers = new Map(); - private _commentControls = new Map(); + private _commentControllers = new Map(); private _activeCommentThread?: MainThreadCommentThread; private _activeComment?: modes.Comment; @@ -372,9 +372,9 @@ export class MainThreadComments extends Disposable implements MainThreadComments this._activeCommentThreadDisposables = []; this._proxy = extHostContext.getProxy(ExtHostContext.ExtHostComments); this._disposables.push(this._commentService.onDidChangeActiveCommentThread(async thread => { - let control = (thread as MainThreadCommentThread).control; + let controller = (thread as MainThreadCommentThread).controller; - if (!control) { + if (!controller) { return; } @@ -383,26 +383,26 @@ export class MainThreadComments extends Disposable implements MainThreadComments this._activeCommentThreadDisposables.push(this._activeCommentThread.onDidChangeInput(input => { // todo, dispose this._input = input; - this._proxy.$onActiveCommentWidgetChange(control.handle, this._activeCommentThread, this._activeComment, this._input ? this._input.value : undefined); + this._proxy.$onActiveCommentWidgetChange(controller.handle, this._activeCommentThread, this._activeComment, this._input ? this._input.value : undefined); })); - await this._proxy.$onActiveCommentWidgetChange(control.handle, this._activeCommentThread, this._activeComment, this._input ? this._input.value : undefined); + await this._proxy.$onActiveCommentWidgetChange(controller.handle, this._activeCommentThread, this._activeComment, this._input ? this._input.value : undefined); })); this._disposables.push(this._commentService.onDidChangeActiveCommentingRange(value => { - let control = (value.commentingRangesInfo as MainThreadCommentingRanges).control; + let controller = (value.commentingRangesInfo as MainThreadCommentingRanges).controller; - if (!control) { + if (!controller) { return; } - this._proxy.$onActiveCommentingRangeChange(control.handle, value.range); + this._proxy.$onActiveCommentingRangeChange(controller.handle, value.range); })); } - $registerCommentControl(handle: number, id: string, label: string): void { - const provider = new MainThreadCommentControl(this._proxy, this._commentService, handle, id, label); - this._commentService.registerCommentControl(String(handle), provider); - this._commentControls.set(handle, provider); + $registerCommentController(handle: number, id: string, label: string): void { + const provider = new MainThreadCommentController(this._proxy, this._commentService, handle, id, label); + this._commentService.registerCommentController(String(handle), provider); + this._commentControllers.set(handle, provider); const commentsPanelAlreadyConstructed = this._panelService.getPanels().some(panel => panel.id === COMMENTS_PANEL_ID); if (!commentsPanelAlreadyConstructed) { @@ -412,7 +412,7 @@ export class MainThreadComments extends Disposable implements MainThreadComments } $createCommentThread(handle: number, commentThreadHandle: number, threadId: string, resource: UriComponents, range: IRange, comments: modes.Comment[], commands: modes.Command[], collapseState: modes.CommentThreadCollapsibleState): modes.CommentThread2 | undefined { - let provider = this._commentControls.get(handle); + let provider = this._commentControllers.get(handle); if (!provider) { return undefined; @@ -422,7 +422,7 @@ export class MainThreadComments extends Disposable implements MainThreadComments } $deleteCommentThread(handle: number, commentThreadHandle: number) { - let provider = this._commentControls.get(handle); + let provider = this._commentControllers.get(handle); if (!provider) { return; @@ -432,7 +432,7 @@ export class MainThreadComments extends Disposable implements MainThreadComments } $createCommentingRanges(handle: number, commentingRangesHandle: number, resource: UriComponents, ranges: IRange[], command: modes.Command) { - let provider = this._commentControls.get(handle); + let provider = this._commentControllers.get(handle); if (!provider) { return undefined; @@ -442,7 +442,7 @@ export class MainThreadComments extends Disposable implements MainThreadComments } $deleteCommentingRanges(handle: number, commentingRangesHandle: number) { - let provider = this._commentControls.get(handle); + let provider = this._commentControllers.get(handle); if (!provider) { return undefined; @@ -453,7 +453,7 @@ export class MainThreadComments extends Disposable implements MainThreadComments } $updateCommentingRanges(handle: number, commentingRangesHandle: number, newRanges: IRange[]): void { - let provider = this._commentControls.get(handle); + let provider = this._commentControllers.get(handle); if (!provider) { return; @@ -462,7 +462,7 @@ export class MainThreadComments extends Disposable implements MainThreadComments provider.updateCommentingRanges(commentingRangesHandle, newRanges); } $updateCommentingRangesCommands(handle: number, commentingRangesHandle: number, command: modes.Command): void { - let provider = this._commentControls.get(handle); + let provider = this._commentControllers.get(handle); if (!provider) { return; @@ -472,7 +472,7 @@ export class MainThreadComments extends Disposable implements MainThreadComments } $updateComments(handle: number, commentThreadHandle: number, comments: modes.Comment[]) { - let provider = this._commentControls.get(handle); + let provider = this._commentControllers.get(handle); if (!provider) { return; @@ -482,7 +482,7 @@ export class MainThreadComments extends Disposable implements MainThreadComments } $setInputValue(handle: number, commentThreadHandle: number, input: string) { - let provider = this._commentControls.get(handle); + let provider = this._commentControllers.get(handle); if (!provider) { return; @@ -493,7 +493,7 @@ export class MainThreadComments extends Disposable implements MainThreadComments } $updateCommentThreadCommands(handle: number, commentThreadHandle: number, acceptInputCommands: modes.Command[]) { - let provider = this._commentControls.get(handle); + let provider = this._commentControllers.get(handle); if (!provider) { return; @@ -503,7 +503,7 @@ export class MainThreadComments extends Disposable implements MainThreadComments } $updateCommentThreadRange(handle: number, commentThreadHandle: number, range: any): void { - let provider = this._commentControls.get(handle); + let provider = this._commentControllers.get(handle); if (!provider) { return; diff --git a/src/vs/workbench/api/node/extHost.api.impl.ts b/src/vs/workbench/api/node/extHost.api.impl.ts index 565c8835155..a5c230a0d63 100644 --- a/src/vs/workbench/api/node/extHost.api.impl.ts +++ b/src/vs/workbench/api/node/extHost.api.impl.ts @@ -670,8 +670,8 @@ export function createApiFactory( }; const comment: typeof vscode.comment = { - createCommentControl(id: string, label: string) { - return extHostComment.createCommentControl(extension, id, label); + createCommentController(id: string, label: string) { + return extHostComment.createCommentController(extension, id, label); } }; diff --git a/src/vs/workbench/api/node/extHost.protocol.ts b/src/vs/workbench/api/node/extHost.protocol.ts index 244c6178187..2661b62befe 100644 --- a/src/vs/workbench/api/node/extHost.protocol.ts +++ b/src/vs/workbench/api/node/extHost.protocol.ts @@ -119,7 +119,7 @@ export interface CommentProviderFeatures { } export interface MainThreadCommentsShape extends IDisposable { - $registerCommentControl(handle: number, id: string, label: string): void; + $registerCommentController(handle: number, id: string, label: string): void; $createCommentThread(handle: number, commentThreadHandle: number, threadId: string, resource: UriComponents, range: IRange, comments: modes.Comment[], commands: modes.Command[], collapseState: modes.CommentThreadCollapsibleState): modes.CommentThread2 | undefined; $deleteCommentThread(handle: number, commentThreadHandle: number): void; $updateComments(handle: number, commentThreadHandle: number, comments: modes.Comment[]): void; @@ -1105,8 +1105,8 @@ export interface ExtHostProgressShape { export interface ExtHostCommentsShape { $provideDocumentComments(handle: number, document: UriComponents): Promise; $createNewCommentThread(handle: number, document: UriComponents, range: IRange, text: string): Promise; - $onActiveCommentWidgetChange(commentControlhandle: number, commentThread: modes.CommentThread2, comment: modes.Comment | undefined, input: string): Promise; - $onActiveCommentingRangeChange(commentControlhandle: number, range: IRange): void; + $onActiveCommentWidgetChange(commentControllerHandle: number, commentThread: modes.CommentThread2, comment: modes.Comment | undefined, input: string): Promise; + $onActiveCommentingRangeChange(commentControllerHandle: number, range: IRange): void; $replyToCommentThread(handle: number, document: UriComponents, range: IRange, commentThread: modes.CommentThread, text: string): Promise; $editComment(handle: number, document: UriComponents, comment: modes.Comment, text: string): Promise; $deleteComment(handle: number, document: UriComponents, comment: modes.Comment): Promise; diff --git a/src/vs/workbench/api/node/extHostComments.ts b/src/vs/workbench/api/node/extHostComments.ts index acfba67e185..d6fc930f30e 100644 --- a/src/vs/workbench/api/node/extHostComments.ts +++ b/src/vs/workbench/api/node/extHostComments.ts @@ -30,9 +30,9 @@ export class ExtHostComments implements ExtHostCommentsShape { private _proxy: MainThreadCommentsShape; - private _commentControls: Map = new Map(); + private _commentControllers: Map = new Map(); - private _commentControlsByExtension: Map = new Map(); + private _commentControllersByExtension: Map = new Map(); private _documentProviders = new Map>(); private _workspaceProviders = new Map>(); @@ -47,21 +47,21 @@ export class ExtHostComments implements ExtHostCommentsShape { _commands.registerArgumentProcessor({ processArgument: arg => { if (arg && arg.$mid === 6) { - const commentControl = this._commentControls.get(arg.handle); + const commentController = this._commentControllers.get(arg.handle); - if (!commentControl) { + if (!commentController) { return arg; } - return commentControl; + return commentController; } else if (arg && arg.$mid === 7) { - const commentControl = this._commentControls.get(arg.commentControlHandle); + const commentController = this._commentControllers.get(arg.commentControlHandle); - if (!commentControl) { + if (!commentController) { return arg; } - const commentThread = commentControl.getCommentThread(arg.commentThreadHandle); + const commentThread = commentController.getCommentThread(arg.commentThreadHandle); if (!commentThread) { return arg; @@ -75,48 +75,48 @@ export class ExtHostComments implements ExtHostCommentsShape { }); } - createCommentControl(extension: IExtensionDescription, id: string, label: string): vscode.CommentControl { + createCommentController(extension: IExtensionDescription, id: string, label: string): vscode.CommentController { const handle = ExtHostComments.handlePool++; - const commentControl = new ExtHostCommentControl(extension, handle, this._commands.converter, this._proxy, id, label); - this._commentControls.set(commentControl.handle, commentControl); + const commentController = new ExtHostCommentController(extension, handle, this._commands.converter, this._proxy, id, label); + this._commentControllers.set(commentController.handle, commentController); - const commentControls = this._commentControlsByExtension.get(ExtensionIdentifier.toKey(extension.identifier)) || []; - commentControls.push(commentControl); - this._commentControlsByExtension.set(ExtensionIdentifier.toKey(extension.identifier), commentControls); + const commentControllers = this._commentControllersByExtension.get(ExtensionIdentifier.toKey(extension.identifier)) || []; + commentControllers.push(commentController); + this._commentControllersByExtension.set(ExtensionIdentifier.toKey(extension.identifier), commentControllers); - return commentControl; + return commentController; } - $onActiveCommentWidgetChange(commentControlhandle: number, commentThread: modes.CommentThread2, comment: modes.Comment | undefined, input: string): Promise { - const commentControl = this._commentControls.get(commentControlhandle); + $onActiveCommentWidgetChange(commentControllerHandle: number, commentThread: modes.CommentThread2, comment: modes.Comment | undefined, input: string): Promise { + const commentController = this._commentControllers.get(commentControllerHandle); - if (!commentControl) { + if (!commentController) { return Promise.resolve(undefined); } - commentControl.$onActiveCommentWidgetChange(commentThread, comment, input); - return Promise.resolve(commentControlhandle); + commentController.$onActiveCommentWidgetChange(commentThread, comment, input); + return Promise.resolve(commentControllerHandle); } - $onCommentWidgetInputChange(commentControlhandle: number, value: string): Promise { - const commentControl = this._commentControls.get(commentControlhandle); + $onCommentWidgetInputChange(commentControllerHandle: number, value: string): Promise { + const commentController = this._commentControllers.get(commentControllerHandle); - if (!commentControl || !commentControl.widget) { + if (!commentController || !commentController.widget) { return Promise.resolve(undefined); } - commentControl.widget.input = value; + commentController.widget.input = value; return Promise.resolve(undefined); } - $onActiveCommentingRangeChange(commentControlhandle: number, range: IRange) { - const commentControl = this._commentControls.get(commentControlhandle); + $onActiveCommentingRangeChange(commentControllerHandle: number, range: IRange) { + const commentController = this._commentControllers.get(commentControllerHandle); - if (!commentControl) { + if (!commentController) { return; } - commentControl.setActiveCommentingRange(extHostTypeConverter.Range.to(range)); + commentController.setActiveCommentingRange(extHostTypeConverter.Range.to(range)); } registerWorkspaceCommentProvider( @@ -412,7 +412,7 @@ export class ExtHostCommentingRanges implements vscode.CommentingRanges { set ranges(newRanges: vscode.Range[]) { this._ranges = newRanges; - this._proxy.$updateCommentingRanges(this._commentControlHandle, this.handle, this._ranges.map(extHostTypeConverter.Range.from)); + this._proxy.$updateCommentingRanges(this._commentControllerHandle, this.handle, this._ranges.map(extHostTypeConverter.Range.from)); } get newCommentThreadCommand(): vscode.Command { @@ -423,19 +423,19 @@ export class ExtHostCommentingRanges implements vscode.CommentingRanges { this._command = command; const internal = this._commandsConverter.toInternal(command); - this._proxy.$updateCommentingRangesCommands(this._commentControlHandle, this.handle, internal); + this._proxy.$updateCommentingRangesCommands(this._commentControllerHandle, this.handle, internal); } constructor( private _proxy: MainThreadCommentsShape, private readonly _commandsConverter: CommandsConverter, - private _commentControlHandle: number, + private _commentControllerHandle: number, private _resource: vscode.Uri, private _ranges: vscode.Range[], private _command: vscode.Command, ) { this._proxy.$createCommentingRanges( - this._commentControlHandle, + this._commentControllerHandle, this.handle, this._resource, this._ranges.map(extHostTypeConverter.Range.from), @@ -444,11 +444,11 @@ export class ExtHostCommentingRanges implements vscode.CommentingRanges { } dispose() { - this._proxy.$deleteCommentingRanges(this._commentControlHandle, this.handle); + this._proxy.$deleteCommentingRanges(this._commentControllerHandle, this.handle); } } -class ExtHostCommentControl implements vscode.CommentControl { +class ExtHostCommentController implements vscode.CommentController { get id(): string { return this._id; } @@ -475,7 +475,7 @@ class ExtHostCommentControl implements vscode.CommentControl { private _id: string, private _label: string ) { - this._proxy.$registerCommentControl(this.handle, _id, _label); + this._proxy.$registerCommentController(this.handle, _id, _label); } createCommentThread(id: string, resource: vscode.Uri, range: vscode.Range, comments: vscode.Comment[], acceptInputCommands: vscode.Command[], collapsibleState?: vscode.CommentThreadCollapsibleState): vscode.CommentThread { diff --git a/src/vs/workbench/contrib/comments/electron-browser/commentService.ts b/src/vs/workbench/contrib/comments/electron-browser/commentService.ts index e134ef9ddab..322138a8c1e 100644 --- a/src/vs/workbench/contrib/comments/electron-browser/commentService.ts +++ b/src/vs/workbench/contrib/comments/electron-browser/commentService.ts @@ -13,7 +13,7 @@ import { keys } from 'vs/base/common/map'; import { CancellationToken } from 'vs/base/common/cancellation'; import { assign } from 'vs/base/common/objects'; import { ICommentThreadChangedEvent } from 'vs/workbench/contrib/comments/common/commentModel'; -import { MainThreadCommentControl } from 'vs/workbench/api/electron-browser/mainThreadComments'; +import { MainThreadCommentController } from 'vs/workbench/api/electron-browser/mainThreadComments'; export const ICommentService = createDecorator('commentService'); @@ -44,7 +44,7 @@ export interface ICommentService { setDocumentComments(resource: URI, commentInfos: ICommentInfo[]): void; setWorkspaceComments(owner: string, commentsByResource: CommentThread[]): void; removeWorkspaceComments(owner: string): void; - registerCommentControl(owner: string, commentControl: MainThreadCommentControl): void; + registerCommentController(owner: string, commentControl: MainThreadCommentController): void; registerDataProvider(owner: string, commentProvider: DocumentCommentProvider): void; unregisterDataProvider(owner: string): void; updateComments(ownerId: string, event: CommentThreadChangedEvent): void; @@ -101,7 +101,7 @@ export class CommentService extends Disposable implements ICommentService { private _commentProviders = new Map(); - private _commentControls = new Map(); + private _commentControls = new Map(); constructor() { super(); @@ -132,7 +132,7 @@ export class CommentService extends Disposable implements ICommentService { this._onDidSetAllCommentThreads.fire({ ownerId: owner, commentThreads: [] }); } - registerCommentControl(owner: string, commentControl: MainThreadCommentControl): void { + registerCommentController(owner: string, commentControl: MainThreadCommentController): void { this._commentControls.set(owner, commentControl); this._onDidSetDataProvider.fire(); } -- GitLab