提交 6a480554 编写于 作者: P Peng Lyu

Bring back empty comment thread factory.

上级 9435d7cc
......@@ -1034,15 +1034,44 @@ declare module 'vscode' {
* Provide a list of ranges which allow new comment threads creation or null for a given document
*/
provideCommentingRanges(document: TextDocument, token: CancellationToken): ProviderResult<Range[]>;
}
export interface CommentThreadTemplate {
/**
* The human-readable label describing the [Comment Thread](#CommentThread)
*/
label?: string;
/**
* Optional accept input command
*
* `acceptInputCommand` is the default action rendered on Comment Widget, which is always placed rightmost.
* This command will be invoked when users the user accepts the value in the comment editor.
* This command will disabled when the comment editor is empty.
*/
acceptInputCommand?: Command;
/**
* The method `createEmptyCommentThread` is called when users attempt to create new comment thread from the gutter or command palette.
* Optional additonal commands.
*
* `additionalCommands` are the secondary actions rendered on Comment Widget.
*/
additionalCommands?: Command[];
}
export interface EmptyCommentThreadFactory {
template: CommentThreadTemplate;
/**
* When users attempt to create new comment thread from the gutter or command palette, `template` will be used first to create the Comment Thread Widget in the editor for users to start comment drafting.
* Then `createEmptyCommentThread` is called after that. Extensions should still call [`createCommentThread`](CommentController.createCommentThread) to create a real [`CommentThread`](#CommentThread)
* Extensions still need to call `createCommentThread` inside this call when appropriate.
*
* @param document The document in which users attempt to create a new comment thread
* @param range The range the comment threadill located within the document.
*
* @returns commentThread The [`CommentThread`](#CommentThread) created by extensions
*/
// REVIEW: dislike, not provider'ish.. Could this be something you set/provide when creating
// the `CommentsController` objects? E.g is this strictly coupled to the ability to limit the ranges
// in which you can comment?
createEmptyCommentThread(document: TextDocument, range: Range): ProviderResult<void>;
createEmptyCommentThread(document: TextDocument, range: Range): ProviderResult<CommentThread>;
}
export interface CommentController {
......@@ -1079,11 +1108,19 @@ declare module 'vscode' {
createCommentThread(id: string, resource: Uri, range: Range, comments: Comment[]): CommentThread;
/**
* Optional commenting range provider.
* Provide a list [ranges](#Range) which support commenting to any given resource uri.
* Optional commenting range provider. Provide a list [ranges](#Range) which support commenting to any given resource uri.
*
* If not provided and `emptyCommentThreadFactory` exits, users can leave comments in any document opened in the editor.
*/
commentingRangeProvider?: CommentingRangeProvider;
/**
* Optional empty comment thread factory. It's necessary for supporting users to trigger Comment Thread creation from the editor or command palette.
*
* If not provided, users won't be able to trigger new comment thread creation from the editor gutter area or command palette.
*/
emptyCommentThreadFactory?: EmptyCommentThreadFactory;
/**
* Optional reaction provider
* Stay in proposed.
......
......@@ -164,20 +164,21 @@ export class ExtHostComments implements ExtHostCommentsShape {
return Promise.resolve();
}
if (!(commentController as any).emptyCommentThreadFactory && !(commentController.commentingRangeProvider && commentController.commentingRangeProvider.createEmptyCommentThread)) {
if (!(commentController as any).emptyCommentThreadFactory && !(commentController.commentingRangeProvider && commentController.commentingRangeProvider.createEmptyCommentThread) && !(commentController.emptyCommentThreadFactory && commentController.emptyCommentThreadFactory.createEmptyCommentThread)) {
return Promise.resolve();
}
const document = this._documents.getDocument(URI.revive(uriComponents));
return asPromise(() => {
// TODO, remove this once GH PR stable deprecates `emptyCommentThreadFactory`.
if ((commentController as any).emptyCommentThreadFactory) {
return (commentController as any).emptyCommentThreadFactory!.createEmptyCommentThread(document, extHostTypeConverter.Range.to(range));
if (commentController.emptyCommentThreadFactory) {
return commentController.emptyCommentThreadFactory!.createEmptyCommentThread(document, extHostTypeConverter.Range.to(range));
}
if (commentController.commentingRangeProvider && commentController.commentingRangeProvider.createEmptyCommentThread) {
return commentController.commentingRangeProvider.createEmptyCommentThread(document, extHostTypeConverter.Range.to(range));
}
return;
}).then(() => Promise.resolve());
}
......@@ -582,7 +583,9 @@ class ExtHostCommentController implements vscode.CommentController {
}
private _threads: Map<number, ExtHostCommentThread> = new Map<number, ExtHostCommentThread>();
commentingRangeProvider?: vscode.CommentingRangeProvider;
commentingRangeProvider?: vscode.CommentingRangeProvider & { createEmptyCommentThread: (document: vscode.TextDocument, range: types.Range) => Promise<vscode.CommentThread>; };
emptyCommentThreadFactory?: vscode.EmptyCommentThreadFactory;
private _commentReactionProvider?: vscode.CommentReactionProvider;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册