mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-24 02:28:34 +01:00
toggle reactions
This commit is contained in:
@@ -120,6 +120,7 @@ export interface CommentProviderFeatures {
|
||||
|
||||
export interface MainThreadCommentsShape extends IDisposable {
|
||||
$registerCommentController(handle: number, id: string, label: string): void;
|
||||
$updateCommentControllerFeatures(handle: number, features: CommentProviderFeatures): void;
|
||||
$createCommentThread(handle: number, commentThreadHandle: number, threadId: string, resource: UriComponents, range: IRange, comments: modes.Comment[], acceptInputCommand: modes.Command | undefined, additionalCommands: modes.Command[], collapseState: modes.CommentThreadCollapsibleState): modes.CommentThread2 | undefined;
|
||||
$deleteCommentThread(handle: number, commentThreadHandle: number): void;
|
||||
$updateComments(handle: number, commentThreadHandle: number, comments: modes.Comment[]): void;
|
||||
@@ -1108,6 +1109,8 @@ export interface ExtHostCommentsShape {
|
||||
$createNewCommentThread(handle: number, document: UriComponents, range: IRange, text: string): Promise<modes.CommentThread | null>;
|
||||
$onCommentWidgetInputChange(commentControllerHandle: number, input: string | undefined): Promise<number | undefined>;
|
||||
$provideCommentingRanges(commentControllerHandle: number, uriComponents: UriComponents, token: CancellationToken): Promise<IRange[] | undefined>;
|
||||
$provideReactionGroup(commentControllerHandle: number): Promise<modes.CommentReaction[] | undefined>;
|
||||
$toggleReaction(commentControllerHandle: number, threadHandle: number, uri: UriComponents, comment: modes.Comment, reaction: modes.CommentReaction): Promise<void>;
|
||||
$createNewCommentWidgetCallback(commentControllerHandle: number, uriComponents: UriComponents, range: IRange, token: CancellationToken): void;
|
||||
$replyToCommentThread(handle: number, document: UriComponents, range: IRange, commentThread: modes.CommentThread, text: string): Promise<modes.CommentThread | null>;
|
||||
$editComment(handle: number, document: UriComponents, comment: modes.Comment, text: string): Promise<void>;
|
||||
|
||||
@@ -112,6 +112,37 @@ export class ExtHostComments implements ExtHostCommentsShape {
|
||||
}).then(ranges => ranges ? ranges.map(x => extHostTypeConverter.Range.from(x)) : undefined);
|
||||
}
|
||||
|
||||
$provideReactionGroup(commentControllerHandle: number): Promise<modes.CommentReaction[] | undefined> {
|
||||
const commentController = this._commentControllers.get(commentControllerHandle);
|
||||
|
||||
if (!commentController || !commentController.reactionProvider) {
|
||||
return Promise.resolve(undefined);
|
||||
}
|
||||
|
||||
return asPromise(() => {
|
||||
return commentController.reactionProvider.availableReactions;
|
||||
}).then(reactions => reactions.map(reaction => convertToReaction2(commentController.reactionProvider, reaction)));
|
||||
}
|
||||
|
||||
$toggleReaction(commentControllerHandle: number, threadHandle: number, uri: UriComponents, comment: modes.Comment, reaction: modes.CommentReaction): Promise<void> {
|
||||
const document = this._documents.getDocument(URI.revive(uri));
|
||||
const commentController = this._commentControllers.get(commentControllerHandle);
|
||||
|
||||
if (!commentController || !commentController.reactionProvider || !commentController.reactionProvider.toggleReaction) {
|
||||
return Promise.resolve(undefined);
|
||||
}
|
||||
|
||||
return asPromise(() => {
|
||||
const commentThread = commentController.getCommentThread(threadHandle);
|
||||
if (commentThread) {
|
||||
const vscodeComment = commentThread.getComment(comment.commentId);
|
||||
return commentController.reactionProvider.toggleReaction(document, vscodeComment, convertFromReaction(reaction));
|
||||
}
|
||||
|
||||
return Promise.resolve(undefined);
|
||||
});
|
||||
}
|
||||
|
||||
$createNewCommentWidgetCallback(commentControllerHandle: number, uriComponents: UriComponents, range: IRange, token: CancellationToken): void {
|
||||
const commentController = this._commentControllers.get(commentControllerHandle);
|
||||
|
||||
@@ -485,6 +516,18 @@ class ExtHostCommentController implements vscode.CommentController {
|
||||
commentingRangeProvider?: vscode.CommentingRangeProvider;
|
||||
emptyCommentThreadFactory: vscode.EmptyCommentThreadFactory;
|
||||
|
||||
|
||||
private _commentReactionProvider?: vscode.CommentReactionProvider;
|
||||
|
||||
get reactionProvider() {
|
||||
return this._commentReactionProvider;
|
||||
}
|
||||
|
||||
set reactionProvider(provider: vscode.CommentReactionProvider) {
|
||||
this._commentReactionProvider = provider;
|
||||
this._proxy.$updateCommentControllerFeatures(this.handle, { reactionGroup: provider.availableReactions.map(reaction => convertToReaction2(provider, reaction)) });
|
||||
}
|
||||
|
||||
constructor(
|
||||
_extension: IExtensionDescription,
|
||||
private _handle: number,
|
||||
@@ -591,7 +634,8 @@ function convertToModeComment(vscodeComment: vscode.Comment, commandsConverter:
|
||||
selectCommand: vscodeComment.selectCommand ? commandsConverter.toInternal(vscodeComment.selectCommand) : undefined,
|
||||
editCommand: vscodeComment.editCommand ? commandsConverter.toInternal(vscodeComment.editCommand) : undefined,
|
||||
deleteCommand: vscodeComment.editCommand ? commandsConverter.toInternal(vscodeComment.deleteCommand) : undefined,
|
||||
label: vscodeComment.label
|
||||
label: vscodeComment.label,
|
||||
commentReactions: vscodeComment.commentReactions ? vscodeComment.commentReactions.map(reaction => convertToReaction2(undefined, reaction)) : undefined
|
||||
};
|
||||
}
|
||||
|
||||
@@ -627,6 +671,16 @@ function convertToReaction(provider: vscode.DocumentCommentProvider | vscode.Wor
|
||||
};
|
||||
}
|
||||
|
||||
function convertToReaction2(provider: vscode.CommentReactionProvider | undefined, reaction: vscode.CommentReaction): modes.CommentReaction {
|
||||
return {
|
||||
label: reaction.label,
|
||||
iconPath: reaction.iconPath ? extHostTypeConverter.pathOrURIToURI(reaction.iconPath) : undefined,
|
||||
count: reaction.count,
|
||||
hasReacted: reaction.hasReacted,
|
||||
canEdit: true//!!provider.toggleReaction
|
||||
};
|
||||
}
|
||||
|
||||
function convertFromReaction(reaction: modes.CommentReaction): vscode.CommentReaction {
|
||||
return {
|
||||
label: reaction.label,
|
||||
|
||||
Reference in New Issue
Block a user