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

Remove Comment Id

上级 bfd274a2
......@@ -1333,8 +1333,7 @@ export enum CommentMode {
* @internal
*/
export interface Comment {
readonly commentId: string;
readonly uniqueIdInThread?: number;
readonly uniqueIdInThread: number;
readonly body: IMarkdownString;
readonly userName: string;
readonly userIconPath?: string;
......
......@@ -713,54 +713,6 @@ declare module 'vscode' {
//#endregion
/**
* Comment Reactions
* Stay in proposed.
*/
interface CommentReaction {
readonly hasReacted?: boolean;
}
/**
* Stay in proposed
*/
export interface CommentReactionProvider {
availableReactions: CommentReaction[];
toggleReaction?(document: TextDocument, comment: Comment, reaction: CommentReaction): Promise<void>;
}
export interface CommentController {
/**
* Optional reaction provider
* Stay in proposed.
*/
reactionProvider?: CommentReactionProvider;
}
/**
* A comment is displayed within the editor or the Comments Panel, depending on how it is provided.
*/
export interface Comment {
/**
* The id of the comment
*/
commentId: string;
}
/**
* A comment controller is able to provide [comments](#CommentThread) support to the editor and
* provide users various ways to interact with comments.
*/
export interface CommentController {
/**
* Optional reaction provider
*/
reactionProvider?: CommentReactionProvider;
}
//#endregion
//#region Terminal
......
......@@ -308,10 +308,6 @@ export class MainThreadCommentController {
return commentingRanges || [];
}
getReactionGroup(): modes.CommentReaction[] | undefined {
return this._features.reactionGroup;
}
async toggleReaction(uri: URI, thread: modes.CommentThread, comment: modes.Comment, reaction: modes.CommentReaction, token: CancellationToken): Promise<void> {
return this._proxy.$toggleReaction(this._handle, thread.commentThreadHandle, uri, comment, reaction);
}
......
......@@ -1284,7 +1284,6 @@ export interface ExtHostCommentsShape {
$updateCommentThreadTemplate(commentControllerHandle: number, threadHandle: number, range: IRange): Promise<void>;
$deleteCommentThread(commentControllerHandle: number, commentThreadHandle: number): void;
$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>;
}
......
......@@ -187,47 +187,28 @@ export class ExtHostComments implements ExtHostCommentsShape, IDisposable {
}).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 => convertToReaction(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) || commentController.reactionHandler)) {
if (!commentController || commentController.reactionHandler) {
return Promise.resolve(undefined);
}
return asPromise(() => {
const commentThread = commentController.getCommentThread(threadHandle);
if (commentThread) {
const vscodeComment = commentThread.getComment(comment.commentId);
const vscodeComment = commentThread.getCommentByUniqueId(comment.uniqueIdInThread);
if (commentController !== undefined && vscodeComment) {
if (commentController.reactionHandler) {
return commentController.reactionHandler(vscodeComment, convertFromReaction(reaction));
}
if (commentController.reactionProvider && commentController.reactionProvider.toggleReaction) {
return commentController.reactionProvider.toggleReaction(document, vscodeComment, convertFromReaction(reaction));
}
}
}
return Promise.resolve(undefined);
});
}
dispose() {
}
......@@ -391,16 +372,6 @@ export class ExtHostCommentThread implements vscode.CommentThread {
);
}
getComment(commentId: string): vscode.Comment | undefined {
const comments = this._comments.filter(comment => comment.commentId === commentId);
if (comments && comments.length) {
return comments[0];
}
return undefined;
}
getCommentByUniqueId(uniqueId: number): vscode.Comment | undefined {
for (let key of this._commentsMap) {
let comment = key[0];
......@@ -442,19 +413,6 @@ class ExtHostCommentController implements vscode.CommentController {
private _threads: Map<number, ExtHostCommentThread> = new Map<number, ExtHostCommentThread>();
commentingRangeProvider?: vscode.CommentingRangeProvider;
private _commentReactionProvider?: vscode.CommentReactionProvider;
get reactionProvider(): vscode.CommentReactionProvider | undefined {
return this._commentReactionProvider;
}
set reactionProvider(provider: vscode.CommentReactionProvider | undefined) {
this._commentReactionProvider = provider;
if (provider) {
this._proxy.$updateCommentControllerFeatures(this.handle, { reactionGroup: provider.availableReactions.map(reaction => convertToReaction(provider, reaction)) });
}
}
private _reactionHandler?: ReactionHandler;
get reactionHandler(): ReactionHandler | undefined {
......@@ -537,7 +495,6 @@ function convertToModeComment(thread: ExtHostCommentThread, commentController: E
const iconPath = vscodeComment.author && vscodeComment.author.iconPath ? vscodeComment.author.iconPath.toString() : undefined;
return {
commentId: vscodeComment.commentId,
mode: vscodeComment.mode,
contextValue: vscodeComment.contextValue,
uniqueIdInThread: commentUniqueId,
......@@ -545,17 +502,16 @@ function convertToModeComment(thread: ExtHostCommentThread, commentController: E
userName: vscodeComment.author.name,
userIconPath: iconPath,
label: vscodeComment.label,
commentReactions: vscodeComment.reactions ? vscodeComment.reactions.map(reaction => convertToReaction(commentController.reactionProvider, reaction)) : undefined
commentReactions: vscodeComment.reactions ? vscodeComment.reactions.map(reaction => convertToReaction(reaction)) : undefined
};
}
function convertToReaction(provider: vscode.CommentReactionProvider | undefined, reaction: vscode.CommentReaction): modes.CommentReaction {
function convertToReaction(reaction: vscode.CommentReaction): modes.CommentReaction {
return {
label: reaction.label,
iconPath: reaction.iconPath ? extHostTypeConverter.pathOrURIToURI(reaction.iconPath) : undefined,
count: reaction.count,
hasReacted: reaction.hasReacted,
canEdit: provider !== undefined ? !!provider.toggleReaction : false
hasReacted: reaction.authorHasReacted,
};
}
......@@ -564,7 +520,6 @@ function convertFromReaction(reaction: modes.CommentReaction): vscode.CommentRea
label: reaction.label || '',
count: reaction.count || 0,
iconPath: reaction.iconPath ? URI.revive(reaction.iconPath) : '',
hasReacted: reaction.hasReacted,
authorHasReacted: reaction.hasReacted || false
};
}
......
......@@ -318,18 +318,18 @@ export class CommentNode extends Disposable {
let toggleReactionAction = this.createReactionPicker2(this.comment.commentReactions || []);
this._reactionsActionBar.push(toggleReactionAction, { label: false, icon: true });
} else {
let reactionGroup = this.commentService.getReactionGroup(this.owner);
if (reactionGroup && reactionGroup.length) {
let toggleReactionAction = this.createReactionPicker2(reactionGroup || []);
this._reactionsActionBar.push(toggleReactionAction, { label: false, icon: true });
}
// let reactionGroup = this.commentService.getReactionGroup(this.owner);
// if (reactionGroup && reactionGroup.length) {
// let toggleReactionAction = this.createReactionPicker2(reactionGroup || []);
// this._reactionsActionBar.push(toggleReactionAction, { label: false, icon: true });
// }
}
}
private createCommentEditor(): void {
const container = dom.append(this._commentEditContainer, dom.$('.edit-textarea'));
this._commentEditor = this.instantiationService.createInstance(SimpleCommentEditor, container, SimpleCommentEditor.getEditorOptions(), this.parentEditor, this.parentThread);
const resource = URI.parse(`comment:commentinput-${this.comment.commentId}-${Date.now()}.md`);
const resource = URI.parse(`comment:commentinput-${this.comment.uniqueIdInThread}-${Date.now()}.md`);
this._commentEditorModel = this.modelService.createModel('', this.modeService.createByFilepathOrFirstLine(resource), resource, false);
this._commentEditor.setModel(this._commentEditorModel);
......
......@@ -54,7 +54,6 @@ export interface ICommentService {
disposeCommentThread(ownerId: string, threadId: string): void;
getComments(resource: URI): Promise<(ICommentInfo | null)[]>;
getCommentingRanges(resource: URI): Promise<IRange[]>;
getReactionGroup(owner: string): CommentReaction[] | undefined;
hasReactionHandler(owner: string): boolean;
toggleReaction(owner: string, resource: URI, thread: CommentThread, comment: Comment, reaction: CommentReaction): Promise<void>;
setActiveCommentThread(commentThread: CommentThread | null): void;
......@@ -183,22 +182,6 @@ export class CommentService extends Disposable implements ICommentService {
}
}
getReactionGroup(owner: string): CommentReaction[] | undefined {
const commentProvider = this._commentControls.get(owner);
if (commentProvider) {
return commentProvider.getReactionGroup();
}
const commentController = this._commentControls.get(owner);
if (commentController) {
return commentController.getReactionGroup();
}
return undefined;
}
hasReactionHandler(owner: string): boolean {
const commentProvider = this._commentControls.get(owner);
......
......@@ -161,14 +161,14 @@ export class ReviewZoneWidget extends ZoneWidget implements ICommentThreadWidget
// we don't do anything here as we always do the reveal ourselves.
}
public reveal(commentId?: string) {
public reveal(commentUniqueId?: number) {
if (!this._isExpanded) {
this.show({ lineNumber: this._commentThread.range.startLineNumber, column: 1 }, 2);
}
if (commentId) {
if (commentUniqueId !== undefined) {
let height = this.editor.getLayoutInfo().height;
let matchedNode = this._commentElements.filter(commentNode => commentNode.comment.commentId === commentId);
let matchedNode = this._commentElements.filter(commentNode => commentNode.comment.uniqueIdInThread === commentUniqueId);
if (matchedNode && matchedNode.length) {
const commentThreadCoords = dom.getDomNodePagePosition(this._commentElements[0].domNode);
const commentCoords = dom.getDomNodePagePosition(matchedNode[0].domNode);
......@@ -289,7 +289,7 @@ export class ReviewZoneWidget extends ZoneWidget implements ICommentThreadWidget
let commentElementsToDelIndex: number[] = [];
for (let i = 0; i < oldCommentsLen; i++) {
let comment = this._commentElements[i].comment;
let newComment = commentThread.comments ? commentThread.comments.filter(c => c.commentId === comment.commentId) : [];
let newComment = commentThread.comments ? commentThread.comments.filter(c => c.uniqueIdInThread === comment.uniqueIdInThread) : [];
if (newComment.length) {
this._commentElements[i].update(newComment[0]);
......@@ -309,7 +309,7 @@ export class ReviewZoneWidget extends ZoneWidget implements ICommentThreadWidget
let newCommentNodeList: CommentNode[] = [];
for (let i = newCommentsLen - 1; i >= 0; i--) {
let currentComment = commentThread.comments![i];
let oldCommentNode = this._commentElements.filter(commentNode => commentNode.comment.commentId === currentComment.commentId);
let oldCommentNode = this._commentElements.filter(commentNode => commentNode.comment.uniqueIdInThread === currentComment.uniqueIdInThread);
if (oldCommentNode.length) {
oldCommentNode[0].update(currentComment);
lastCommentElement = oldCommentNode[0].domNode;
......@@ -606,13 +606,13 @@ export class ReviewZoneWidget extends ZoneWidget implements ICommentThreadWidget
this._disposables.add(newCommentNode);
this._disposables.add(newCommentNode.onDidDelete(deletedNode => {
const deletedNodeId = deletedNode.comment.commentId;
const deletedElementIndex = arrays.firstIndex(this._commentElements, commentNode => commentNode.comment.commentId === deletedNodeId);
const deletedNodeId = deletedNode.comment.uniqueIdInThread;
const deletedElementIndex = arrays.firstIndex(this._commentElements, commentNode => commentNode.comment.uniqueIdInThread === deletedNodeId);
if (deletedElementIndex > -1) {
this._commentElements.splice(deletedElementIndex, 1);
}
const deletedCommentIndex = arrays.firstIndex(this._commentThread.comments!, comment => comment.commentId === deletedNodeId);
const deletedCommentIndex = arrays.firstIndex(this._commentThread.comments!, comment => comment.uniqueIdInThread === deletedNodeId);
if (deletedCommentIndex > -1) {
this._commentThread.comments!.splice(deletedCommentIndex, 1);
}
......
......@@ -247,18 +247,18 @@ export class ReviewController implements IEditorContribution {
return editor.getContribution<ReviewController>(ID);
}
public revealCommentThread(threadId: string, commentId: string, fetchOnceIfNotExist: boolean): void {
public revealCommentThread(threadId: string, commentUniqueId: number, fetchOnceIfNotExist: boolean): void {
const commentThreadWidget = this._commentWidgets.filter(widget => widget.commentThread.threadId === threadId);
if (commentThreadWidget.length === 1) {
commentThreadWidget[0].reveal(commentId);
commentThreadWidget[0].reveal(commentUniqueId);
} else if (fetchOnceIfNotExist) {
if (this._computePromise) {
this._computePromise.then(_ => {
this.revealCommentThread(threadId, commentId, false);
this.revealCommentThread(threadId, commentUniqueId, false);
});
} else {
this.beginCompute().then(_ => {
this.revealCommentThread(threadId, commentId, false);
this.revealCommentThread(threadId, commentUniqueId, false);
});
}
}
......
......@@ -175,7 +175,7 @@ export class CommentsPanel extends Panel {
let currentActiveResource = activeEditor ? activeEditor.getResource() : undefined;
if (currentActiveResource && currentActiveResource.toString() === element.resource.toString()) {
const threadToReveal = element instanceof ResourceWithCommentThreads ? element.commentThreads[0].threadId : element.threadId;
const commentToReveal = element instanceof ResourceWithCommentThreads ? element.commentThreads[0].comment.commentId : element.comment.commentId;
const commentToReveal = element instanceof ResourceWithCommentThreads ? element.commentThreads[0].comment.uniqueIdInThread : element.comment.uniqueIdInThread;
const control = this.editorService.activeTextEditorWidget;
if (threadToReveal && isCodeEditor(control)) {
const controller = ReviewController.get(control);
......@@ -200,7 +200,7 @@ export class CommentsPanel extends Panel {
const control = editor.getControl();
if (threadToReveal && isCodeEditor(control)) {
const controller = ReviewController.get(control);
controller.revealCommentThread(threadToReveal, commentToReveal.commentId, true);
controller.revealCommentThread(threadToReveal, commentToReveal.uniqueIdInThread, true);
}
}
});
......
......@@ -23,7 +23,7 @@ export class CommentsDataSource implements IDataSource {
return element.id;
}
if (element instanceof CommentNode) {
return `${element.resource.toString()}-${element.comment.commentId}`;
return `${element.resource.toString()}-${element.comment.uniqueIdInThread}`;
}
return '';
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册