提交 905248fa 编写于 作者: P Peng Lyu

comments panel handle new comment thread registration.

上级 42194d82
...@@ -992,7 +992,7 @@ declare module 'vscode' { ...@@ -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 * @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. * does not want to participate or was cancelled.
*/ */
registerCommentingRangeProvider(provider: (uri: Uri, token: CancellationToken) => ProviderResult<Range[]>, callback: (uri: Uri, range: Range) => void); registerCommentingRangeProvider(provider: (document: TextDocument, token: CancellationToken) => ProviderResult<Range[]>, callback: (document: TextDocument, range: Range) => void);
dispose(): void; dispose(): void;
} }
......
...@@ -239,6 +239,13 @@ export class MainThreadCommentController { ...@@ -239,6 +239,13 @@ export class MainThreadCommentController {
updateComments(commentThreadHandle: number, comments: modes.Comment[]) { updateComments(commentThreadHandle: number, comments: modes.Comment[]) {
let thread = this._threads.get(commentThreadHandle); let thread = this._threads.get(commentThreadHandle);
thread.comments = comments; thread.comments = comments;
this._commentService.updateComments(`${this.handle}`, {
added: [],
removed: [],
changed: [thread],
draftMode: modes.DraftMode.NotSupported
});
} }
updateAcceptInputCommands(commentThreadHandle: number, acceptInputCommands: modes.Command[]) { updateAcceptInputCommands(commentThreadHandle: number, acceptInputCommands: modes.Command[]) {
...@@ -289,6 +296,15 @@ export class MainThreadCommentController { ...@@ -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 { toJSON(): any {
return { return {
$mid: 6, $mid: 6,
...@@ -348,9 +364,13 @@ export class MainThreadComments extends Disposable implements MainThreadComments ...@@ -348,9 +364,13 @@ export class MainThreadComments extends Disposable implements MainThreadComments
this._commentService.registerCommentController(String(handle), provider); this._commentService.registerCommentController(String(handle), provider);
this._commentControllers.set(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); const commentsPanelAlreadyConstructed = this._panelService.getPanels().some(panel => panel.id === COMMENTS_PANEL_ID);
if (!commentsPanelAlreadyConstructed) { if (!commentsPanelAlreadyConstructed) {
this.registerPanel(commentsPanelAlreadyConstructed); this.registerPanel(commentsPanelAlreadyConstructed);
this.registerOpenPanelListener(commentsPanelAlreadyConstructed);
} }
this._commentService.setWorkspaceComments(String(handle), []); this._commentService.setWorkspaceComments(String(handle), []);
} }
...@@ -466,6 +486,15 @@ export class MainThreadComments extends Disposable implements MainThreadComments ...@@ -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) { if (this._openPanelListener) {
this._openPanelListener.dispose(); this._openPanelListener.dispose();
this._openPanelListener = null; this._openPanelListener = null;
......
...@@ -106,9 +106,10 @@ export class ExtHostComments implements ExtHostCommentsShape { ...@@ -106,9 +106,10 @@ export class ExtHostComments implements ExtHostCommentsShape {
return Promise.resolve(undefined); return Promise.resolve(undefined);
} }
const document = this._documents.getDocument(URI.revive(uriComponents));
return asPromise(() => { return asPromise(() => {
return commentController.commentingRangeProvider.provider(URI.revive(uriComponents), token); return commentController.commentingRangeProvider.provider(document, token);
}).then(ranges => ranges.map(extHostTypeConverter.Range.from)); }).then(ranges => ranges ? ranges.map(extHostTypeConverter.Range.from) : undefined);
} }
$createNewCommentWidgetCallback(commentControllerHandle: number, uriComponents: UriComponents, range: IRange, token: CancellationToken): void { $createNewCommentWidgetCallback(commentControllerHandle: number, uriComponents: UriComponents, range: IRange, token: CancellationToken): void {
...@@ -118,7 +119,8 @@ export class ExtHostComments implements ExtHostCommentsShape { ...@@ -118,7 +119,8 @@ export class ExtHostComments implements ExtHostCommentsShape {
return; 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( registerWorkspaceCommentProvider(
...@@ -412,8 +414,8 @@ export class ExtHostCommentInputBox implements vscode.CommentInputBox { ...@@ -412,8 +414,8 @@ export class ExtHostCommentInputBox implements vscode.CommentInputBox {
class ExtHostCommentingRangeProvider { class ExtHostCommentingRangeProvider {
constructor( constructor(
public provider: (uri: vscode.Uri, token: vscode.CancellationToken) => vscode.ProviderResult<vscode.Range[]>, public provider: (document: vscode.TextDocument, token: vscode.CancellationToken) => vscode.ProviderResult<vscode.Range[]>,
public callback: (uri: vscode.Uri, range: vscode.Range) => void public callback: (document: vscode.TextDocument, range: vscode.Range) => void
) { ) {
} }
...@@ -464,7 +466,7 @@ class ExtHostCommentController implements vscode.CommentController { ...@@ -464,7 +466,7 @@ class ExtHostCommentController implements vscode.CommentController {
return commentThread; return commentThread;
} }
registerCommentingRangeProvider(provider: (uri: vscode.Uri, token: vscode.CancellationToken) => vscode.ProviderResult<vscode.Range[]>, callback: (uri: vscode.Uri, range: vscode.Range) => void) { registerCommentingRangeProvider(provider: (document: vscode.TextDocument, token: vscode.CancellationToken) => vscode.ProviderResult<vscode.Range[]>, callback: (document: vscode.TextDocument, range: vscode.Range) => void) {
this._commentingRangeProvider = new ExtHostCommentingRangeProvider(provider, callback); this._commentingRangeProvider = new ExtHostCommentingRangeProvider(provider, callback);
} }
......
...@@ -41,7 +41,7 @@ export class ResourceWithCommentThreads { ...@@ -41,7 +41,7 @@ export class ResourceWithCommentThreads {
constructor(resource: URI, commentThreads: CommentThread[]) { constructor(resource: URI, commentThreads: CommentThread[]) {
this.id = resource.toString(); this.id = resource.toString();
this.resource = resource; 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 { public static createCommentNode(resource: URI, commentThread: CommentThread): CommentNode {
...@@ -99,14 +99,20 @@ export class CommentsModel { ...@@ -99,14 +99,20 @@ export class CommentsModel {
// Find comment node on resource that is that thread and replace it // Find comment node on resource that is that thread and replace it
const index = firstIndex(matchingResourceData.commentThreads, (commentThread) => commentThread.threadId === thread.threadId); 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 => { added.forEach(thread => {
const existingResource = threadsForOwner.filter(resourceWithThreads => resourceWithThreads.resource.toString() === thread.resource); const existingResource = threadsForOwner.filter(resourceWithThreads => resourceWithThreads.resource.toString() === thread.resource);
if (existingResource.length) { if (existingResource.length) {
const resource = existingResource[0]; 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 { } else {
threadsForOwner.push(new ResourceWithCommentThreads(URI.parse(thread.resource), [thread])); threadsForOwner.push(new ResourceWithCommentThreads(URI.parse(thread.resource), [thread]));
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册