提交 c8ffa51c 编写于 作者: P Peng Lyu

optional commenting range provider and empty comemnt thread factory.

上级 05efab0e
......@@ -736,7 +736,7 @@ declare module 'vscode' {
range: Range;
/**
* Label describing the [Comment Thread](#CommentThread)
* The human-readable label describing the [Comment Thread](#CommentThread)
*/
label?: string;
......@@ -746,19 +746,24 @@ declare module 'vscode' {
comments: Comment[];
/**
* Optional accept input command
*
* `acceptInputCommand` is the default action rendered on Comment Widget, which is always placed rightmost.
* It will be executed when users submit the comment from keyboard shortcut.
* This action is disabled when the comment editor is empty.
* 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;
/**
* Optional additonal commands.
*
* `additionalCommands` are the secondary actions rendered on Comment Widget.
*/
additionalCommands?: Command[];
/**
* Whether the thread should be collapsed or expanded when opening the document. Defaults to Collapsed.
* Whether the thread should be collapsed or expanded when opening the document.
* Defaults to Collapsed.
*/
collapsibleState?: CommentThreadCollapsibleState;
dispose?(): void;
......@@ -931,24 +936,49 @@ declare module 'vscode' {
value: string;
}
export interface CommentingRangeProvider {
provideCommentingRange(document: TextDocument, token: CancellationToken): ProviderResult<Range[]>;
}
export interface EmptyCommentThreadFactory {
/**
* The method `createEmptyCommentThread` is called when users attempt to create new comment thread from the gutter or command palette.
* Extensions still need to call `createCommentThread` inside this call when appropriate.
*/
createEmptyCommentThread(document: TextDocument, range: Range): ProviderResult<void>;
}
export interface CommentController {
/**
* The id of this comment controller.
*/
readonly id: string;
/**
* The human-readable label of this comment controller.
*/
readonly label: string;
/**
* The active (focused) comment input box.
* The active (focused) [comment input box](#CommentInputBox).
*/
readonly inputBox?: CommentInputBox;
createCommentThread(id: string, resource: Uri, range: Range): CommentThread;
/**
* Optional commenting range provider.
* Provide a list [ranges](#Range) which support commenting to any given resource uri.
*
* @param uri The uri of the resource open in a text editor.
* @param callback, a handler called when users attempt to create a new comment thread, either from the gutter or command palette
* @param token A cancellation token.
* @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: (document: TextDocument, token: CancellationToken) => ProviderResult<Range[]>, callback: (document: TextDocument, range: Range) => void): void;
commentingRangeProvider?: CommentingRangeProvider;
/**
* Optional new comment thread factory.
*/
emptyCommentThreadFactory: EmptyCommentThreadFactory;
/**
* Dispose this comment controller.
*/
dispose(): void;
}
......
......@@ -108,19 +108,19 @@ export class ExtHostComments implements ExtHostCommentsShape {
const document = this._documents.getDocument(URI.revive(uriComponents));
return asPromise(() => {
return commentController.commentingRangeProvider.provider(document, token);
return commentController.commentingRangeProvider.provideCommentingRange(document, token);
}).then(ranges => ranges ? ranges.map(extHostTypeConverter.Range.from) : undefined);
}
$createNewCommentWidgetCallback(commentControllerHandle: number, uriComponents: UriComponents, range: IRange, token: CancellationToken): void {
const commentController = this._commentControllers.get(commentControllerHandle);
if (!commentController || !commentController.commentingRangeProvider) {
if (!commentController || !commentController.emptyCommentThreadFactory) {
return;
}
const document = this._documents.getDocument(URI.revive(uriComponents));
commentController.commentingRangeProvider.callback(document, extHostTypeConverter.Range.to(range));
commentController.emptyCommentThreadFactory.createEmptyCommentThread(document, extHostTypeConverter.Range.to(range));
}
registerWorkspaceCommentProvider(
......@@ -435,16 +435,6 @@ export class ExtHostCommentInputBox implements vscode.CommentInputBox {
this._value = input;
}
}
class ExtHostCommentingRangeProvider {
constructor(
public provider: (document: vscode.TextDocument, token: vscode.CancellationToken) => vscode.ProviderResult<vscode.Range[]>,
public callback: (document: vscode.TextDocument, range: vscode.Range) => void
) {
}
}
class ExtHostCommentController implements vscode.CommentController {
get id(): string {
return this._id;
......@@ -462,16 +452,8 @@ class ExtHostCommentController implements vscode.CommentController {
}
private _threads: Map<number, ExtHostCommentThread> = new Map<number, ExtHostCommentThread>();
private _commentingRangeProvider: ExtHostCommentingRangeProvider | undefined = undefined;
get commentingRangeProvider(): ExtHostCommentingRangeProvider | undefined {
return this._commentingRangeProvider;
}
set commentingRangeProvider(commentingRangeProvider: ExtHostCommentingRangeProvider | undefined) {
this._commentingRangeProvider = commentingRangeProvider;
}
commentingRangeProvider?: vscode.CommentingRangeProvider;
emptyCommentThreadFactory: vscode.EmptyCommentThreadFactory;
constructor(
_extension: IExtensionDescription,
......@@ -490,10 +472,6 @@ class ExtHostCommentController implements vscode.CommentController {
return commentThread;
}
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);
}
$onCommentWidgetInputChange(input: string) {
if (!this.inputBox) {
this.inputBox = new ExtHostCommentInputBox(this._proxy, this.handle, input);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册