add new comment.

This commit is contained in:
Peng Lyu
2018-04-13 09:59:49 -07:00
parent 0cdeb4109d
commit 36672be949
14 changed files with 243 additions and 41 deletions

View File

@@ -831,7 +831,8 @@ export interface ExtHostProgressShape {
}
export interface ExtHostCommentsShape {
$providerComments(handle: number, document: UriComponents): TPromise<modes.CommentThread[]>;
$provideComments(handle: number, document: UriComponents): TPromise<modes.CommentThread[]>;
$provideNewCommentRange(handle: number, document: UriComponents): TPromise<modes.NewCommentAction>;
}
// --- proxy identifiers

View File

@@ -14,6 +14,7 @@ import * as extHostTypeConverter from 'vs/workbench/api/node/extHostTypeConverte
import * as vscode from 'vscode';
import { ExtHostCommentsShape, IMainContext, MainContext, MainThreadCommentsShape } from './extHost.protocol';
import { CommandsConverter } from './extHostCommands';
import { IRange } from 'vs/editor/common/core/range';
export class ExtHostComments implements ExtHostCommentsShape {
@@ -46,7 +47,7 @@ export class ExtHostComments implements ExtHostCommentsShape {
};
}
$providerComments(handle: number, uri: UriComponents): TPromise<modes.CommentThread[]> {
$provideComments(handle: number, uri: UriComponents): TPromise<modes.CommentThread[]> {
const data = this._documents.getDocumentData(URI.revive(uri));
if (!data || !data.document) {
return TPromise.as([]);
@@ -58,13 +59,33 @@ export class ExtHostComments implements ExtHostCommentsShape {
})
.then(comments => comments.map(x => convertCommentThread(x, this._commandsConverter)));
}
$provideNewCommentRange(handle: number, uri: UriComponents): TPromise<modes.NewCommentAction> {
const data = this._documents.getDocumentData(URI.revive(uri));
if (!data || !data.document) {
return TPromise.as(null);
}
return asWinJsPromise(token => {
let provider = this._providers.get(handle);
return provider.provideNewCommentRange(data.document, token);
})
.then(newCommentAction => convertNewCommandAction(newCommentAction, this._commandsConverter));
}
}
function convertNewCommandAction(vscodeNewCommentAction: vscode.NewCommentAction, commandsConverter: CommandsConverter): modes.NewCommentAction {
return {
ranges: vscodeNewCommentAction.ranges.map(range => extHostTypeConverter.fromRange(range)),
actions: vscodeNewCommentAction.actions.map(commandsConverter.toInternal)
};
}
function convertCommentThread(vscodeCommentThread: vscode.CommentThread, commandsConverter: CommandsConverter): modes.CommentThread {
return {
threadId: vscodeCommentThread.threadId,
range: extHostTypeConverter.fromRange(vscodeCommentThread.range),
newCommentRange: extHostTypeConverter.fromRange(vscodeCommentThread.newCommentRange),
comments: vscodeCommentThread.comments.map(convertComment),
actions: vscodeCommentThread.actions.map(commandsConverter.toInternal)
};