Skip to content

Commit cda402b

Browse files
Copilotalexr00
andauthored
Adopt comment draft state extension API proposal (#8135)
* Initial plan * Adopt comment draft state extension API proposal - Created vscode.proposed.commentState.d.ts with CommentState enum - Added commentState to enabledApiProposals in package.json - Updated CommentBase, TemporaryComment, and GHPRComment to use new state property - Comments now have state set to Draft or Published based on isDraft flag Co-authored-by: alexr00 <[email protected]> * clean up --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: alexr00 <[email protected]>
1 parent 889edb3 commit cda402b

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
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+
"commentsDraftState",
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 & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,11 @@ abstract class CommentBase implements vscode.Comment {
107107
*/
108108
public contextValue: string;
109109

110+
/**
111+
* The state of the comment (Published or Draft)
112+
*/
113+
public state?: vscode.CommentState;
114+
110115
constructor(
111116
parent: GHPRCommentThread,
112117
) {
@@ -173,6 +178,7 @@ export class TemporaryComment extends CommentBase {
173178
iconPath: currentUser.avatarUrl ? vscode.Uri.parse(`${currentUser.avatarUrl}&s=64`) : undefined,
174179
};
175180
this.label = isDraft ? vscode.l10n.t('Pending') : undefined;
181+
this.state = isDraft ? vscode.CommentState.Draft : vscode.CommentState.Published;
176182
this.contextValue = 'temporary,canEdit,canDelete';
177183
this.originalBody = originalComment ? originalComment.rawComment.body : undefined;
178184
this.reactions = originalComment ? originalComment.reactions : undefined;
@@ -249,6 +255,7 @@ export class GHPRComment extends CommentBase {
249255
updateCommentReactions(this, comment.reactions);
250256

251257
this.label = comment.isDraft ? vscode.l10n.t('Pending') : undefined;
258+
this.state = comment.isDraft ? vscode.CommentState.Draft : vscode.CommentState.Published;
252259

253260
const contextValues: string[] = [];
254261
if (comment.canEdit) {
@@ -288,7 +295,9 @@ export class GHPRComment extends CommentBase {
288295

289296
const oldLabel = this.label;
290297
this.label = comment.isDraft ? vscode.l10n.t('Pending') : undefined;
291-
if (this.label !== oldLabel) {
298+
const newState = comment.isDraft ? vscode.CommentState.Draft : vscode.CommentState.Published;
299+
if (this.label !== oldLabel || this.state !== newState) {
300+
this.state = newState;
292301
refresh = true;
293302
}
294303

0 commit comments

Comments
 (0)