Add support for editing comments, #58078

This commit is contained in:
Rachel Macfarlane
2018-09-17 11:22:41 -07:00
committed by GitHub
parent ec058d3dd4
commit 1d1105e96b
9 changed files with 445 additions and 108 deletions

View File

@@ -73,10 +73,10 @@ export class ExtHostComments implements ExtHostCommentsShape {
return TPromise.as(null);
}
const provider = this._documentProviders.get(handle);
return asThenable(() => {
let provider = this._documentProviders.get(handle);
return provider.createNewCommentThread(data.document, ran, text, CancellationToken.None);
}).then(commentThread => commentThread ? convertToCommentThread(commentThread, this._commandsConverter) : null);
}).then(commentThread => commentThread ? convertToCommentThread(provider, commentThread, this._commandsConverter) : null);
}
$replyToCommentThread(handle: number, uri: UriComponents, range: IRange, thread: modes.CommentThread, text: string): Thenable<modes.CommentThread> {
@@ -87,10 +87,23 @@ export class ExtHostComments implements ExtHostCommentsShape {
return TPromise.as(null);
}
const provider = this._documentProviders.get(handle);
return asThenable(() => {
let provider = this._documentProviders.get(handle);
return provider.replyToCommentThread(data.document, ran, convertFromCommentThread(thread), text, CancellationToken.None);
}).then(commentThread => commentThread ? convertToCommentThread(commentThread, this._commandsConverter) : null);
}).then(commentThread => commentThread ? convertToCommentThread(provider, commentThread, this._commandsConverter) : null);
}
$editComment(handle: number, uri: UriComponents, comment: modes.Comment, text: string): Thenable<modes.Comment> {
const data = this._documents.getDocumentData(URI.revive(uri));
if (!data || !data.document) {
throw new Error('Unable to retrieve document from URI');
}
const provider = this._documentProviders.get(handle);
return asThenable(() => {
return provider.editComment(data.document, convertFromComment(comment), text, CancellationToken.None);
}).then(comment => convertToComment(provider, comment, this._commandsConverter));
}
$provideDocumentComments(handle: number, uri: UriComponents): Thenable<modes.CommentInfo> {
@@ -99,11 +112,10 @@ export class ExtHostComments implements ExtHostCommentsShape {
return TPromise.as(null);
}
const provider = this._documentProviders.get(handle);
return asThenable(() => {
let provider = this._documentProviders.get(handle);
return provider.provideDocumentComments(data.document, CancellationToken.None);
})
.then(commentInfo => commentInfo ? convertCommentInfo(handle, commentInfo, this._commandsConverter) : null);
}).then(commentInfo => commentInfo ? convertCommentInfo(handle, provider, commentInfo, this._commandsConverter) : null);
}
$provideWorkspaceComments(handle: number): Thenable<modes.CommentThread[]> {
@@ -115,7 +127,7 @@ export class ExtHostComments implements ExtHostCommentsShape {
return asThenable(() => {
return provider.provideWorkspaceComments(CancellationToken.None);
}).then(comments =>
comments.map(x => convertToCommentThread(x, this._commandsConverter)
comments.map(comment => convertToCommentThread(provider, comment, this._commandsConverter)
));
}
@@ -124,28 +136,28 @@ export class ExtHostComments implements ExtHostCommentsShape {
this._proxy.$onDidCommentThreadsChange(handle, {
owner: handle,
changed: event.changed.map(x => convertToCommentThread(x, this._commandsConverter)),
added: event.added.map(x => convertToCommentThread(x, this._commandsConverter)),
removed: event.removed.map(x => convertToCommentThread(x, this._commandsConverter))
changed: event.changed.map(thread => convertToCommentThread(provider, thread, this._commandsConverter)),
added: event.added.map(thread => convertToCommentThread(provider, thread, this._commandsConverter)),
removed: event.removed.map(thread => convertToCommentThread(provider, thread, this._commandsConverter))
});
});
}
}
function convertCommentInfo(owner: number, vscodeCommentInfo: vscode.CommentInfo, commandsConverter: CommandsConverter): modes.CommentInfo {
function convertCommentInfo(owner: number, provider: vscode.DocumentCommentProvider, vscodeCommentInfo: vscode.CommentInfo, commandsConverter: CommandsConverter): modes.CommentInfo {
return {
owner: owner,
threads: vscodeCommentInfo.threads.map(x => convertToCommentThread(x, commandsConverter)),
threads: vscodeCommentInfo.threads.map(x => convertToCommentThread(provider, x, commandsConverter)),
commentingRanges: vscodeCommentInfo.commentingRanges ? vscodeCommentInfo.commentingRanges.map(range => extHostTypeConverter.Range.from(range)) : []
};
}
function convertToCommentThread(vscodeCommentThread: vscode.CommentThread, commandsConverter: CommandsConverter): modes.CommentThread {
function convertToCommentThread(provider: vscode.DocumentCommentProvider | vscode.WorkspaceCommentProvider, vscodeCommentThread: vscode.CommentThread, commandsConverter: CommandsConverter): modes.CommentThread {
return {
threadId: vscodeCommentThread.threadId,
resource: vscodeCommentThread.resource.toString(),
range: extHostTypeConverter.Range.from(vscodeCommentThread.range),
comments: vscodeCommentThread.comments.map(comment => convertToComment(comment, commandsConverter)),
comments: vscodeCommentThread.comments.map(comment => convertToComment(provider, comment, commandsConverter)),
collapsibleState: vscodeCommentThread.collapsibleState
};
}
@@ -165,16 +177,19 @@ function convertFromComment(comment: modes.Comment): vscode.Comment {
commentId: comment.commentId,
body: extHostTypeConverter.MarkdownString.to(comment.body),
userName: comment.userName,
gravatar: comment.gravatar
gravatar: comment.gravatar,
canEdit: comment.canEdit
};
}
function convertToComment(vscodeComment: vscode.Comment, commandsConverter: CommandsConverter): modes.Comment {
function convertToComment(provider: vscode.DocumentCommentProvider | vscode.WorkspaceCommentProvider, vscodeComment: vscode.Comment, commandsConverter: CommandsConverter): modes.Comment {
const canEdit = !!(provider as vscode.DocumentCommentProvider).editComment && vscodeComment.canEdit;
return {
commentId: vscodeComment.commentId,
body: extHostTypeConverter.MarkdownString.from(vscodeComment.body),
userName: vscodeComment.userName,
gravatar: vscodeComment.gravatar,
canEdit: canEdit,
command: vscodeComment.command ? commandsConverter.toInternal(vscodeComment.command) : null
};
}