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

comments panel handle new comment thread registration.

上级 42194d82
......@@ -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<Range[]>, callback: (uri: Uri, range: Range) => void);
registerCommentingRangeProvider(provider: (document: TextDocument, token: CancellationToken) => ProviderResult<Range[]>, callback: (document: TextDocument, range: Range) => void);
dispose(): void;
}
......
......@@ -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;
......
......@@ -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<vscode.Range[]>,
public callback: (uri: vscode.Uri, range: vscode.Range) => void
public provider: (document: vscode.TextDocument, token: vscode.CancellationToken) => vscode.ProviderResult<vscode.Range[]>,
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<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);
}
......
......@@ -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]));
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册