diff --git a/src/vs/vscode.proposed.d.ts b/src/vs/vscode.proposed.d.ts index 93c361aa2a24b6a047abba03f35fb072c0cb5777..a882a05d59fbff6ba5b43acbc9f23e3d73167818 100644 --- a/src/vs/vscode.proposed.d.ts +++ b/src/vs/vscode.proposed.d.ts @@ -992,7 +992,7 @@ declare module 'vscode' { * @return A thenable that resolves to a list of commenting ranges or null and undefined if the provider * does not want to participate or was cancelled. */ - registerCommentingRangeProvider(provider: (uri: Uri, token: CancellationToken) => ProviderResult, callback: (uri: Uri, range: Range) => void); + registerCommentingRangeProvider(provider: (document: TextDocument, token: CancellationToken) => ProviderResult, callback: (document: TextDocument, range: Range) => void); dispose(): void; } diff --git a/src/vs/workbench/api/electron-browser/mainThreadComments.ts b/src/vs/workbench/api/electron-browser/mainThreadComments.ts index e50af3509e04eac253df25193dc4c35567f3e8a8..7ef63a775e236c3f1321b95917b044f4027e67ed 100644 --- a/src/vs/workbench/api/electron-browser/mainThreadComments.ts +++ b/src/vs/workbench/api/electron-browser/mainThreadComments.ts @@ -239,6 +239,13 @@ export class MainThreadCommentController { updateComments(commentThreadHandle: number, comments: modes.Comment[]) { let thread = this._threads.get(commentThreadHandle); thread.comments = comments; + + this._commentService.updateComments(`${this.handle}`, { + added: [], + removed: [], + changed: [thread], + draftMode: modes.DraftMode.NotSupported + }); } updateAcceptInputCommands(commentThreadHandle: number, acceptInputCommands: modes.Command[]) { @@ -289,6 +296,15 @@ export class MainThreadCommentController { }; } + getAllComments(): MainThreadCommentThread[] { + let ret = []; + for (let thread of keys(this._threads)) { + ret.push(this._threads.get(thread)); + } + + return ret; + } + toJSON(): any { return { $mid: 6, @@ -348,9 +364,13 @@ export class MainThreadComments extends Disposable implements MainThreadComments this._commentService.registerCommentController(String(handle), provider); this._commentControllers.set(handle, provider); + const providerId = generateUuid(); + this._handlers.set(handle, providerId); + const commentsPanelAlreadyConstructed = this._panelService.getPanels().some(panel => panel.id === COMMENTS_PANEL_ID); if (!commentsPanelAlreadyConstructed) { this.registerPanel(commentsPanelAlreadyConstructed); + this.registerOpenPanelListener(commentsPanelAlreadyConstructed); } this._commentService.setWorkspaceComments(String(handle), []); } @@ -466,6 +486,15 @@ export class MainThreadComments extends Disposable implements MainThreadComments }); }); + keys(this._commentControllers).forEach(handle => { + let threads = this._commentControllers.get(handle).getAllComments(); + + if (threads.length) { + const providerId = this._handlers.get(handle); + this._commentService.setWorkspaceComments(providerId, threads); + } + }); + if (this._openPanelListener) { this._openPanelListener.dispose(); this._openPanelListener = null; diff --git a/src/vs/workbench/api/node/extHostComments.ts b/src/vs/workbench/api/node/extHostComments.ts index b6e04c85153d9faa6533acce87db08d060b23d4b..c4555575aa4bb05b201fe16aef5eefbcc6d54190 100644 --- a/src/vs/workbench/api/node/extHostComments.ts +++ b/src/vs/workbench/api/node/extHostComments.ts @@ -106,9 +106,10 @@ export class ExtHostComments implements ExtHostCommentsShape { return Promise.resolve(undefined); } + const document = this._documents.getDocument(URI.revive(uriComponents)); return asPromise(() => { - return commentController.commentingRangeProvider.provider(URI.revive(uriComponents), token); - }).then(ranges => ranges.map(extHostTypeConverter.Range.from)); + return commentController.commentingRangeProvider.provider(document, token); + }).then(ranges => ranges ? ranges.map(extHostTypeConverter.Range.from) : undefined); } $createNewCommentWidgetCallback(commentControllerHandle: number, uriComponents: UriComponents, range: IRange, token: CancellationToken): void { @@ -118,7 +119,8 @@ export class ExtHostComments implements ExtHostCommentsShape { return; } - commentController.commentingRangeProvider.callback(URI.revive(uriComponents), extHostTypeConverter.Range.to(range)); + const document = this._documents.getDocument(URI.revive(uriComponents)); + commentController.commentingRangeProvider.callback(document, extHostTypeConverter.Range.to(range)); } registerWorkspaceCommentProvider( @@ -412,8 +414,8 @@ export class ExtHostCommentInputBox implements vscode.CommentInputBox { class ExtHostCommentingRangeProvider { constructor( - public provider: (uri: vscode.Uri, token: vscode.CancellationToken) => vscode.ProviderResult, - public callback: (uri: vscode.Uri, range: vscode.Range) => void + public provider: (document: vscode.TextDocument, token: vscode.CancellationToken) => vscode.ProviderResult, + public callback: (document: vscode.TextDocument, range: vscode.Range) => void ) { } @@ -464,7 +466,7 @@ class ExtHostCommentController implements vscode.CommentController { return commentThread; } - registerCommentingRangeProvider(provider: (uri: vscode.Uri, token: vscode.CancellationToken) => vscode.ProviderResult, callback: (uri: vscode.Uri, range: vscode.Range) => void) { + registerCommentingRangeProvider(provider: (document: vscode.TextDocument, token: vscode.CancellationToken) => vscode.ProviderResult, callback: (document: vscode.TextDocument, range: vscode.Range) => void) { this._commentingRangeProvider = new ExtHostCommentingRangeProvider(provider, callback); } diff --git a/src/vs/workbench/contrib/comments/common/commentModel.ts b/src/vs/workbench/contrib/comments/common/commentModel.ts index 8eed03dfcff659d7a1a7bb2ff1dbac67d7b45ff7..7a12bf1219714744c03165743fc5cd616ca49232 100644 --- a/src/vs/workbench/contrib/comments/common/commentModel.ts +++ b/src/vs/workbench/contrib/comments/common/commentModel.ts @@ -41,7 +41,7 @@ export class ResourceWithCommentThreads { constructor(resource: URI, commentThreads: CommentThread[]) { this.id = resource.toString(); this.resource = resource; - this.commentThreads = commentThreads.map(thread => ResourceWithCommentThreads.createCommentNode(resource, thread)); + this.commentThreads = commentThreads.filter(thread => thread.comments.length).map(thread => ResourceWithCommentThreads.createCommentNode(resource, thread)); } public static createCommentNode(resource: URI, commentThread: CommentThread): CommentNode { @@ -99,14 +99,20 @@ export class CommentsModel { // Find comment node on resource that is that thread and replace it const index = firstIndex(matchingResourceData.commentThreads, (commentThread) => commentThread.threadId === thread.threadId); - matchingResourceData.commentThreads[index] = ResourceWithCommentThreads.createCommentNode(URI.parse(matchingResourceData.id), thread); + if (index >= 0) { + matchingResourceData.commentThreads[index] = ResourceWithCommentThreads.createCommentNode(URI.parse(matchingResourceData.id), thread); + } else { + matchingResourceData.commentThreads.push(ResourceWithCommentThreads.createCommentNode(URI.parse(matchingResourceData.id), thread)); + } }); added.forEach(thread => { const existingResource = threadsForOwner.filter(resourceWithThreads => resourceWithThreads.resource.toString() === thread.resource); if (existingResource.length) { const resource = existingResource[0]; - resource.commentThreads.push(ResourceWithCommentThreads.createCommentNode(resource.resource, thread)); + if (thread.comments.length) { + resource.commentThreads.push(ResourceWithCommentThreads.createCommentNode(resource.resource, thread)); + } } else { threadsForOwner.push(new ResourceWithCommentThreads(URI.parse(thread.resource), [thread])); }