Skip to content

Commit

Permalink
Comment detail should be timestamp
Browse files Browse the repository at this point in the history
Part of #139524
  • Loading branch information
alexr00 committed Jan 21, 2022
1 parent 12c80bb commit 8b27820
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 37 deletions.
2 changes: 1 addition & 1 deletion src/vs/editor/common/languages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1716,7 +1716,7 @@ export interface Comment {
readonly commentReactions?: CommentReaction[];
readonly label?: string;
readonly mode?: CommentMode;
readonly detail?: Date | string;
readonly timestamp?: Date;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/vs/workbench/api/browser/mainThreadComments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ export class MainThreadCommentThread implements modes.CommentThread {
userName: comment.userName,
commentReactions: comment.commentReactions,
contextValue: comment.contextValue,
detail: comment.detail ? <Date | string>revive<Date | string>(comment.detail) : undefined,
timestamp: comment.timestamp ? <Date>revive<Date>(comment.timestamp) : undefined,
label: comment.label,
mode: comment.mode,
userIconPath: comment.userIconPath
Expand Down
4 changes: 2 additions & 2 deletions src/vs/workbench/api/common/extHost.protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,9 @@ export interface CommentChanges {
readonly commentReactions?: modes.CommentReaction[];
readonly label?: string;
readonly mode?: modes.CommentMode;
readonly detail?: {
readonly timestamp?: {
$mid: MarshalledId.Date
} | string;
};
}

export type CommentThreadChanges = Partial<{
Expand Down
14 changes: 6 additions & 8 deletions src/vs/workbench/api/common/extHostComments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -618,18 +618,16 @@ export function createExtHostComments(mainContext: IMainContext, commands: ExtHo

const iconPath = vscodeComment.author && vscodeComment.author.iconPath ? vscodeComment.author.iconPath.toString() : undefined;

if (vscodeComment.detail) {
if (vscodeComment.timestamp) {
checkProposedApiEnabled(thread.extensionDescription, 'commentTimestamp');
}

let detail: { $mid: MarshalledId.Date, source: any } | string | undefined;
if (vscodeComment.detail && (typeof vscodeComment.detail !== 'string')) {
detail = {
source: vscodeComment.detail,
let timestamp: { $mid: MarshalledId.Date, source: any } | undefined;
if (vscodeComment.timestamp) {
timestamp = {
source: vscodeComment.timestamp,
$mid: MarshalledId.Date
};
} else {
detail = vscodeComment.detail;
}

return {
Expand All @@ -641,7 +639,7 @@ export function createExtHostComments(mainContext: IMainContext, commands: ExtHo
userIconPath: iconPath,
label: vscodeComment.label,
commentReactions: vscodeComment.reactions ? vscodeComment.reactions.map(reaction => convertToReaction(reaction)) : undefined,
detail: detail
timestamp
};
}

Expand Down
37 changes: 16 additions & 21 deletions src/vs/workbench/contrib/comments/browser/commentNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ export class CommentNode extends Disposable {
private _commentEditorDisposables: IDisposable[] = [];
private _commentEditorModel: ITextModel | null = null;
private _isPendingLabel!: HTMLElement;
private _detail: HTMLElement | undefined;
private _timestamp: TimestampWidget | undefined;
private _timestamp: HTMLElement | undefined;
private _timestampWidget: TimestampWidget | undefined;
private _contextKeyService: IContextKeyService;
private _commentContextValue: IContextKey<string>;

Expand Down Expand Up @@ -126,29 +126,24 @@ export class CommentNode extends Disposable {
return this._onDidClick.event;
}

private createDetail(container: HTMLElement) {
this._detail = dom.append(container, dom.$('span.detail'));
this.updateDetail(this.comment.detail);
private createTimestamp(container: HTMLElement) {
this._timestamp = dom.append(container, dom.$('span.timestamp-container'));
this.updateTimestamp(this.comment.timestamp);
}

private updateDetail(detail?: Date | string) {
if (!this._detail) {
private updateTimestamp(timestamp?: Date) {
if (!this._timestamp) {
return;
}

if (!detail) {
this._timestamp?.dispose();
this._detail.innerText = '';
} else if (typeof detail === 'string') {
this._timestamp?.dispose();
this._detail.innerText = detail;
if (!timestamp) {
this._timestampWidget?.dispose();
} else {
this._detail.innerText = '';
if (!this._timestamp) {
this._timestamp = new TimestampWidget(this.configurationService, this._detail, detail);
this._register(this._timestamp);
if (!this._timestampWidget) {
this._timestampWidget = new TimestampWidget(this.configurationService, this._timestamp, timestamp);
this._register(this._timestampWidget);
} else {
this._timestamp.setTimestamp(detail);
this._timestampWidget.setTimestamp(timestamp);
}
}
}
Expand All @@ -157,7 +152,7 @@ export class CommentNode extends Disposable {
const header = dom.append(commentDetailsContainer, dom.$(`div.comment-title.${MOUSE_CURSOR_TEXT_CSS_CLASS_NAME}`));
const author = dom.append(header, dom.$('strong.author'));
author.innerText = this.comment.userName;
this.createDetail(header);
this.createTimestamp(header);
this._isPendingLabel = dom.append(header, dom.$('span.isPending'));

if (this.comment.label) {
Expand Down Expand Up @@ -549,8 +544,8 @@ export class CommentNode extends Disposable {
this._commentContextValue.reset();
}

if (this.comment.detail) {
this.updateDetail(this.comment.detail);
if (this.comment.timestamp) {
this.updateTimestamp(this.comment.timestamp);
}
}

Expand Down
7 changes: 3 additions & 4 deletions src/vscode-dts/vscode.proposed.commentTimestamp.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@
declare module 'vscode' {
export interface Comment {
/**
* An optional detail that will be displayed less prominently than the `author`.
* If a date is provided, then the date will be formatted according to the user's
* locale and settings.
* An optional timestamp that will be displayed in comments.
* The date will be formatted according to the user's locale and settings.
*/
detail?: Date | string
timestamp?: Date;
}
}

0 comments on commit 8b27820

Please sign in to comment.