Skip to content

Commit 8c3188b

Browse files
authored
Fix comments error telemetry (microsoft#236060)
Fixes microsoft#230642
1 parent e4cf87c commit 8c3188b

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

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

+8-2
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ import { IAccessibilityService } from '../../../../platform/accessibility/common
4747
import { URI } from '../../../../base/common/uri.js';
4848
import { IUriIdentityService } from '../../../../platform/uriIdentity/common/uriIdentity.js';
4949
import { threadHasMeaningfulComments } from './commentsModel.js';
50+
import { INotificationService } from '../../../../platform/notification/common/notification.js';
5051

5152
export const ID = 'editor.contrib.review';
5253

@@ -485,7 +486,8 @@ export class CommentController implements IEditorContribution {
485486
@IContextKeyService contextKeyService: IContextKeyService,
486487
@IEditorService private readonly editorService: IEditorService,
487488
@IKeybindingService private readonly keybindingService: IKeybindingService,
488-
@IAccessibilityService private readonly accessibilityService: IAccessibilityService
489+
@IAccessibilityService private readonly accessibilityService: IAccessibilityService,
490+
@INotificationService private readonly notificationService: INotificationService
489491
) {
490492
this._commentInfos = [];
491493
this._commentWidgets = [];
@@ -1168,7 +1170,11 @@ export class CommentController implements IEditorContribution {
11681170
if (!newCommentInfos.length || !this.editor?.hasModel()) {
11691171
this._addInProgress = false;
11701172
if (!newCommentInfos.length) {
1171-
throw new Error(`There are no commenting ranges at the current position (${range ? 'with range' : 'without range'}).`);
1173+
if (range) {
1174+
this.notificationService.error(nls.localize('comments.addCommand.error', "The cursor must be within a commenting range to add a comment."));
1175+
} else {
1176+
this.notificationService.error(nls.localize('comments.addFileCommentCommand.error', "File comments are not allowed on this file."));
1177+
}
11721178
}
11731179
return Promise.resolve();
11741180
}

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

+1-6
Original file line numberDiff line numberDiff line change
@@ -280,12 +280,7 @@ registerAction2(class extends Action2 {
280280

281281
const position = args?.range ? new Range(args.range.startLineNumber, args.range.startLineNumber, args.range.endLineNumber, args.range.endColumn)
282282
: (args?.fileComment ? undefined : activeEditor.getSelection());
283-
const notificationService = accessor.get(INotificationService);
284-
try {
285-
await controller.addOrToggleCommentAtLine(position, undefined);
286-
} catch (e) {
287-
notificationService.error(nls.localize('comments.addCommand.error', "The cursor must be within a commenting range to add a comment"));
288-
}
283+
await controller.addOrToggleCommentAtLine(position, undefined);
289284
}
290285
});
291286

0 commit comments

Comments
 (0)