Skip to content

Commit 479feb5

Browse files
author
Rachel Macfarlane
committed
Fixes microsoft#59348, Error in editComment/deleteComment not indicated in UI
1 parent beebc71 commit 479feb5

File tree

4 files changed

+25
-25
lines changed

4 files changed

+25
-25
lines changed

src/vs/workbench/parts/comments/electron-browser/commentNode.ts

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import { isMacintosh } from 'vs/base/common/platform';
2828
import { Selection } from 'vs/editor/common/core/selection';
2929
import { IDialogService } from 'vs/platform/dialogs/common/dialogs';
3030
import { Emitter, Event } from 'vs/base/common/event';
31+
import { INotificationService } from 'vs/platform/notification/common/notification';
3132

3233
const UPDATE_COMMENT_LABEL = nls.localize('label.updateComment', "Update comment");
3334
const UPDATE_IN_PROGRESS_LABEL = nls.localize('label.updatingComment', "Updating comment...");
@@ -62,7 +63,8 @@ export class CommentNode extends Disposable {
6263
private commentService: ICommentService,
6364
private modelService: IModelService,
6465
private modeService: IModeService,
65-
private dialogService: IDialogService
66+
private dialogService: IDialogService,
67+
private notificationService: INotificationService
6668
) {
6769
super();
6870

@@ -150,18 +152,17 @@ export class CommentNode extends Disposable {
150152
this._commentEditContainer.remove();
151153
}
152154

153-
private editComment(): void {
155+
private async editComment(): Promise<void> {
154156
this._updateCommentButton.enabled = false;
155157
this._updateCommentButton.label = UPDATE_IN_PROGRESS_LABEL;
156158

157159
try {
158-
this.commentService.editComment(this.owner, this.resource, this.comment, this._commentEditor.getValue()).then(editedComment => {
159-
this._updateCommentButton.enabled = true;
160-
this._updateCommentButton.label = UPDATE_COMMENT_LABEL;
161-
this._commentEditor.getDomNode().style.outline = '';
162-
this.removeCommentEditor();
163-
this.update(editedComment);
164-
});
160+
const editedComment = await this.commentService.editComment(this.owner, this.resource, this.comment, this._commentEditor.getValue());
161+
this._updateCommentButton.enabled = true;
162+
this._updateCommentButton.label = UPDATE_COMMENT_LABEL;
163+
this._commentEditor.getDomNode().style.outline = '';
164+
this.removeCommentEditor();
165+
this.update(editedComment);
165166
} catch (e) {
166167
this._updateCommentButton.enabled = true;
167168
this._updateCommentButton.label = UPDATE_COMMENT_LABEL;
@@ -180,13 +181,16 @@ export class CommentNode extends Disposable {
180181
message: nls.localize('confirmDelete', "Delete comment?"),
181182
type: 'question',
182183
primaryButton: nls.localize('label.delete', "Delete")
183-
}).then(result => {
184+
}).then(async result => {
184185
if (result.confirmed) {
185-
this.commentService.deleteComment(this.owner, this.resource, this.comment).then((didDelete) => {
186+
try {
187+
const didDelete = await this.commentService.deleteComment(this.owner, this.resource, this.comment);
186188
if (didDelete) {
187189
this._onDidDelete.fire(this);
188190
}
189-
});
191+
} catch (e) {
192+
this.notificationService.error(nls.localize('commentDeletionError', "Deleting the comment failed: {0}.", e.message));
193+
}
190194
}
191195
});
192196
});

src/vs/workbench/parts/comments/electron-browser/commentService.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
'use strict';
77

8-
import * as nls from 'vs/nls';
98
import { CommentThread, DocumentCommentProvider, CommentThreadChangedEvent, CommentInfo, Comment } from 'vs/editor/common/modes';
109
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
1110
import { Event, Emitter } from 'vs/base/common/event';
@@ -14,7 +13,6 @@ import { URI } from 'vs/base/common/uri';
1413
import { Range } from 'vs/editor/common/core/range';
1514
import { keys } from 'vs/base/common/map';
1615
import { CancellationToken } from 'vs/base/common/cancellation';
17-
import { INotificationService } from 'vs/platform/notification/common/notification';
1816

1917
export const ICommentService = createDecorator<ICommentService>('commentService');
2018

@@ -68,7 +66,7 @@ export class CommentService extends Disposable implements ICommentService {
6866

6967
private _commentProviders = new Map<number, DocumentCommentProvider>();
7068

71-
constructor(@INotificationService private notificationService: INotificationService) {
69+
constructor() {
7270
super();
7371
}
7472

@@ -132,12 +130,7 @@ export class CommentService extends Disposable implements ICommentService {
132130
const commentProvider = this._commentProviders.get(owner);
133131

134132
if (commentProvider) {
135-
try {
136-
return commentProvider.deleteComment(resource, comment, CancellationToken.None).then(() => true);
137-
} catch (e) {
138-
this.notificationService.error(nls.localize('commentDeletionError', "Deleting the comment failed: {0}.", e.message));
139-
return Promise.resolve(false);
140-
}
133+
return commentProvider.deleteComment(resource, comment, CancellationToken.None).then(() => true);
141134
}
142135

143136
return Promise.resolve(false);

src/vs/workbench/parts/comments/electron-browser/commentThreadWidget.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import { IMarginData } from 'vs/editor/browser/controller/mouseTarget';
3939
import { ModelDecorationOptions } from 'vs/editor/common/model/textModel';
4040
import { CommentNode } from 'vs/workbench/parts/comments/electron-browser/commentNode';
4141
import { IDialogService } from 'vs/platform/dialogs/common/dialogs';
42+
import { INotificationService } from 'vs/platform/notification/common/notification';
4243

4344
export const COMMENTEDITOR_DECORATION_KEY = 'commenteditordecoration';
4445
const COLLAPSE_ACTION_CLASS = 'expand-review-action octicon octicon-x';
@@ -85,6 +86,7 @@ export class ReviewZoneWidget extends ZoneWidget {
8586
private commentService: ICommentService,
8687
private openerService: IOpenerService,
8788
private dialogService: IDialogService,
89+
private notificationService: INotificationService,
8890
editor: ICodeEditor,
8991
owner: number,
9092
commentThread: modes.CommentThread,
@@ -352,7 +354,8 @@ export class ReviewZoneWidget extends ZoneWidget {
352354
this.commentService,
353355
this.modelService,
354356
this.modeService,
355-
this.dialogService);
357+
this.dialogService,
358+
this.notificationService);
356359

357360
this._disposables.push(newCommentNode);
358361
this._disposables.push(newCommentNode.onDidDelete(deletedNode => {

src/vs/workbench/parts/comments/electron-browser/commentsEditorContribution.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ export class ReviewController implements IEditorContribution {
358358
}
359359
});
360360
added.forEach(thread => {
361-
let zoneWidget = new ReviewZoneWidget(this.instantiationService, this.modeService, this.modelService, this.themeService, this.commentService, this.openerService, this.dialogService, this.editor, e.owner, thread, {});
361+
let zoneWidget = new ReviewZoneWidget(this.instantiationService, this.modeService, this.modelService, this.themeService, this.commentService, this.openerService, this.dialogService, this.notificationService, this.editor, e.owner, thread, {});
362362
zoneWidget.display(thread.range.startLineNumber, this._commentingRangeDecorator.commentsOptions);
363363
this._commentWidgets.push(zoneWidget);
364364
this._commentInfos.filter(info => info.owner === e.owner)[0].threads.push(thread);
@@ -380,7 +380,7 @@ export class ReviewController implements IEditorContribution {
380380
// add new comment
381381
this._reviewPanelVisible.set(true);
382382
const { replyCommand, ownerId } = newCommentInfo;
383-
this._newCommentWidget = new ReviewZoneWidget(this.instantiationService, this.modeService, this.modelService, this.themeService, this.commentService, this.openerService, this.dialogService, this.editor, ownerId, {
383+
this._newCommentWidget = new ReviewZoneWidget(this.instantiationService, this.modeService, this.modelService, this.themeService, this.commentService, this.openerService, this.dialogService, this.notificationService, this.editor, ownerId, {
384384
threadId: null,
385385
resource: null,
386386
comments: [],
@@ -507,7 +507,7 @@ export class ReviewController implements IEditorContribution {
507507

508508
this._commentInfos.forEach(info => {
509509
info.threads.forEach(thread => {
510-
let zoneWidget = new ReviewZoneWidget(this.instantiationService, this.modeService, this.modelService, this.themeService, this.commentService, this.openerService, this.dialogService, this.editor, info.owner, thread, {});
510+
let zoneWidget = new ReviewZoneWidget(this.instantiationService, this.modeService, this.modelService, this.themeService, this.commentService, this.openerService, this.dialogService, this.notificationService, this.editor, info.owner, thread, {});
511511
zoneWidget.display(thread.range.startLineNumber, this._commentingRangeDecorator.commentsOptions);
512512
this._commentWidgets.push(zoneWidget);
513513
});

0 commit comments

Comments
 (0)