Skip to content

Commit

Permalink
Respond to API feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
alexr00 committed Jan 7, 2022
1 parent 4539881 commit 7e586e7
Show file tree
Hide file tree
Showing 10 changed files with 120 additions and 42 deletions.
5 changes: 5 additions & 0 deletions remote/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,11 @@ data-uri-to-buffer@3:
resolved "https://registry.yarnpkg.com/data-uri-to-buffer/-/data-uri-to-buffer-3.0.1.tgz#594b8973938c5bc2c33046535785341abc4f3636"
integrity sha512-WboRycPNsVw3B3TL559F7kuBUM4d8CgMEvk6xEJlOp7OBPjt6G7z8WMWlD2rOFZLk6OYfFIUGsCOWzcQH9K2og==

dayjs@^1.10.7:
version "1.10.7"
resolved "https://registry.yarnpkg.com/dayjs/-/dayjs-1.10.7.tgz#2cf5f91add28116748440866a0a1d26f3a6ce468"
integrity sha512-P6twpd70BcPK34K26uJ1KT3wlhpuOAPoMwJzpsIWUxHZ7wpmbdZL/hQqBDfz7hGurYSa5PhzdhDHtt319hL3ig==

debug@3.1.0, debug@^3.1.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/debug/-/debug-3.1.0.tgz#5bb5a0672628b64149566ba16819e61518c67261"
Expand Down
2 changes: 2 additions & 0 deletions src/vs/base/common/marshalling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export const enum MarshalledId {
TimelineActionContext,
NotebookCellActionContext,
TestItemContext,
Date,
}

export interface MarshalledObject {
Expand Down Expand Up @@ -68,6 +69,7 @@ export function revive<T = any>(obj: any, depth = 0): Revived<T> {
switch ((<MarshalledObject>obj).$mid) {
case MarshalledId.Uri: return <any>URI.revive(obj);
case MarshalledId.Regexp: return <any>new RegExp(obj.source, obj.flags);
case MarshalledId.Date: return <any>new Date(obj.source);
}

if (
Expand Down
11 changes: 1 addition & 10 deletions src/vs/editor/common/languages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1663,15 +1663,6 @@ export enum CommentMode {
Preview = 1
}

/**
* @internal
*/
export interface Timestamp {
date: Date;
useRelativeTime?: boolean;
label?: string;
}

/**
* @internal
*/
Expand All @@ -1684,7 +1675,7 @@ export interface Comment {
readonly commentReactions?: CommentReaction[];
readonly label?: string;
readonly mode?: CommentMode;
readonly timestamp?: Timestamp;
readonly detail?: Date | string;
}

/**
Expand Down
22 changes: 19 additions & 3 deletions src/vs/workbench/api/browser/mainThreadComments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ import { Registry } from 'vs/platform/registry/common/platform';
import { extHostNamedCustomer } from 'vs/workbench/api/common/extHostCustomers';
import { ICommentInfo, ICommentService } from 'vs/workbench/contrib/comments/browser/commentService';
import { CommentsPanel } from 'vs/workbench/contrib/comments/browser/commentsView';
import { CommentProviderFeatures, ExtHostCommentsShape, ExtHostContext, IExtHostContext, MainContext, MainThreadCommentsShape, CommentThreadChanges } from '../common/extHost.protocol';
import { CommentProviderFeatures, ExtHostCommentsShape, ExtHostContext, IExtHostContext, MainContext, MainThreadCommentsShape, CommentThreadChanges, CommentChanges } from '../common/extHost.protocol';
import { COMMENTS_VIEW_ID, COMMENTS_VIEW_TITLE } from 'vs/workbench/contrib/comments/browser/commentsTreeViewer';
import { ViewContainer, IViewContainersRegistry, Extensions as ViewExtensions, ViewContainerLocation, IViewsRegistry, IViewsService, IViewDescriptorService } from 'vs/workbench/common/views';
import { SyncDescriptor } from 'vs/platform/instantiation/common/descriptors';
import { ViewPaneContainer } from 'vs/workbench/browser/parts/views/viewPaneContainer';
import { Codicon } from 'vs/base/common/codicons';
import { registerIcon } from 'vs/platform/theme/common/iconRegistry';
import { localize } from 'vs/nls';
import { MarshalledId } from 'vs/base/common/marshalling';
import { MarshalledId, revive } from 'vs/base/common/marshalling';


export class MainThreadCommentThread implements modes.CommentThread {
Expand Down Expand Up @@ -139,11 +139,27 @@ export class MainThreadCommentThread implements modes.CommentThread {
if (modified('range')) { this._range = changes.range!; }
if (modified('label')) { this._label = changes.label; }
if (modified('contextValue')) { this._contextValue = changes.contextValue === null ? undefined : changes.contextValue; }
if (modified('comments')) { this._comments = changes.comments; }
if (modified('comments')) { this._comments = this.commentsFromCommentChanges(changes.comments); }
if (modified('collapseState')) { this._collapsibleState = changes.collapseState; }
if (modified('canReply')) { this.canReply = changes.canReply!; }
}

private commentsFromCommentChanges(comments?: CommentChanges[]): modes.Comment[] | undefined {
return comments?.map(comment => {
return {
body: comment.body,
uniqueIdInThread: comment.uniqueIdInThread,
userName: comment.userName,
commentReactions: comment.commentReactions,
contextValue: comment.contextValue,
detail: comment.detail ? <Date | string>revive<Date | string>(comment.detail) : undefined,
label: comment.label,
mode: comment.mode,
userIconPath: comment.userIconPath
};
});
}

dispose() {
this._isDisposed = true;
this._onDidChangeCollasibleState.dispose();
Expand Down
18 changes: 16 additions & 2 deletions src/vs/workbench/api/common/extHost.protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { SerializedError } from 'vs/base/common/errors';
import { IRelativePattern } from 'vs/base/common/glob';
import { IMarkdownString } from 'vs/base/common/htmlContent';
import { IDisposable } from 'vs/base/common/lifecycle';
import { revive } from 'vs/base/common/marshalling';
import { MarshalledId, revive } from 'vs/base/common/marshalling';
import * as performance from 'vs/base/common/performance';
import Severity from 'vs/base/common/severity';
import { Dto } from 'vs/base/common/types';
Expand Down Expand Up @@ -160,11 +160,25 @@ export interface CommentProviderFeatures {
options?: modes.CommentOptions;
}

export interface CommentChanges {
readonly uniqueIdInThread: number;
readonly body: IMarkdownString;
readonly userName: string;
readonly userIconPath?: string;
readonly contextValue?: string;
readonly commentReactions?: modes.CommentReaction[];
readonly label?: string;
readonly mode?: modes.CommentMode;
readonly detail?: {
$mid: MarshalledId.Date
} | string;
}

export type CommentThreadChanges = Partial<{
range: IRange,
label: string,
contextValue: string | null,
comments: modes.Comment[],
comments: CommentChanges[],
collapseState: modes.CommentThreadCollapsibleState;
canReply: boolean;
}>;
Expand Down
20 changes: 15 additions & 5 deletions src/vs/workbench/api/common/extHostComments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import * as extHostTypeConverter from 'vs/workbench/api/common/extHostTypeConver
import * as types from 'vs/workbench/api/common/extHostTypes';
import { checkProposedApiEnabled } from 'vs/workbench/services/extensions/common/extensions';
import type * as vscode from 'vscode';
import { ExtHostCommentsShape, IMainContext, MainContext, CommentThreadChanges } from './extHost.protocol';
import { ExtHostCommentsShape, IMainContext, MainContext, CommentThreadChanges, CommentChanges } from './extHost.protocol';
import { ExtHostCommands } from './extHostCommands';

type ProviderHandle = number;
Expand Down Expand Up @@ -434,7 +434,7 @@ export function createExtHostComments(mainContext: IMainContext, commands: ExtHo
}
if (modified('comments')) {
formattedModifications.comments =
this._comments.map(cmt => convertToModeComment(this, cmt, this._commentsMap));
this._comments.map(cmt => convertToDTOComment(this, cmt, this._commentsMap));
}
if (modified('collapsibleState')) {
formattedModifications.collapseState = convertToCollapsibleState(this._collapseState);
Expand Down Expand Up @@ -609,7 +609,7 @@ export function createExtHostComments(mainContext: IMainContext, commands: ExtHo
}
}

function convertToModeComment(thread: ExtHostCommentThread, vscodeComment: vscode.Comment, commentsMap: Map<vscode.Comment, number>): modes.Comment {
function convertToDTOComment(thread: ExtHostCommentThread, vscodeComment: vscode.Comment, commentsMap: Map<vscode.Comment, number>): CommentChanges {
let commentUniqueId = commentsMap.get(vscodeComment)!;
if (!commentUniqueId) {
commentUniqueId = ++thread.commentHandle;
Expand All @@ -618,10 +618,20 @@ export function createExtHostComments(mainContext: IMainContext, commands: ExtHo

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

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

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

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

Expand Down
39 changes: 34 additions & 5 deletions src/vs/workbench/contrib/comments/browser/commentNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import { DropdownMenuActionViewItem } from 'vs/base/browser/ui/dropdown/dropdown
import { Codicon } from 'vs/base/common/codicons';
import { MarshalledId } from 'vs/base/common/marshalling';
import { TimestampWidget } from 'vs/workbench/contrib/comments/browser/timestamp';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';

export class CommentNode extends Disposable {
private _domNode: HTMLElement;
Expand All @@ -54,6 +55,7 @@ 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 _contextKeyService: IContextKeyService;
private _commentContextValue: IContextKey<string>;
Expand Down Expand Up @@ -85,7 +87,8 @@ export class CommentNode extends Disposable {
@ILanguageService private languageService: ILanguageService,
@INotificationService private notificationService: INotificationService,
@IContextMenuService private contextMenuService: IContextMenuService,
@IContextKeyService contextKeyService: IContextKeyService
@IContextKeyService contextKeyService: IContextKeyService,
@IConfigurationService private configurationService: IConfigurationService
) {
super();

Expand Down Expand Up @@ -123,12 +126,38 @@ 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 updateDetail(detail?: Date | string) {
if (!this._detail) {
return;
}

if (!detail) {
this._timestamp?.dispose();
this._detail.innerText = '';
} else if (typeof detail === 'string') {
this._timestamp?.dispose();
this._detail.innerText = detail;
} else {
this._detail.innerText = '';
if (!this._timestamp) {
this._timestamp = new TimestampWidget(this.configurationService, this._detail, detail);
this._register(this._timestamp);
} else {
this._timestamp.setTimestamp(detail);
}
}
}

private createHeader(commentDetailsContainer: HTMLElement): void {
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._timestamp = new TimestampWidget(header, this.comment.timestamp);
this._register(this._timestamp);
this.createDetail(header);
this._isPendingLabel = dom.append(header, dom.$('span.isPending'));

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

if (this.comment.timestamp) {
this._timestamp?.setTimestamp(this.comment.timestamp);
if (this.comment.detail) {
this.updateDetail(this.comment.detail);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ Registry.as<IConfigurationRegistry>(ConfigurationExtensions.Configuration).regis
default: 'openOnSessionStartWithComments',
description: nls.localize('openComments', "Controls when the comments panel should open."),
restricted: false
},
'comments.useRelativeTime': {
type: 'boolean',
default: true,
description: nls.localize('useRelativeTime', "Determines if relative time will be used in comment timestamps (ex. '1 day ago').")

}
}
});
Expand Down
33 changes: 21 additions & 12 deletions src/vs/workbench/contrib/comments/browser/timestamp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@

import * as dom from 'vs/base/browser/dom';
import { Disposable } from 'vs/base/common/lifecycle';
import { Timestamp } from 'vs/editor/common/modes';
import * as dayjs from 'dayjs';
import * as relativeTime from 'dayjs/plugin/relativeTime';
import * as updateLocale from 'dayjs/plugin/updateLocale';
import * as localizedFormat from 'dayjs/plugin/localizedFormat';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';

const USE_RELATIVE_TIME_CONFIGURATION = 'comments.useRelativeTime';

dayjs.extend(relativeTime, {
thresholds: [
Expand Down Expand Up @@ -52,34 +54,41 @@ dayjs.extend(localizedFormat);

export class TimestampWidget extends Disposable {
private _date: HTMLElement;
private _timestamp: Timestamp | undefined;
private _timestamp: Date | undefined;
private _useRelativeTime: boolean;

constructor(container: HTMLElement, timeStamp?: Timestamp) {
constructor(private configurationService: IConfigurationService, container: HTMLElement, timeStamp?: Date) {
super();
this._date = dom.append(container, dom.$('span.timestamp'));
this._useRelativeTime = this.useRelativeTimeSetting;
this.setTimestamp(timeStamp);
}

public async setTimestamp(timestamp: Timestamp | undefined) {
if ((timestamp?.date !== this._timestamp?.date) || (timestamp?.useRelativeTime !== this._timestamp?.useRelativeTime)) {
private get useRelativeTimeSetting(): boolean {
return this.configurationService.getValue<boolean>(USE_RELATIVE_TIME_CONFIGURATION);
}

public async setTimestamp(timestamp: Date | undefined) {
if ((timestamp !== this._timestamp) || (this.useRelativeTimeSetting !== this._useRelativeTime)) {
this.updateDate(timestamp);
}
this._timestamp = timestamp;
this._useRelativeTime = this.useRelativeTimeSetting;
}

private updateDate(timestamp?: Timestamp) {
private updateDate(timestamp?: Date) {
if (!timestamp) {
this._date.textContent = '';
} else if ((timestamp.date !== this._timestamp?.date)
|| (timestamp.useRelativeTime !== this._timestamp.useRelativeTime)) {
} else if ((timestamp !== this._timestamp)
|| (this.useRelativeTimeSetting !== this._useRelativeTime)) {

let textContent: string;
let tooltip: string | undefined;
if (timestamp.useRelativeTime) {
textContent = this.getRelative(timestamp.date);
tooltip = timestamp.label ?? this.getDateString(timestamp.date);
if (this.useRelativeTimeSetting) {
textContent = this.getRelative(timestamp);
tooltip = this.getDateString(timestamp);
} else {
textContent = timestamp.label ?? this.getDateString(timestamp.date);
textContent = this.getDateString(timestamp);
}

this._date.textContent = textContent;
Expand Down
6 changes: 1 addition & 5 deletions src/vscode-dts/vscode.proposed.commentTimestamp.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@

declare module 'vscode' {
export interface Comment {
timestamp?: {
date: Date,
label?: string,
useRelativeTime?: boolean
}
detail?: Date | string
}
}

0 comments on commit 7e586e7

Please sign in to comment.