Skip to content

Commit

Permalink
Allow individual comments to be marked as draft (#173305)
Browse files Browse the repository at this point in the history
* Allow individual comments to be marked as draft

This is a proposal for #171166.

* Remove `hasDraftComments` from `CommentThread`

* Rename `CommentVisibility` to `CommentState`

* Rename `CommentVisibility` to `CommentState`

* Add api proposal check

---------

Co-authored-by: Alex Ross <[email protected]>
  • Loading branch information
hermannloose and alexr00 authored Mar 28, 2023
1 parent 0a3470a commit de3b0db
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 2 deletions.
8 changes: 8 additions & 0 deletions src/vs/editor/common/languages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1658,6 +1658,14 @@ export enum CommentMode {
Preview = 1
}

/**
* @internal
*/
export enum CommentState {
Published = 0,
Draft = 1
}

/**
* @internal
*/
Expand Down
1 change: 1 addition & 0 deletions src/vs/workbench/api/common/extHost.api.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1285,6 +1285,7 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I
ColorPresentation: extHostTypes.ColorPresentation,
ColorThemeKind: extHostTypes.ColorThemeKind,
CommentMode: extHostTypes.CommentMode,
CommentState: extHostTypes.CommentState,
CommentThreadCollapsibleState: extHostTypes.CommentThreadCollapsibleState,
CommentThreadState: extHostTypes.CommentThreadState,
CompletionItem: extHostTypes.CompletionItem,
Expand Down
1 change: 1 addition & 0 deletions src/vs/workbench/api/common/extHost.protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ export interface CommentChanges {
readonly commentReactions?: languages.CommentReaction[];
readonly label?: string;
readonly mode?: languages.CommentMode;
readonly state?: languages.CommentState;
readonly timestamp?: string;
}

Expand Down
9 changes: 7 additions & 2 deletions src/vs/workbench/api/common/extHostComments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ export function createExtHostComments(mainContext: IMainContext, commands: ExtHo
}
if (modified('comments')) {
formattedModifications.comments =
this._comments.map(cmt => convertToDTOComment(this, cmt, this._commentsMap));
this._comments.map(cmt => convertToDTOComment(this, cmt, this._commentsMap, this.extensionDescription));
}
if (modified('collapsibleState')) {
formattedModifications.collapseState = convertToCollapsibleState(this._collapseState);
Expand Down Expand Up @@ -666,13 +666,17 @@ export function createExtHostComments(mainContext: IMainContext, commands: ExtHo
}
}

function convertToDTOComment(thread: ExtHostCommentThread, vscodeComment: vscode.Comment, commentsMap: Map<vscode.Comment, number>): CommentChanges {
function convertToDTOComment(thread: ExtHostCommentThread, vscodeComment: vscode.Comment, commentsMap: Map<vscode.Comment, number>, extension: IExtensionDescription): CommentChanges {
let commentUniqueId = commentsMap.get(vscodeComment)!;
if (!commentUniqueId) {
commentUniqueId = ++thread.commentHandle;
commentsMap.set(vscodeComment, commentUniqueId);
}

if (vscodeComment.state !== undefined) {
checkProposedApiEnabled(extension, 'commentsDraftState');
}

return {
mode: vscodeComment.mode,
contextValue: vscodeComment.contextValue,
Expand All @@ -682,6 +686,7 @@ export function createExtHostComments(mainContext: IMainContext, commands: ExtHo
userIconPath: vscodeComment.author.iconPath,
label: vscodeComment.label,
commentReactions: vscodeComment.reactions ? vscodeComment.reactions.map(reaction => convertToReaction(reaction)) : undefined,
state: vscodeComment.state,
timestamp: vscodeComment.timestamp?.toJSON()
};
}
Expand Down
5 changes: 5 additions & 0 deletions src/vs/workbench/api/common/extHostTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3056,6 +3056,11 @@ export enum CommentMode {
Preview = 1
}

export enum CommentState {
Published = 0,
Draft = 1
}

export enum CommentThreadState {
Unresolved = 0,
Resolved = 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
export const allApiProposals = Object.freeze({
authSession: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.authSession.d.ts',
codiconDecoration: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.codiconDecoration.d.ts',
commentsDraftState: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.commentsDraftState.d.ts',
contribCommentEditorActionsMenu: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.contribCommentEditorActionsMenu.d.ts',
contribCommentPeekContext: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.contribCommentPeekContext.d.ts',
contribCommentThreadAdditionalMenu: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.contribCommentThreadAdditionalMenu.d.ts',
Expand Down
18 changes: 18 additions & 0 deletions src/vscode-dts/vscode.proposed.commentsDraftState.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

declare module 'vscode' {

// https://github.com/microsoft/vscode/issues/171166

export enum CommentState {
Published = 0,
Draft = 1
}

export interface Comment {
state?: CommentState;
}
}

0 comments on commit de3b0db

Please sign in to comment.