From 4f249529e8c6da8bbe2c5bcfb6928bfc9cd2567a Mon Sep 17 00:00:00 2001 From: Peng Lyu Date: Fri, 22 Feb 2019 12:05:08 -0800 Subject: [PATCH] Commenting Ranges API --- src/vs/editor/common/modes.ts | 10 ++ src/vs/vscode.proposed.d.ts | 11 ++ .../electron-browser/mainThreadComments.ts | 110 +++++++++++++++++- src/vs/workbench/api/node/extHost.protocol.ts | 4 + src/vs/workbench/api/node/extHostComments.ts | 59 +++++++++- 5 files changed, 192 insertions(+), 2 deletions(-) diff --git a/src/vs/editor/common/modes.ts b/src/vs/editor/common/modes.ts index 5d76af1b1fb..1c56cb6b5d4 100644 --- a/src/vs/editor/common/modes.ts +++ b/src/vs/editor/common/modes.ts @@ -1255,6 +1255,16 @@ export interface CommentThread2 { onDidChangeAcceptInputCommands: Event; } +/** + * @internal + */ + +export interface CommentingRanges { + readonly resource: URI; + ranges: IRange[]; + acceptInputCommands: Command[]; +} + /** * @internal */ diff --git a/src/vs/vscode.proposed.d.ts b/src/vs/vscode.proposed.d.ts index 1b3eb561ded..f101c1248f3 100644 --- a/src/vs/vscode.proposed.d.ts +++ b/src/vs/vscode.proposed.d.ts @@ -763,6 +763,12 @@ declare module 'vscode' { Expanded = 1 } + interface CommentingRanges { + readonly resource: Uri; + ranges: Range[]; + acceptInputCommands: Command[]; + } + /** * A collection of comments representing a conversation at a particular range in a document. */ @@ -830,6 +836,8 @@ declare module 'vscode' { * * This will be treated as false if the comment is provided by a `WorkspaceCommentProvider`, or * if it is provided by a `DocumentCommentProvider` and no `editComment` method is given. + * + * DEPRECATED, use editCommand */ canEdit?: boolean; @@ -838,6 +846,8 @@ declare module 'vscode' { * * This will be treated as false if the comment is provided by a `WorkspaceCommentProvider`, or * if it is provided by a `DocumentCommentProvider` and no `deleteComment` method is given. + * + * DEPRECATED, use deleteCommand */ canDelete?: boolean; @@ -960,6 +970,7 @@ declare module 'vscode' { */ readonly widget?: CommentWidget; createCommentThread(id: string, resource: Uri, range: Range, comments: Comment[], acceptInputCommands: Command[], collapsibleState?: CommentThreadCollapsibleState): CommentThread; + createCommentingRanges(resource: Uri, ranges: Range[], acceptInputCommands: Command[]): CommentingRanges; dispose(): void; } diff --git a/src/vs/workbench/api/electron-browser/mainThreadComments.ts b/src/vs/workbench/api/electron-browser/mainThreadComments.ts index cf76955af68..80b1024d003 100644 --- a/src/vs/workbench/api/electron-browser/mainThreadComments.ts +++ b/src/vs/workbench/api/electron-browser/mainThreadComments.ts @@ -160,12 +160,48 @@ export class MainThreadCommentThread implements modes.CommentThread2 { } } +export class MainThreadCommentingRanges implements modes.CommentingRanges { + get ranges(): IRange[] { + return this._ranges; + } + + set ranges(newRanges: IRange[]) { + this._ranges = newRanges; + } + + set acceptInputCommands(newCommands: modes.Command[]) { + this._acceptInputCommands = newCommands; + this._onDidChangeAcceptInputCommands.fire(this._acceptInputCommands); + } + + get acceptInputCommands(): modes.Command[] { + return this._acceptInputCommands; + } + + private _onDidChangeAcceptInputCommands = new Emitter(); + get onDidChangeAcceptInputCommands(): Event { return this._onDidChangeAcceptInputCommands.event; } + + constructor( + public commentingRangesHandle: number, + public control: MainThreadCommentControl, + public resource: URI, + private _ranges: IRange[], + private _acceptInputCommands: modes.Command[], + ) { + } + + dispose() { + + } +} + export class MainThreadCommentControl { get handle(): number { return this._handle; } private _threads: Map = new Map(); + private _commentingRanges: Map = new Map(); constructor( private _proxy: ExtHostCommentsShape, private _handle: number, @@ -202,6 +238,38 @@ export class MainThreadCommentControl { thread.comments = comments; } + createCommentingRanges(commentingRangesHandle: number, resource: UriComponents, ranges: IRange[], commands: modes.Command[]) { + let commentingRange = new MainThreadCommentingRanges( + commentingRangesHandle, + this, + URI.revive(resource), + ranges, + commands + ); + + this._commentingRanges.set(commentingRangesHandle, commentingRange); + return commentingRange; + } + + deleteCommentingRanges(commentingRangesHandle: number) { + let commentingRanges = this._commentingRanges.get(commentingRangesHandle); + + this._commentingRanges.delete(commentingRangesHandle); + commentingRanges.dispose(); + } + + updateCommentingRanges(commentingRangesHandle: number, newRanges: IRange[]) { + let commentingRanges = this._commentingRanges.get(commentingRangesHandle); + + commentingRanges.ranges = newRanges; + } + + updateCommentingRangesCommands(commentingRangesHandle: number, acceptInputCommands: modes.Command[]) { + let commentingRanges = this._commentingRanges.get(commentingRangesHandle); + + commentingRanges.acceptInputCommands = acceptInputCommands; + } + updateAcceptInputCommands(commentThreadHandle: number, acceptInputCommands: modes.Command[]) { let thread = this._threads.get(commentThreadHandle); thread.acceptInputCommands = acceptInputCommands; @@ -294,7 +362,7 @@ export class MainThreadComments extends Disposable implements MainThreadComments let provider = this._commentControls.get(handle); if (!provider) { - return; + return undefined; } return provider.createCommentThread(commentThreadHandle, threadId, resource, range, comments, commands, collapseState); @@ -310,6 +378,46 @@ export class MainThreadComments extends Disposable implements MainThreadComments return provider.deleteCommentThread(commentThreadHandle); } + $createCommentingRanges(handle: number, commentingRangesHandle: number, resource: UriComponents, ranges: IRange[], commands: modes.Command[]) { + let provider = this._commentControls.get(handle); + + if (!provider) { + return undefined; + } + + return provider.createCommentingRanges(commentingRangesHandle, resource, ranges, commands); + } + + $deleteCommentingRanges(handle: number, commentingRangesHandle: number) { + let provider = this._commentControls.get(handle); + + if (!provider) { + return undefined; + } + + return provider.deleteCommentingRanges(commentingRangesHandle); + + } + + $updateCommentingRanges(handle: number, commentingRangesHandle: number, newRanges: IRange[]): void { + let provider = this._commentControls.get(handle); + + if (!provider) { + return; + } + + provider.updateCommentingRanges(commentingRangesHandle, newRanges); + } + $updateCommentingRangesCommands(handle: number, commentingRangesHandle: number, acceptInputCommands: modes.Command[]): void { + let provider = this._commentControls.get(handle); + + if (!provider) { + return; + } + + provider.updateCommentingRangesCommands(commentingRangesHandle, acceptInputCommands); + } + $updateComments(handle: number, commentThreadHandle: number, comments: modes.Comment[]) { let provider = this._commentControls.get(handle); diff --git a/src/vs/workbench/api/node/extHost.protocol.ts b/src/vs/workbench/api/node/extHost.protocol.ts index 343cc7877b2..d7911fb9073 100644 --- a/src/vs/workbench/api/node/extHost.protocol.ts +++ b/src/vs/workbench/api/node/extHost.protocol.ts @@ -123,6 +123,10 @@ export interface MainThreadCommentsShape extends IDisposable { $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; + $createCommentingRanges(handle: number, commentingRangesHandle: number, resource: UriComponents, ranges: IRange[], commands: modes.Command[]): void; + $deleteCommentingRanges(handle: number, commentingRangesHandle: number): void; + $updateCommentingRanges(handle: number, commentingRangesHandle: number, newRanges: IRange[]): void; + $updateCommentingRangesCommands(handle: number, commentingRangesHandle: number, acceptInputCommands: modes.Command[]): void; $setInputValue(handle: number, commentThreadHandle: number, input: string): void; $updateCommentThreadCommands(handle: number, commentThreadHandle: number, acceptInputCommands: modes.Command[]): void; $registerDocumentCommentProvider(handle: number, features: CommentProviderFeatures): void; diff --git a/src/vs/workbench/api/node/extHostComments.ts b/src/vs/workbench/api/node/extHostComments.ts index ba2dba387a1..3a06ecd11ea 100644 --- a/src/vs/workbench/api/node/extHostComments.ts +++ b/src/vs/workbench/api/node/extHostComments.ts @@ -378,11 +378,61 @@ export class ExtHostCommentWidget implements vscode.CommentWidget { public commentThread: ExtHostCommentThread, public comment: vscode.Comment | undefined, input: string - ) { + ) { this._input = input; } } +export class ExtHostCommentingRanges implements vscode.CommentingRanges { + private static _handlePool: number = 0; + readonly handle = ExtHostCommentingRanges._handlePool++; + + get resource(): vscode.Uri { + return this._resource; + } + + get ranges(): vscode.Range[] { + return this._ranges; + } + + set ranges(newRanges: vscode.Range[]) { + this._ranges = newRanges; + this._proxy.$updateCommentingRanges(this._commentControlHandle, this.handle, this._ranges.map(extHostTypeConverter.Range.from)); + } + + get acceptInputCommands(): vscode.Command[] { + return this._acceptInputCommands; + } + + set acceptInputCommands(replyCommands: vscode.Command[]) { + this._acceptInputCommands = replyCommands; + + const internals = replyCommands.map(this._commandsConverter.toInternal.bind(this._commandsConverter)); + this._proxy.$updateCommentingRangesCommands(this._commentControlHandle, this.handle, internals); + } + + constructor( + private _proxy: MainThreadCommentsShape, + private readonly _commandsConverter: CommandsConverter, + private _commentControlHandle: number, + private _resource: vscode.Uri, + private _ranges: vscode.Range[], + private _acceptInputCommands: vscode.Command[], + ) { + this._proxy.$createCommentingRanges( + this._commentControlHandle, + this.handle, + this._resource, + this._ranges.map(extHostTypeConverter.Range.from), + this._acceptInputCommands.map(this._commandsConverter.toInternal.bind(this._commandsConverter)) + ); + } + + dispose() { + this._proxy.$deleteCommentingRanges(this._commentControlHandle, this.handle); + } +} + class ExtHostCommentControl implements vscode.CommentControl { get id(): string { return this._id; @@ -399,6 +449,7 @@ class ExtHostCommentControl implements vscode.CommentControl { } private _threads: Map = new Map(); + private _commentingRanges: Map = new Map(); constructor( _extension: IExtensionDescription, @@ -431,6 +482,12 @@ class ExtHostCommentControl implements vscode.CommentControl { this.widget = extHostCommentWidget; } + createCommentingRanges(resource: vscode.Uri, ranges: vscode.Range[], acceptInputCommands: vscode.Command[]): vscode.CommentingRanges { + const commentingRange = new ExtHostCommentingRanges(this._proxy, this._commandsConverter, this.handle, resource, ranges, acceptInputCommands); + this._commentingRanges.set(commentingRange.handle, commentingRange); + return commentingRange; + } + getCommentThread(handle: number) { return this._threads.get(handle); }