Skip to content

Commit f1bad37

Browse files
committed
Remove Comment Id
1 parent bfd274a commit f1bad37

11 files changed

Lines changed: 27 additions & 143 deletions

File tree

src/vs/editor/common/modes.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1333,8 +1333,7 @@ export enum CommentMode {
13331333
* @internal
13341334
*/
13351335
export interface Comment {
1336-
readonly commentId: string;
1337-
readonly uniqueIdInThread?: number;
1336+
readonly uniqueIdInThread: number;
13381337
readonly body: IMarkdownString;
13391338
readonly userName: string;
13401339
readonly userIconPath?: string;

src/vs/vscode.proposed.d.ts

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -713,54 +713,6 @@ declare module 'vscode' {
713713

714714
//#endregion
715715

716-
/**
717-
* Comment Reactions
718-
* Stay in proposed.
719-
*/
720-
interface CommentReaction {
721-
readonly hasReacted?: boolean;
722-
}
723-
724-
/**
725-
* Stay in proposed
726-
*/
727-
export interface CommentReactionProvider {
728-
availableReactions: CommentReaction[];
729-
toggleReaction?(document: TextDocument, comment: Comment, reaction: CommentReaction): Promise<void>;
730-
}
731-
732-
733-
export interface CommentController {
734-
/**
735-
* Optional reaction provider
736-
* Stay in proposed.
737-
*/
738-
reactionProvider?: CommentReactionProvider;
739-
}
740-
741-
742-
/**
743-
* A comment is displayed within the editor or the Comments Panel, depending on how it is provided.
744-
*/
745-
export interface Comment {
746-
/**
747-
* The id of the comment
748-
*/
749-
commentId: string;
750-
}
751-
752-
/**
753-
* A comment controller is able to provide [comments](#CommentThread) support to the editor and
754-
* provide users various ways to interact with comments.
755-
*/
756-
export interface CommentController {
757-
/**
758-
* Optional reaction provider
759-
*/
760-
reactionProvider?: CommentReactionProvider;
761-
}
762-
763-
//#endregion
764716

765717
//#region Terminal
766718

src/vs/workbench/api/browser/mainThreadComments.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -308,10 +308,6 @@ export class MainThreadCommentController {
308308
return commentingRanges || [];
309309
}
310310

311-
getReactionGroup(): modes.CommentReaction[] | undefined {
312-
return this._features.reactionGroup;
313-
}
314-
315311
async toggleReaction(uri: URI, thread: modes.CommentThread, comment: modes.Comment, reaction: modes.CommentReaction, token: CancellationToken): Promise<void> {
316312
return this._proxy.$toggleReaction(this._handle, thread.commentThreadHandle, uri, comment, reaction);
317313
}

src/vs/workbench/api/common/extHost.protocol.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1284,7 +1284,6 @@ export interface ExtHostCommentsShape {
12841284
$updateCommentThreadTemplate(commentControllerHandle: number, threadHandle: number, range: IRange): Promise<void>;
12851285
$deleteCommentThread(commentControllerHandle: number, commentThreadHandle: number): void;
12861286
$provideCommentingRanges(commentControllerHandle: number, uriComponents: UriComponents, token: CancellationToken): Promise<IRange[] | undefined>;
1287-
$provideReactionGroup(commentControllerHandle: number): Promise<modes.CommentReaction[] | undefined>;
12881287
$toggleReaction(commentControllerHandle: number, threadHandle: number, uri: UriComponents, comment: modes.Comment, reaction: modes.CommentReaction): Promise<void>;
12891288
}
12901289

src/vs/workbench/api/common/extHostComments.ts

Lines changed: 5 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -187,47 +187,28 @@ export class ExtHostComments implements ExtHostCommentsShape, IDisposable {
187187
}).then(ranges => ranges ? ranges.map(x => extHostTypeConverter.Range.from(x)) : undefined);
188188
}
189189

190-
$provideReactionGroup(commentControllerHandle: number): Promise<modes.CommentReaction[] | undefined> {
191-
const commentController = this._commentControllers.get(commentControllerHandle);
192-
193-
if (!commentController || !commentController.reactionProvider) {
194-
return Promise.resolve(undefined);
195-
}
196-
197-
return asPromise(() => {
198-
return commentController!.reactionProvider!.availableReactions;
199-
}).then(reactions => reactions.map(reaction => convertToReaction(commentController.reactionProvider, reaction)));
200-
}
201-
202190
$toggleReaction(commentControllerHandle: number, threadHandle: number, uri: UriComponents, comment: modes.Comment, reaction: modes.CommentReaction): Promise<void> {
203-
const document = this._documents.getDocument(URI.revive(uri));
204191
const commentController = this._commentControllers.get(commentControllerHandle);
205192

206-
if (!commentController || !((commentController.reactionProvider && commentController.reactionProvider.toggleReaction) || commentController.reactionHandler)) {
193+
if (!commentController || commentController.reactionHandler) {
207194
return Promise.resolve(undefined);
208195
}
209196

210197
return asPromise(() => {
211198
const commentThread = commentController.getCommentThread(threadHandle);
212199
if (commentThread) {
213-
const vscodeComment = commentThread.getComment(comment.commentId);
200+
const vscodeComment = commentThread.getCommentByUniqueId(comment.uniqueIdInThread);
214201

215202
if (commentController !== undefined && vscodeComment) {
216203
if (commentController.reactionHandler) {
217204
return commentController.reactionHandler(vscodeComment, convertFromReaction(reaction));
218205
}
219-
220-
if (commentController.reactionProvider && commentController.reactionProvider.toggleReaction) {
221-
return commentController.reactionProvider.toggleReaction(document, vscodeComment, convertFromReaction(reaction));
222-
}
223206
}
224-
225207
}
226208

227209
return Promise.resolve(undefined);
228210
});
229211
}
230-
231212
dispose() {
232213

233214
}
@@ -391,16 +372,6 @@ export class ExtHostCommentThread implements vscode.CommentThread {
391372
);
392373
}
393374

394-
getComment(commentId: string): vscode.Comment | undefined {
395-
const comments = this._comments.filter(comment => comment.commentId === commentId);
396-
397-
if (comments && comments.length) {
398-
return comments[0];
399-
}
400-
401-
return undefined;
402-
}
403-
404375
getCommentByUniqueId(uniqueId: number): vscode.Comment | undefined {
405376
for (let key of this._commentsMap) {
406377
let comment = key[0];
@@ -442,19 +413,6 @@ class ExtHostCommentController implements vscode.CommentController {
442413
private _threads: Map<number, ExtHostCommentThread> = new Map<number, ExtHostCommentThread>();
443414
commentingRangeProvider?: vscode.CommentingRangeProvider;
444415

445-
private _commentReactionProvider?: vscode.CommentReactionProvider;
446-
447-
get reactionProvider(): vscode.CommentReactionProvider | undefined {
448-
return this._commentReactionProvider;
449-
}
450-
451-
set reactionProvider(provider: vscode.CommentReactionProvider | undefined) {
452-
this._commentReactionProvider = provider;
453-
if (provider) {
454-
this._proxy.$updateCommentControllerFeatures(this.handle, { reactionGroup: provider.availableReactions.map(reaction => convertToReaction(provider, reaction)) });
455-
}
456-
}
457-
458416
private _reactionHandler?: ReactionHandler;
459417

460418
get reactionHandler(): ReactionHandler | undefined {
@@ -537,25 +495,23 @@ function convertToModeComment(thread: ExtHostCommentThread, commentController: E
537495
const iconPath = vscodeComment.author && vscodeComment.author.iconPath ? vscodeComment.author.iconPath.toString() : undefined;
538496

539497
return {
540-
commentId: vscodeComment.commentId,
541498
mode: vscodeComment.mode,
542499
contextValue: vscodeComment.contextValue,
543500
uniqueIdInThread: commentUniqueId,
544501
body: extHostTypeConverter.MarkdownString.from(vscodeComment.body),
545502
userName: vscodeComment.author.name,
546503
userIconPath: iconPath,
547504
label: vscodeComment.label,
548-
commentReactions: vscodeComment.reactions ? vscodeComment.reactions.map(reaction => convertToReaction(commentController.reactionProvider, reaction)) : undefined
505+
commentReactions: vscodeComment.reactions ? vscodeComment.reactions.map(reaction => convertToReaction(reaction)) : undefined
549506
};
550507
}
551508

552-
function convertToReaction(provider: vscode.CommentReactionProvider | undefined, reaction: vscode.CommentReaction): modes.CommentReaction {
509+
function convertToReaction(reaction: vscode.CommentReaction): modes.CommentReaction {
553510
return {
554511
label: reaction.label,
555512
iconPath: reaction.iconPath ? extHostTypeConverter.pathOrURIToURI(reaction.iconPath) : undefined,
556513
count: reaction.count,
557-
hasReacted: reaction.hasReacted,
558-
canEdit: provider !== undefined ? !!provider.toggleReaction : false
514+
hasReacted: reaction.authorHasReacted,
559515
};
560516
}
561517

@@ -564,7 +520,6 @@ function convertFromReaction(reaction: modes.CommentReaction): vscode.CommentRea
564520
label: reaction.label || '',
565521
count: reaction.count || 0,
566522
iconPath: reaction.iconPath ? URI.revive(reaction.iconPath) : '',
567-
hasReacted: reaction.hasReacted,
568523
authorHasReacted: reaction.hasReacted || false
569524
};
570525
}

src/vs/workbench/contrib/comments/browser/commentNode.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -318,18 +318,18 @@ export class CommentNode extends Disposable {
318318
let toggleReactionAction = this.createReactionPicker2(this.comment.commentReactions || []);
319319
this._reactionsActionBar.push(toggleReactionAction, { label: false, icon: true });
320320
} else {
321-
let reactionGroup = this.commentService.getReactionGroup(this.owner);
322-
if (reactionGroup && reactionGroup.length) {
323-
let toggleReactionAction = this.createReactionPicker2(reactionGroup || []);
324-
this._reactionsActionBar.push(toggleReactionAction, { label: false, icon: true });
325-
}
321+
// let reactionGroup = this.commentService.getReactionGroup(this.owner);
322+
// if (reactionGroup && reactionGroup.length) {
323+
// let toggleReactionAction = this.createReactionPicker2(reactionGroup || []);
324+
// this._reactionsActionBar.push(toggleReactionAction, { label: false, icon: true });
325+
// }
326326
}
327327
}
328328

329329
private createCommentEditor(): void {
330330
const container = dom.append(this._commentEditContainer, dom.$('.edit-textarea'));
331331
this._commentEditor = this.instantiationService.createInstance(SimpleCommentEditor, container, SimpleCommentEditor.getEditorOptions(), this.parentEditor, this.parentThread);
332-
const resource = URI.parse(`comment:commentinput-${this.comment.commentId}-${Date.now()}.md`);
332+
const resource = URI.parse(`comment:commentinput-${this.comment.uniqueIdInThread}-${Date.now()}.md`);
333333
this._commentEditorModel = this.modelService.createModel('', this.modeService.createByFilepathOrFirstLine(resource), resource, false);
334334

335335
this._commentEditor.setModel(this._commentEditorModel);

src/vs/workbench/contrib/comments/browser/commentService.ts

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ export interface ICommentService {
5454
disposeCommentThread(ownerId: string, threadId: string): void;
5555
getComments(resource: URI): Promise<(ICommentInfo | null)[]>;
5656
getCommentingRanges(resource: URI): Promise<IRange[]>;
57-
getReactionGroup(owner: string): CommentReaction[] | undefined;
5857
hasReactionHandler(owner: string): boolean;
5958
toggleReaction(owner: string, resource: URI, thread: CommentThread, comment: Comment, reaction: CommentReaction): Promise<void>;
6059
setActiveCommentThread(commentThread: CommentThread | null): void;
@@ -183,22 +182,6 @@ export class CommentService extends Disposable implements ICommentService {
183182
}
184183
}
185184

186-
getReactionGroup(owner: string): CommentReaction[] | undefined {
187-
const commentProvider = this._commentControls.get(owner);
188-
189-
if (commentProvider) {
190-
return commentProvider.getReactionGroup();
191-
}
192-
193-
const commentController = this._commentControls.get(owner);
194-
195-
if (commentController) {
196-
return commentController.getReactionGroup();
197-
}
198-
199-
return undefined;
200-
}
201-
202185
hasReactionHandler(owner: string): boolean {
203186
const commentProvider = this._commentControls.get(owner);
204187

src/vs/workbench/contrib/comments/browser/commentThreadWidget.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -161,14 +161,14 @@ export class ReviewZoneWidget extends ZoneWidget implements ICommentThreadWidget
161161
// we don't do anything here as we always do the reveal ourselves.
162162
}
163163

164-
public reveal(commentId?: string) {
164+
public reveal(commentUniqueId?: number) {
165165
if (!this._isExpanded) {
166166
this.show({ lineNumber: this._commentThread.range.startLineNumber, column: 1 }, 2);
167167
}
168168

169-
if (commentId) {
169+
if (commentUniqueId !== undefined) {
170170
let height = this.editor.getLayoutInfo().height;
171-
let matchedNode = this._commentElements.filter(commentNode => commentNode.comment.commentId === commentId);
171+
let matchedNode = this._commentElements.filter(commentNode => commentNode.comment.uniqueIdInThread === commentUniqueId);
172172
if (matchedNode && matchedNode.length) {
173173
const commentThreadCoords = dom.getDomNodePagePosition(this._commentElements[0].domNode);
174174
const commentCoords = dom.getDomNodePagePosition(matchedNode[0].domNode);
@@ -289,7 +289,7 @@ export class ReviewZoneWidget extends ZoneWidget implements ICommentThreadWidget
289289
let commentElementsToDelIndex: number[] = [];
290290
for (let i = 0; i < oldCommentsLen; i++) {
291291
let comment = this._commentElements[i].comment;
292-
let newComment = commentThread.comments ? commentThread.comments.filter(c => c.commentId === comment.commentId) : [];
292+
let newComment = commentThread.comments ? commentThread.comments.filter(c => c.uniqueIdInThread === comment.uniqueIdInThread) : [];
293293

294294
if (newComment.length) {
295295
this._commentElements[i].update(newComment[0]);
@@ -309,7 +309,7 @@ export class ReviewZoneWidget extends ZoneWidget implements ICommentThreadWidget
309309
let newCommentNodeList: CommentNode[] = [];
310310
for (let i = newCommentsLen - 1; i >= 0; i--) {
311311
let currentComment = commentThread.comments![i];
312-
let oldCommentNode = this._commentElements.filter(commentNode => commentNode.comment.commentId === currentComment.commentId);
312+
let oldCommentNode = this._commentElements.filter(commentNode => commentNode.comment.uniqueIdInThread === currentComment.uniqueIdInThread);
313313
if (oldCommentNode.length) {
314314
oldCommentNode[0].update(currentComment);
315315
lastCommentElement = oldCommentNode[0].domNode;
@@ -606,13 +606,13 @@ export class ReviewZoneWidget extends ZoneWidget implements ICommentThreadWidget
606606

607607
this._disposables.add(newCommentNode);
608608
this._disposables.add(newCommentNode.onDidDelete(deletedNode => {
609-
const deletedNodeId = deletedNode.comment.commentId;
610-
const deletedElementIndex = arrays.firstIndex(this._commentElements, commentNode => commentNode.comment.commentId === deletedNodeId);
609+
const deletedNodeId = deletedNode.comment.uniqueIdInThread;
610+
const deletedElementIndex = arrays.firstIndex(this._commentElements, commentNode => commentNode.comment.uniqueIdInThread === deletedNodeId);
611611
if (deletedElementIndex > -1) {
612612
this._commentElements.splice(deletedElementIndex, 1);
613613
}
614614

615-
const deletedCommentIndex = arrays.firstIndex(this._commentThread.comments!, comment => comment.commentId === deletedNodeId);
615+
const deletedCommentIndex = arrays.firstIndex(this._commentThread.comments!, comment => comment.uniqueIdInThread === deletedNodeId);
616616
if (deletedCommentIndex > -1) {
617617
this._commentThread.comments!.splice(deletedCommentIndex, 1);
618618
}

src/vs/workbench/contrib/comments/browser/commentsEditorContribution.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -247,18 +247,18 @@ export class ReviewController implements IEditorContribution {
247247
return editor.getContribution<ReviewController>(ID);
248248
}
249249

250-
public revealCommentThread(threadId: string, commentId: string, fetchOnceIfNotExist: boolean): void {
250+
public revealCommentThread(threadId: string, commentUniqueId: number, fetchOnceIfNotExist: boolean): void {
251251
const commentThreadWidget = this._commentWidgets.filter(widget => widget.commentThread.threadId === threadId);
252252
if (commentThreadWidget.length === 1) {
253-
commentThreadWidget[0].reveal(commentId);
253+
commentThreadWidget[0].reveal(commentUniqueId);
254254
} else if (fetchOnceIfNotExist) {
255255
if (this._computePromise) {
256256
this._computePromise.then(_ => {
257-
this.revealCommentThread(threadId, commentId, false);
257+
this.revealCommentThread(threadId, commentUniqueId, false);
258258
});
259259
} else {
260260
this.beginCompute().then(_ => {
261-
this.revealCommentThread(threadId, commentId, false);
261+
this.revealCommentThread(threadId, commentUniqueId, false);
262262
});
263263
}
264264
}

src/vs/workbench/contrib/comments/browser/commentsPanel.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ export class CommentsPanel extends Panel {
175175
let currentActiveResource = activeEditor ? activeEditor.getResource() : undefined;
176176
if (currentActiveResource && currentActiveResource.toString() === element.resource.toString()) {
177177
const threadToReveal = element instanceof ResourceWithCommentThreads ? element.commentThreads[0].threadId : element.threadId;
178-
const commentToReveal = element instanceof ResourceWithCommentThreads ? element.commentThreads[0].comment.commentId : element.comment.commentId;
178+
const commentToReveal = element instanceof ResourceWithCommentThreads ? element.commentThreads[0].comment.uniqueIdInThread : element.comment.uniqueIdInThread;
179179
const control = this.editorService.activeTextEditorWidget;
180180
if (threadToReveal && isCodeEditor(control)) {
181181
const controller = ReviewController.get(control);
@@ -200,7 +200,7 @@ export class CommentsPanel extends Panel {
200200
const control = editor.getControl();
201201
if (threadToReveal && isCodeEditor(control)) {
202202
const controller = ReviewController.get(control);
203-
controller.revealCommentThread(threadToReveal, commentToReveal.commentId, true);
203+
controller.revealCommentThread(threadToReveal, commentToReveal.uniqueIdInThread, true);
204204
}
205205
}
206206
});

0 commit comments

Comments
 (0)