Skip to content

Commit 0dbb1f7

Browse files
Copilotalexr00
andcommitted
Adopt CommentState API proposal for draft comments
Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com>
1 parent 46f2916 commit 0dbb1f7

File tree

3 files changed

+29
-5
lines changed

3 files changed

+29
-5
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"commentingRangeHint",
2121
"commentReactor",
2222
"commentReveal",
23+
"commentState",
2324
"commentThreadApplicability",
2425
"contribAccessibilityHelpContent",
2526
"contribCommentEditorActionsMenu",
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
declare module 'vscode' {
7+
8+
// https://github.com/microsoft/vscode/issues/171166
9+
10+
export enum CommentState {
11+
Published = 0,
12+
Draft = 1
13+
}
14+
15+
export interface Comment {
16+
state?: CommentState;
17+
}
18+
}

src/github/prComment.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,11 @@ abstract class CommentBase implements vscode.Comment {
9797
*/
9898
public label: string | undefined;
9999

100+
/**
101+
* The state of the comment
102+
*/
103+
public state?: vscode.CommentState;
104+
100105
/**
101106
* The list of reactions to the comment
102107
*/
@@ -172,7 +177,7 @@ export class TemporaryComment extends CommentBase {
172177
name: currentUser.specialDisplayName ?? currentUser.login,
173178
iconPath: currentUser.avatarUrl ? vscode.Uri.parse(`${currentUser.avatarUrl}&s=64`) : undefined,
174179
};
175-
this.label = isDraft ? vscode.l10n.t('Pending') : undefined;
180+
this.state = isDraft ? vscode.CommentState.Draft : vscode.CommentState.Published;
176181
this.contextValue = 'temporary,canEdit,canDelete';
177182
this.originalBody = originalComment ? originalComment.rawComment.body : undefined;
178183
this.reactions = originalComment ? originalComment.reactions : undefined;
@@ -248,7 +253,7 @@ export class GHPRComment extends CommentBase {
248253

249254
updateCommentReactions(this, comment.reactions);
250255

251-
this.label = comment.isDraft ? vscode.l10n.t('Pending') : undefined;
256+
this.state = comment.isDraft ? vscode.CommentState.Draft : vscode.CommentState.Published;
252257

253258
const contextValues: string[] = [];
254259
if (comment.canEdit) {
@@ -286,9 +291,9 @@ export class GHPRComment extends CommentBase {
286291
refresh = true;
287292
}
288293

289-
const oldLabel = this.label;
290-
this.label = comment.isDraft ? vscode.l10n.t('Pending') : undefined;
291-
if (this.label !== oldLabel) {
294+
const oldState = this.state;
295+
this.state = comment.isDraft ? vscode.CommentState.Draft : vscode.CommentState.Published;
296+
if (this.state !== oldState) {
292297
refresh = true;
293298
}
294299

0 commit comments

Comments
 (0)