diff --git a/src/vs/editor/common/modes.ts b/src/vs/editor/common/modes.ts index 5f16fd84920..c1f7b22eb18 100644 --- a/src/vs/editor/common/modes.ts +++ b/src/vs/editor/common/modes.ts @@ -1261,6 +1261,7 @@ export interface CommentThread2 { acceptInputCommands: Command[]; onDidChangeAcceptInputCommands: Event; onDidChangeRange: Event; + onDidChangeCollasibleState: Event; } /** diff --git a/src/vs/vscode.proposed.d.ts b/src/vs/vscode.proposed.d.ts index 9a662635b70..3460facb745 100644 --- a/src/vs/vscode.proposed.d.ts +++ b/src/vs/vscode.proposed.d.ts @@ -910,6 +910,9 @@ declare module 'vscode' { readonly hasReacted?: boolean; } + /** + * DEPRECATED + */ interface DocumentCommentProvider { /** * Provide the commenting ranges and comment threads for the given document. The comments are displayed within the editor. @@ -954,6 +957,9 @@ declare module 'vscode' { onDidChangeCommentThreads: Event; } + /** + * DEPRECATED + */ interface WorkspaceCommentProvider { /** * Provide all comments for the workspace. Comments are shown within the comments panel. Selecting a comment @@ -967,31 +973,27 @@ declare module 'vscode' { onDidChangeCommentThreads: Event; } - export interface CommentWidget { - /* - * Comment thread in this Comment Widget - */ - commentThread: CommentThread; + export interface CommentInputBox { - /* - * Textarea content in the comment widget. - * There is only one active input box in a comment widget. + /** + * Setter and getter for the contents of the input box. */ - input: string; + value: string; } export interface CommentController { readonly id: string; readonly label: string; /** - * The active (focused) comment widget. + * The active (focused) comment input box. */ - readonly widget?: CommentWidget; + readonly inputBox?: CommentInputBox; + /** * The active range users attempt to create comments against. */ readonly activeCommentingRange?: Range; - createCommentThread(id: string, resource: Uri, range: Range, comments: Comment[], acceptInputCommands: Command[], collapsibleState?: CommentThreadCollapsibleState): CommentThread; + createCommentThread(id: string, resource: Uri, range: Range): CommentThread; createCommentingRanges(resource: Uri, ranges: Range[], newCommentThreadCommand: 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 2d5e9f9c61d..a72953a66c2 100644 --- a/src/vs/workbench/api/electron-browser/mainThreadComments.ts +++ b/src/vs/workbench/api/electron-browser/mainThreadComments.ts @@ -130,6 +130,19 @@ export class MainThreadCommentThread implements modes.CommentThread2 { private _onDidChangeRange = new Emitter(); public onDidChangeRange = this._onDidChangeRange.event; + get collapsibleState() { + return this._collapsibleState; + } + + set collapsibleState(newState: modes.CommentThreadCollapsibleState) { + this._collapsibleState = newState; + + } + + private _onDidChangeCollasibleState = new Emitter(); + public onDidChangeCollasibleState = this._onDidChangeCollasibleState.event; + + constructor( public commentThreadHandle: number, public controller: MainThreadCommentController, @@ -139,7 +152,7 @@ export class MainThreadCommentThread implements modes.CommentThread2 { private _range: IRange, private _comments: modes.Comment[], private _acceptInputCommands: modes.Command[], - public collapsibleState?: modes.CommentThreadCollapsibleState, + private _collapsibleState: modes.CommentThreadCollapsibleState ) { } @@ -210,6 +223,7 @@ export class MainThreadCommentController { } private _threads: Map = new Map(); + private _activeCommentThread?: MainThreadCommentThread; private _commentingRanges: Map = new Map(); constructor( private _proxy: ExtHostCommentsShape, @@ -299,15 +313,21 @@ export class MainThreadCommentController { thread.acceptInputCommands = acceptInputCommands; } + updateCollapsibleState(commentThreadHandle: number, collapseState: modes.CommentThreadCollapsibleState) { + let thread = this._threads.get(commentThreadHandle); + thread.collapsibleState = collapseState; + } + updateCommentThreadRange(commentThreadHandle: number, range: IRange) { let thread = this._threads.get(commentThreadHandle); thread.range = range; } - updateInput(commentThreadHandle: number, input: string) { - let thread = this._threads.get(commentThreadHandle); - let commentInput = thread.input; - if (commentInput) { + updateInput(input: string) { + let thread = this._activeCommentThread; + + if (thread && thread.input) { + let commentInput = thread.input; commentInput.value = input; thread.input = commentInput; } @@ -355,7 +375,6 @@ export class MainThreadComments extends Disposable implements MainThreadComments private _commentControllers = new Map(); private _activeCommentThread?: MainThreadCommentThread; - private _activeComment?: modes.Comment; private _input?: modes.CommentInput; private _openPanelListener: IDisposable | null; @@ -383,10 +402,10 @@ export class MainThreadComments extends Disposable implements MainThreadComments this._activeCommentThreadDisposables.push(this._activeCommentThread.onDidChangeInput(input => { // todo, dispose this._input = input; - this._proxy.$onActiveCommentWidgetChange(controller.handle, this._activeCommentThread, this._activeComment, this._input ? this._input.value : undefined); + this._proxy.$onCommentWidgetInputChange(controller.handle, this._input ? this._input.value : undefined); })); - await this._proxy.$onActiveCommentWidgetChange(controller.handle, this._activeCommentThread, this._activeComment, this._input ? this._input.value : undefined); + await this._proxy.$onCommentWidgetInputChange(controller.handle, this._input ? this._input.value : undefined); })); this._disposables.push(this._commentService.onDidChangeActiveCommentingRange(value => { @@ -481,15 +500,14 @@ export class MainThreadComments extends Disposable implements MainThreadComments provider.updateComments(commentThreadHandle, comments); } - $setInputValue(handle: number, commentThreadHandle: number, input: string) { + $setInputValue(handle: number, input: string) { let provider = this._commentControllers.get(handle); if (!provider) { return; } - provider.updateInput(commentThreadHandle, input); - + provider.updateInput(input); } $updateCommentThreadCommands(handle: number, commentThreadHandle: number, acceptInputCommands: modes.Command[]) { @@ -502,6 +520,16 @@ export class MainThreadComments extends Disposable implements MainThreadComments provider.updateAcceptInputCommands(commentThreadHandle, acceptInputCommands); } + $updateCommentThreadCollapsibleState(handle: number, commentThreadHandle: number, collapseState: modes.CommentThreadCollapsibleState): void { + let provider = this._commentControllers.get(handle); + + if (!provider) { + return; + } + + provider.updateCollapsibleState(commentThreadHandle, collapseState); + } + $updateCommentThreadRange(handle: number, commentThreadHandle: number, range: any): void { let provider = this._commentControllers.get(handle); diff --git a/src/vs/workbench/api/node/extHost.protocol.ts b/src/vs/workbench/api/node/extHost.protocol.ts index 2661b62befe..f778a351dcb 100644 --- a/src/vs/workbench/api/node/extHost.protocol.ts +++ b/src/vs/workbench/api/node/extHost.protocol.ts @@ -127,8 +127,9 @@ export interface MainThreadCommentsShape extends IDisposable { $deleteCommentingRanges(handle: number, commentingRangesHandle: number): void; $updateCommentingRanges(handle: number, commentingRangesHandle: number, newRanges: IRange[]): void; $updateCommentingRangesCommands(handle: number, commentingRangesHandle: number, command: modes.Command): void; - $setInputValue(handle: number, commentThreadHandle: number, input: string): void; + $setInputValue(handle: number, input: string): void; $updateCommentThreadCommands(handle: number, commentThreadHandle: number, acceptInputCommands: modes.Command[]): void; + $updateCommentThreadCollapsibleState(handle: number, commentThreadHandle: number, collapseState: modes.CommentThreadCollapsibleState): void; $updateCommentThreadRange(handle: number, commentThreadHandle: number, range: IRange): void; $registerDocumentCommentProvider(handle: number, features: CommentProviderFeatures): void; $unregisterDocumentCommentProvider(handle: number): void; @@ -1105,7 +1106,7 @@ export interface ExtHostProgressShape { export interface ExtHostCommentsShape { $provideDocumentComments(handle: number, document: UriComponents): Promise; $createNewCommentThread(handle: number, document: UriComponents, range: IRange, text: string): Promise; - $onActiveCommentWidgetChange(commentControllerHandle: number, commentThread: modes.CommentThread2, comment: modes.Comment | undefined, input: string): Promise; + $onCommentWidgetInputChange(commentControllerHandle: number, 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; diff --git a/src/vs/workbench/api/node/extHostComments.ts b/src/vs/workbench/api/node/extHostComments.ts index d6fc930f30e..20a2bc40d6e 100644 --- a/src/vs/workbench/api/node/extHostComments.ts +++ b/src/vs/workbench/api/node/extHostComments.ts @@ -87,28 +87,17 @@ export class ExtHostComments implements ExtHostCommentsShape { return commentController; } - $onActiveCommentWidgetChange(commentControllerHandle: number, commentThread: modes.CommentThread2, comment: modes.Comment | undefined, input: string): Promise { + $onCommentWidgetInputChange(commentControllerHandle: number, input: string): Promise { const commentController = this._commentControllers.get(commentControllerHandle); if (!commentController) { return Promise.resolve(undefined); } - commentController.$onActiveCommentWidgetChange(commentThread, comment, input); + commentController.$onCommentWidgetInputChange(input); return Promise.resolve(commentControllerHandle); } - $onCommentWidgetInputChange(commentControllerHandle: number, value: string): Promise { - const commentController = this._commentControllers.get(commentControllerHandle); - - if (!commentController || !commentController.widget) { - return Promise.resolve(undefined); - } - - commentController.widget.input = value; - return Promise.resolve(undefined); - } - $onActiveCommentingRangeChange(commentControllerHandle: number, range: IRange) { const commentController = this._commentControllers.get(commentControllerHandle); @@ -304,6 +293,8 @@ export class ExtHostCommentThread implements vscode.CommentThread { return this._range; } + private _comments: vscode.Comment[] = []; + get comments(): vscode.Comment[] { return this._comments; } @@ -313,6 +304,7 @@ export class ExtHostCommentThread implements vscode.CommentThread { this._comments = newComments; } + private _acceptInputCommands: vscode.Command[] = []; get acceptInputCommands(): vscode.Command[] { return this._acceptInputCommands; } @@ -324,17 +316,25 @@ export class ExtHostCommentThread implements vscode.CommentThread { this._proxy.$updateCommentThreadCommands(this._commentControlHandle, this.handle, internals); } - collapsibleState?: vscode.CommentThreadCollapsibleState; + private _collapseState?: vscode.CommentThreadCollapsibleState = vscode.CommentThreadCollapsibleState.Collapsed; + + get collapsibleState(): vscode.CommentThreadCollapsibleState { + return this._collapseState; + } + + set collapsibleState(newState: vscode.CommentThreadCollapsibleState) { + this._collapseState = newState; + this._proxy.$updateCommentThreadCollapsibleState(this._commentControlHandle, this.handle, newState); + + } + constructor( private _proxy: MainThreadCommentsShape, private readonly _commandsConverter: CommandsConverter, private _commentControlHandle: number, private _threadId: string, private _resource: vscode.Uri, - private _range: vscode.Range, - private _comments: vscode.Comment[], - private _acceptInputCommands: vscode.Command[], - private _collapseState?: vscode.CommentThreadCollapsibleState + private _range: vscode.Range ) { this._proxy.$createCommentThread( this._commentControlHandle, @@ -366,35 +366,35 @@ export class ExtHostCommentThread implements vscode.CommentThread { } } -export class ExtHostCommentWidget implements vscode.CommentWidget { - private _onDidChangeInput = new Emitter(); +export class ExtHostCommentInputBox implements vscode.CommentInputBox { + private _onDidChangeValue = new Emitter(); - get onDidChangeInput(): Event { - return this._onDidChangeInput.event; + get onDidChangeValue(): Event { + return this._onDidChangeValue.event; + } + private _value: string = ''; + get value(): string { + return this._value; } - private _input: string = ''; - get input(): string { - return this._input; - } - - set input(newInput: string) { - this._input = newInput; - this._onDidChangeInput.fire(this._input); - this._proxy.$setInputValue(this.commentControlHandle, this.commentThread.handle, newInput); + set value(newInput: string) { + this._value = newInput; + this._onDidChangeValue.fire(this._value); + this._proxy.$setInputValue(this.commentControllerHandle, newInput); } constructor( private _proxy: MainThreadCommentsShape, - public commentControlHandle: number, - - public commentThread: ExtHostCommentThread, - public comment: vscode.Comment | undefined, + public commentControllerHandle: number, input: string ) { - this._input = input; + this._value = input; + } + + setInput(input: string) { + this._value = input; } } @@ -457,7 +457,7 @@ class ExtHostCommentController implements vscode.CommentController { return this._label; } - public widget?: ExtHostCommentWidget; + public inputBox?: ExtHostCommentInputBox; public activeCommentingRange?: vscode.Range; public get handle(): number { @@ -478,24 +478,18 @@ class ExtHostCommentController implements vscode.CommentController { 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 { - const commentThread = new ExtHostCommentThread(this._proxy, this._commandsConverter, this.handle, id, resource, range, comments, acceptInputCommands, collapsibleState); + createCommentThread(id: string, resource: vscode.Uri, range: vscode.Range): vscode.CommentThread { + const commentThread = new ExtHostCommentThread(this._proxy, this._commandsConverter, this.handle, id, resource, range); this._threads.set(commentThread.handle, commentThread); return commentThread; } - $onActiveCommentWidgetChange(commentThread: modes.CommentThread2, comment: modes.Comment | undefined, input: string) { - let extHostCommentThread = this._threads.get(commentThread.commentThreadHandle); - - const extHostCommentWidget = new ExtHostCommentWidget( - this._proxy, - this.handle, - extHostCommentThread, - comment ? extHostCommentThread.getComment(comment.commentId) : undefined, - input || '' - ); - - this.widget = extHostCommentWidget; + $onCommentWidgetInputChange(input: string) { + if (!this.inputBox) { + this.inputBox = new ExtHostCommentInputBox(this._proxy, this.handle, input); + } else { + this.inputBox.setInput(input); + } } createCommentingRanges(resource: vscode.Uri, ranges: vscode.Range[], newCommentThreadCommand: vscode.Command): vscode.CommentingRanges { diff --git a/src/vs/workbench/contrib/comments/electron-browser/commentThreadWidget.ts b/src/vs/workbench/contrib/comments/electron-browser/commentThreadWidget.ts index ccd46fe4c0f..4cc65996c6f 100644 --- a/src/vs/workbench/contrib/comments/electron-browser/commentThreadWidget.ts +++ b/src/vs/workbench/contrib/comments/electron-browser/commentThreadWidget.ts @@ -450,6 +450,20 @@ export class ReviewZoneWidget extends ZoneWidget { this.show({ lineNumber, column: 1 }, 2); } })); + + this._disposables.push((this._commentThread as modes.CommentThread2).onDidChangeCollasibleState(state => { + if (state === modes.CommentThreadCollapsibleState.Expanded && this._isCollapsed) { + const lineNumber = this._commentThread.range.startLineNumber; + + this.show({ lineNumber, column: 1 }, 2); + return; + } + + if (state === modes.CommentThreadCollapsibleState.Collapsed && !this._isCollapsed) { + this.hide(); + return; + } + })); } else { this.createCommentWidgetActions(this._formActions, model); }