Skip to content

Commit

Permalink
[vscode] support CommentThread state property
Browse files Browse the repository at this point in the history
solves #12231

Contributed on behalf of STMicroelectronics

Signed-off-by: Remi Schnekenburger <rschnekenburger@eclipsesource.com>
  • Loading branch information
rschnekenbu committed Apr 25, 2023
1 parent 17e5269 commit 7d085e2
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 3 deletions.
7 changes: 7 additions & 0 deletions packages/plugin-ext/src/common/plugin-api-rpc-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -686,6 +686,11 @@ export interface Comment {
readonly timestamp?: string;
}

export enum CommentThreadState {
Unresolved = 0,
Resolved = 1
}

export enum CommentThreadCollapsibleState {
/**
* Determines an item is collapsed
Expand Down Expand Up @@ -714,10 +719,12 @@ export interface CommentThread {
comments: Comment[] | undefined;
onDidChangeComments: TheiaEvent<Comment[] | undefined>;
collapsibleState?: CommentThreadCollapsibleState;
state?: CommentThreadState;
input?: CommentInput;
onDidChangeInput: TheiaEvent<CommentInput | undefined>;
onDidChangeRange: TheiaEvent<Range>;
onDidChangeLabel: TheiaEvent<string | undefined>;
onDidChangeState: TheiaEvent<CommentThreadState | undefined>;
onDidChangeCollapsibleState: TheiaEvent<CommentThreadCollapsibleState | undefined>;
isDisposed: boolean;
canReply: boolean;
Expand Down
2 changes: 2 additions & 0 deletions packages/plugin-ext/src/common/plugin-api-rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ import {
CallHierarchyOutgoingCall,
Comment,
CommentOptions,
CommentThreadState,
CommentThreadCollapsibleState,
CommentThread,
CommentThreadChangedEvent,
Expand Down Expand Up @@ -1943,6 +1944,7 @@ export type CommentThreadChanges = Partial<{
contextValue: string,
comments: Comment[],
collapseState: CommentThreadCollapsibleState;
state: CommentThreadState;
canReply: boolean;
}>;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
Comment,
CommentMode,
CommentThread,
CommentThreadState,
CommentThreadCollapsibleState
} from '../../../common/plugin-api-rpc-model';
import { CommentGlyphWidget } from './comment-glyph-widget';
Expand Down Expand Up @@ -97,6 +98,9 @@ export class CommentThreadWidget extends BaseWidget {
commentForm.update();
}
}));
this.toDispose.push(this._commentThread.onDidChangeState(_state => {
this.update();
}));
this.contextMenu = this.menus.getMenu(COMMENT_THREAD_CONTEXT);
this.contextMenu.children.map(node => node instanceof ActionMenuNode && node.when).forEach(exp => {
if (typeof exp === 'string') {
Expand Down Expand Up @@ -231,7 +235,8 @@ export class CommentThreadWidget extends BaseWidget {
if (this._commentThread.comments && this._commentThread.comments.length) {
const onlyUnique = (value: Comment, index: number, self: Comment[]) => self.indexOf(value) === index;
const participantsList = this._commentThread.comments.filter(onlyUnique).map(comment => `@${comment.userName}`).join(', ');
label = `Participants: ${participantsList}`;
const resolutionState = (this._commentThread.state === CommentThreadState.Resolved) ? '(Resolved)' : '(Unresolved)';
label = `Participants: ${participantsList} ${resolutionState}`;
} else {
label = 'Start discussion';
}
Expand Down
19 changes: 18 additions & 1 deletion packages/plugin-ext/src/main/browser/comments/comments-main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
CommentThreadChangedEvent
} from '../../../common/plugin-api-rpc-model';
import { Event, Emitter } from '@theia/core/lib/common/event';
import { CommentThreadCollapsibleState } from '../../../plugin/types-impl';
import { CommentThreadCollapsibleState, CommentThreadState } from '../../../plugin/types-impl';
import {
CommentProviderFeatures,
CommentsExt,
Expand Down Expand Up @@ -124,6 +124,21 @@ export class CommentThreadImpl implements CommentThread, Disposable {
private readonly onDidChangeCollapsibleStateEmitter = new Emitter<CommentThreadCollapsibleState | undefined>();
readonly onDidChangeCollapsibleState = this.onDidChangeCollapsibleStateEmitter.event;

private _state: CommentThreadState | undefined;
get state(): CommentThreadState | undefined {
return this._state;
}

set state(newState: CommentThreadState | undefined) {
if (this._state !== newState) {
this._state = newState;
this.onDidChangeStateEmitter.fire(this._state);
}
}

private readonly onDidChangeStateEmitter = new Emitter<CommentThreadState | undefined>();
readonly onDidChangeState = this.onDidChangeStateEmitter.event;

private readonly onDidChangeCanReplyEmitter = new Emitter<boolean>();
readonly onDidChangeCanReply = this.onDidChangeCanReplyEmitter.event;

Expand Down Expand Up @@ -163,12 +178,14 @@ export class CommentThreadImpl implements CommentThread, Disposable {
if (modified('contextValue')) { this._contextValue = changes.contextValue; }
if (modified('comments')) { this._comments = changes.comments; }
if (modified('collapseState')) { this._collapsibleState = changes.collapseState; }
if (modified('state')) { this._state = changes.state; }
if (modified('canReply')) { this._canReply = changes.canReply!; }
}

dispose(): void {
this._isDisposed = true;
this.onDidChangeCollapsibleStateEmitter.dispose();
this.onDidChangeStateEmitter.dispose();
this.onDidChangeCommentsEmitter.dispose();
this.onDidChangeInputEmitter.dispose();
this.onDidChangeLabelEmitter.dispose();
Expand Down
33 changes: 32 additions & 1 deletion packages/plugin-ext/src/plugin/comments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ import * as theia from '@theia/plugin';
import { RPCProtocol } from '../common/rpc-protocol';
import { CommandRegistryImpl } from './command-registry';
import { UriComponents } from '../common/uri-components';
import { CommentThreadCollapsibleState, URI } from './types-impl';
import { CommentThreadCollapsibleState, CommentThreadState, URI } from './types-impl';
import {
Range,
Comment,
CommentThreadState as CommentThreadStateModel,
CommentThreadCollapsibleState as CommentThreadCollapsibleStateModel,
CommentOptions
} from '../common/plugin-api-rpc-model';
Expand Down Expand Up @@ -185,6 +186,7 @@ type CommentThreadModification = Partial<{
contextValue: string | undefined,
comments: theia.Comment[],
collapsibleState: theia.CommentThreadCollapsibleState
state: theia.CommentThreadState
canReply: boolean;
}>;

Expand Down Expand Up @@ -276,6 +278,20 @@ export class ExtHostCommentThread implements theia.CommentThread, theia.Disposab
this._onDidUpdateCommentThread.fire();
}

private _state?: theia.CommentThreadState;

get state(): theia.CommentThreadState {
return this._state!;
}

set state(newState: theia.CommentThreadState) {
if (this._state !== newState) {
this._state = newState;
this.modifications.state = newState;
this._onDidUpdateCommentThread.fire();
}
}

private localDisposables: Disposable[];

private _isDisposed: boolean;
Expand Down Expand Up @@ -357,6 +373,9 @@ export class ExtHostCommentThread implements theia.CommentThread, theia.Disposab
if (modified('collapsibleState')) {
formattedModifications.collapseState = convertToCollapsibleState(this.collapseState);
}
if (modified('state')) {
formattedModifications.state = convertToState(this._state);
}
if (modified('canReply')) {
formattedModifications.canReply = this.canReply;
}
Expand Down Expand Up @@ -516,3 +535,15 @@ function convertToCollapsibleState(kind: theia.CommentThreadCollapsibleState | u
}
return CommentThreadCollapsibleStateModel.Collapsed;
}

function convertToState(kind: theia.CommentThreadState | undefined): CommentThreadStateModel {
if (kind !== undefined) {
switch (kind) {
case CommentThreadState.Resolved:
return CommentThreadStateModel.Resolved;
case CommentThreadState.Unresolved:
return CommentThreadStateModel.Unresolved;
}
}
return CommentThreadStateModel.Unresolved;
}
2 changes: 2 additions & 0 deletions packages/plugin-ext/src/plugin/plugin-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ import {
WebviewPanelTargetArea,
UIKind,
FileSystemError,
CommentThreadState,
CommentThreadCollapsibleState,
QuickInputButtons,
QuickPickItemKind,
Expand Down Expand Up @@ -1278,6 +1279,7 @@ export function createAPIFactory(
WebviewPanelTargetArea,
UIKind,
FileSystemError,
CommentThreadState,
CommentThreadCollapsibleState,
QuickInputButtons,
CommentMode,
Expand Down
5 changes: 5 additions & 0 deletions packages/plugin-ext/src/plugin/types-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1995,6 +1995,11 @@ export class DocumentSymbol {
}
}

export enum CommentThreadState {
Unresolved = 0,
Resolved = 1
}

export enum CommentThreadCollapsibleState {
Collapsed = 0,
Expanded = 1
Expand Down
13 changes: 13 additions & 0 deletions packages/plugin/src/theia.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12984,6 +12984,11 @@ export module '@theia/plugin' {
*/
label?: string;

/**
* The optional state of a comment thread, which may affect how the comment is displayed.
*/
state?: CommentThreadState;

/**
* Dispose this comment thread.
*
Expand All @@ -12997,6 +13002,14 @@ export module '@theia/plugin' {
canReply: boolean;
}

/**
* The state of a comment thread.
*/
export enum CommentThreadState {
Unresolved = 0,
Resolved = 1
}

/**
* Author information of a {@link Comment comment}
*/
Expand Down

0 comments on commit 7d085e2

Please sign in to comment.