diff --git a/src/vs/editor/common/modes.ts b/src/vs/editor/common/modes.ts index 890b6b14584065eb98028a2f6182f48d5b692e26..53131ce3c41654c3f399d26301e816c8e7a615f0 100644 --- a/src/vs/editor/common/modes.ts +++ b/src/vs/editor/common/modes.ts @@ -1203,7 +1203,7 @@ export interface Command { * @internal */ export interface CommentInfo { - extensionId: string; + extensionId?: string; threads: CommentThread[]; commentingRanges?: (IRange[] | CommentingRanges); reply?: Command; @@ -1266,8 +1266,8 @@ export interface CommentThread2 { comments: Comment[]; onDidChangeComments: Event; collapsibleState?: CommentThreadCollapsibleState; - input: CommentInput; - onDidChangeInput: Event; + input: CommentInput | undefined; + onDidChangeInput: Event; acceptInputCommand?: Command; additionalCommands: Command[]; onDidChangeAcceptInputCommand: Event; @@ -1368,8 +1368,8 @@ export interface CommentThreadChangedEvent { */ export interface DocumentCommentProvider { provideDocumentComments(resource: URI, token: CancellationToken): Promise; - createNewCommentThread(resource: URI, range: Range, text: string, token: CancellationToken): Promise; - replyToCommentThread(resource: URI, range: Range, thread: CommentThread, text: string, token: CancellationToken): Promise; + createNewCommentThread(resource: URI, range: Range, text: string, token: CancellationToken): Promise; + replyToCommentThread(resource: URI, range: Range, thread: CommentThread, text: string, token: CancellationToken): Promise; editComment(resource: URI, comment: Comment, text: string, token: CancellationToken): Promise; deleteComment(resource: URI, comment: Comment, token: CancellationToken): Promise; startDraft?(resource: URI, token: CancellationToken): Promise; diff --git a/src/vs/workbench/api/electron-browser/mainThreadComments.ts b/src/vs/workbench/api/electron-browser/mainThreadComments.ts index 62ac83c48a2f5f3af40a90d7ce0359b3a79e0204..844cb64183d20b17f38eb144dad5019a9c3e2381 100644 --- a/src/vs/workbench/api/electron-browser/mainThreadComments.ts +++ b/src/vs/workbench/api/electron-browser/mainThreadComments.ts @@ -127,7 +127,7 @@ export class MainThreadCommentThread implements modes.CommentThread2 { } get acceptInputCommand(): modes.Command { - return this._acceptInputCommand; + return this._acceptInputCommand!; } private _onDidChangeAcceptInputCommand = new Emitter(); @@ -249,7 +249,7 @@ export class MainThreadCommentController { } deleteCommentThread(commentThreadHandle: number) { - let thread = this._threads.get(commentThreadHandle); + let thread = this.getKnownThread(commentThreadHandle); this._threads.delete(commentThreadHandle); this._commentService.updateComments(this._uniqueId, { @@ -263,7 +263,7 @@ export class MainThreadCommentController { } updateComments(commentThreadHandle: number, comments: modes.Comment[]) { - let thread = this._threads.get(commentThreadHandle); + let thread = this.getKnownThread(commentThreadHandle); thread.comments = comments; this._commentService.updateComments(this._uniqueId, { @@ -275,27 +275,27 @@ export class MainThreadCommentController { } updateAcceptInputCommand(commentThreadHandle: number, acceptInputCommand: modes.Command) { - let thread = this._threads.get(commentThreadHandle); + let thread = this.getKnownThread(commentThreadHandle); thread.acceptInputCommand = acceptInputCommand; } updateAdditionalCommands(commentThreadHandle: number, additionalCommands: modes.Command[]) { - let thread = this._threads.get(commentThreadHandle); + let thread = this.getKnownThread(commentThreadHandle); thread.additionalCommands = additionalCommands; } updateCollapsibleState(commentThreadHandle: number, collapseState: modes.CommentThreadCollapsibleState) { - let thread = this._threads.get(commentThreadHandle); + let thread = this.getKnownThread(commentThreadHandle); thread.collapsibleState = collapseState; } updateCommentThreadRange(commentThreadHandle: number, range: IRange) { - let thread = this._threads.get(commentThreadHandle); + let thread = this.getKnownThread(commentThreadHandle); thread.range = range; } updateCommentThreadLabel(commentThreadHandle: number, label: string) { - let thread = this._threads.get(commentThreadHandle); + let thread = this.getKnownThread(commentThreadHandle); thread.label = label; } @@ -309,11 +309,21 @@ export class MainThreadCommentController { } } + private getKnownThread(commentThreadHandle: number) { + const thread = this._threads.get(commentThreadHandle); + if (!thread) { + throw new Error('unknown thread'); + } + return thread; + } + + async getDocumentComments(resource: URI, token) { - let ret = []; + let ret: modes.CommentThread2[] = []; for (let thread of keys(this._threads)) { - if (this._threads.get(thread).resource === resource.toString()) { - ret.push(this._threads.get(thread)); + const commentThread = this._threads.get(thread)!; + if (commentThread.resource === resource.toString()) { + ret.push(commentThread); } } @@ -338,9 +348,9 @@ export class MainThreadCommentController { } getAllComments(): MainThreadCommentThread[] { - let ret = []; + let ret: MainThreadCommentThread[] = []; for (let thread of keys(this._threads)) { - ret.push(this._threads.get(thread)); + ret.push(this._threads.get(thread)!); } return ret; @@ -540,17 +550,17 @@ export class MainThreadComments extends Disposable implements MainThreadComments keys(this._workspaceProviders).forEach(handle => { this._proxy.$provideWorkspaceComments(handle).then(commentThreads => { if (commentThreads) { - const providerId = this._handlers.get(handle); + const providerId = this.getHandler(handle); this._commentService.setWorkspaceComments(providerId, commentThreads); } }); }); keys(this._commentControllers).forEach(handle => { - let threads = this._commentControllers.get(handle).getAllComments(); + let threads = this._commentControllers.get(handle)!.getAllComments(); if (threads.length) { - const providerId = this._handlers.get(handle); + const providerId = this.getHandler(handle); this._commentService.setWorkspaceComments(providerId, threads); } }); @@ -564,6 +574,13 @@ export class MainThreadComments extends Disposable implements MainThreadComments } } + private getHandler(handle: number) { + if (!this._handlers.has(handle)) { + throw new Error('Unknown handler'); + } + return this._handlers.get(handle)!; + } + $registerWorkspaceCommentProvider(handle: number, extensionId: ExtensionIdentifier): void { this._workspaceProviders.set(handle, undefined); @@ -611,7 +628,7 @@ export class MainThreadComments extends Disposable implements MainThreadComments $unregisterDocumentCommentProvider(handle: number): void { this._documentProviders.delete(handle); - const handlerId = this._handlers.get(handle); + const handlerId = this.getHandler(handle); this._commentService.unregisterDataProvider(handlerId); this._handlers.delete(handle); } @@ -627,14 +644,14 @@ export class MainThreadComments extends Disposable implements MainThreadComments } } - const handlerId = this._handlers.get(handle); + const handlerId = this.getHandler(handle); this._commentService.removeWorkspaceComments(handlerId); this._handlers.delete(handle); } $onDidCommentThreadsChange(handle: number, event: modes.CommentThreadChangedEvent) { // notify comment service - const providerId = this._handlers.get(handle); + const providerId = this.getHandler(handle); this._commentService.updateComments(providerId, event); } @@ -658,7 +675,10 @@ export class MainThreadComments extends Disposable implements MainThreadComments async provideWorkspaceComments(): Promise { const result: modes.CommentThread[] = []; for (const handle of keys(this._workspaceProviders)) { - result.push(...await this._proxy.$provideWorkspaceComments(handle)); + const result = await this._proxy.$provideWorkspaceComments(handle); + if (Array.isArray(result)) { + result.push(...result); + } } return result; } diff --git a/src/vs/workbench/api/node/extHost.protocol.ts b/src/vs/workbench/api/node/extHost.protocol.ts index 15a16ca11cc2ed70ccd0d2cfa3ad43484bc383f9..4af7ec3763a3dbe23097e2ccf2795cde5c439b6e 100644 --- a/src/vs/workbench/api/node/extHost.protocol.ts +++ b/src/vs/workbench/api/node/extHost.protocol.ts @@ -1106,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; - $onCommentWidgetInputChange(commentControllerHandle: number, input: string): Promise; + $onCommentWidgetInputChange(commentControllerHandle: number, input: string | undefined): Promise; $provideCommentingRanges(commentControllerHandle: number, uriComponents: UriComponents, token: CancellationToken): Promise; $createNewCommentWidgetCallback(commentControllerHandle: number, uriComponents: UriComponents, range: IRange, token: CancellationToken): void; $replyToCommentThread(handle: number, document: UriComponents, range: IRange, commentThread: modes.CommentThread, text: string): Promise;