From 70af91ce981ac2485d24f2255ce6cab8761e1f8f Mon Sep 17 00:00:00 2001 From: Alex Ross Date: Wed, 1 Nov 2023 15:09:00 +0100 Subject: [PATCH] Add comment thread pending comment reconciliation Fixes #196574 --- .../comments/browser/commentsController.ts | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/vs/workbench/contrib/comments/browser/commentsController.ts b/src/vs/workbench/contrib/comments/browser/commentsController.ts index 2eb6c4c38bbce..4e7ca0f1050d2 100644 --- a/src/vs/workbench/contrib/comments/browser/commentsController.ts +++ b/src/vs/workbench/contrib/comments/browser/commentsController.ts @@ -869,8 +869,20 @@ export class CommentController implements IEditorContribution { const matchedZones = this._commentWidgets.filter(zoneWidget => zoneWidget.owner === thread.owner && Range.lift(zoneWidget.commentThread.range)?.equalsRange(thread.range)); if (thread.isReply && matchedZones.length) { this.commentService.removeContinueOnComment({ owner: thread.owner, uri: editorURI, range: thread.range, isReply: true }); - const matchedZone = matchedZones[0]; - matchedZone.setPendingComment(thread.body); + matchedZones[0].setPendingComment(thread.body); + } else if (matchedZones.length) { + this.commentService.removeContinueOnComment({ owner: thread.owner, uri: editorURI, range: thread.range, isReply: false }); + const existingPendingComment = matchedZones[0].getPendingComments().newComment; + // We need to try to reconcile the existing pending comment with the incoming pending comment + let pendingComment: string; + if (!existingPendingComment || thread.body.includes(existingPendingComment)) { + pendingComment = thread.body; + } else if (existingPendingComment.includes(thread.body)) { + pendingComment = existingPendingComment; + } else { + pendingComment = `${existingPendingComment}\n${thread.body}`; + } + matchedZones[0].setPendingComment(pendingComment); } else if (!thread.isReply) { const threadStillAvailable = this.commentService.removeContinueOnComment({ owner: thread.owner, uri: editorURI, range: thread.range, isReply: false }); if (!threadStillAvailable) {