diff --git a/src/git/models/pullRequest.ts b/src/git/models/pullRequest.ts index 42bd686..3105e98 100644 --- a/src/git/models/pullRequest.ts +++ b/src/git/models/pullRequest.ts @@ -24,6 +24,32 @@ export interface PullRequestShape extends IssueOrPullRequest { readonly mergedDate?: Date; } +export function toPullRequestShape(value: PullRequest): PullRequestShape { + const shape: PullRequestShape = { + type: value.type, + provider: { + id: value.provider.id, + name: value.provider.name, + domain: value.provider.domain, + icon: value.provider.icon, + }, + id: value.id, + title: value.title, + url: value.url, + date: value.date, + closedDate: value.closedDate, + closed: value.closed, + author: { + name: value.author.name, + avatarUrl: value.author.avatarUrl, + url: value.author.url, + }, + state: value.state, + mergedDate: value.mergedDate, + }; + return shape; +} + export class PullRequest implements PullRequestShape { static is(pr: any): pr is PullRequest { return pr instanceof PullRequest; diff --git a/src/system/serialize.ts b/src/system/serialize.ts index f116d5f..d40cac1 100644 --- a/src/system/serialize.ts +++ b/src/system/serialize.ts @@ -9,9 +9,19 @@ export type Serialized = T extends Function : T; export function serialize(obj: T): Serialized { - function replacer(this: any, key: string, value: unknown) { - const original = this[key]; - return original instanceof Date ? original.getTime() : value; + try { + function replacer(this: any, key: string, value: unknown) { + if (value instanceof Date) return value.getTime(); + if (value instanceof Map || value instanceof Set) return [...value.entries()]; + if (value instanceof Function || value instanceof Error) return undefined; + if (value instanceof RegExp) return value.toString(); + + const original = this[key]; + return original instanceof Date ? original.getTime() : value; + } + return JSON.parse(JSON.stringify(obj, replacer)) as Serialized; + } catch (ex) { + debugger; + throw ex; } - return JSON.parse(JSON.stringify(obj, replacer)) as Serialized; } diff --git a/src/webviews/apps/commitDetails/commitDetails.ts b/src/webviews/apps/commitDetails/commitDetails.ts index ab8d53f..973594c 100644 --- a/src/webviews/apps/commitDetails/commitDetails.ts +++ b/src/webviews/apps/commitDetails/commitDetails.ts @@ -6,7 +6,6 @@ import type { CommitActionsParams, State } from '../../commitDetails/protocol'; import { AutolinkSettingsCommandType, CommitActionsCommandType, - DidChangeRichStateNotificationType, DidChangeStateNotificationType, FileActionsCommandType, OpenFileCommandType, @@ -95,27 +94,27 @@ export class CommitDetailsApp extends App> { protected override onMessageReceived(e: MessageEvent) { const msg = e.data as IpcMessage; switch (msg.method) { - case DidChangeRichStateNotificationType.method: - onIpc(DidChangeRichStateNotificationType, msg, params => { - if (this.state.selected == null) return; - - assertsSerialized(params); - - const newState = { ...this.state }; - if (params.formattedMessage != null) { - newState.selected!.message = params.formattedMessage; - } - // if (params.pullRequest != null) { - newState.pullRequest = params.pullRequest; - // } - // if (params.formattedMessage != null) { - newState.autolinkedIssues = params.autolinkedIssues; - // } - - this.state = newState; - this.renderRichContent(); - }); - break; + // case DidChangeRichStateNotificationType.method: + // onIpc(DidChangeRichStateNotificationType, msg, params => { + // if (this.state.selected == null) return; + + // assertsSerialized(params); + + // const newState = { ...this.state }; + // if (params.formattedMessage != null) { + // newState.selected!.message = params.formattedMessage; + // } + // // if (params.pullRequest != null) { + // newState.pullRequest = params.pullRequest; + // // } + // // if (params.formattedMessage != null) { + // newState.autolinkedIssues = params.autolinkedIssues; + // // } + + // this.state = newState; + // this.renderRichContent(); + // }); + // break; case DidChangeStateNotificationType.method: onIpc(DidChangeStateNotificationType, msg, params => { assertsSerialized(params.state); diff --git a/src/webviews/commitDetails/commitDetailsWebviewView.ts b/src/webviews/commitDetails/commitDetailsWebviewView.ts index 6c7b867..3e353bd 100644 --- a/src/webviews/commitDetails/commitDetailsWebviewView.ts +++ b/src/webviews/commitDetails/commitDetailsWebviewView.ts @@ -10,6 +10,7 @@ import type { GitFileChange } from '../../git/models/file'; import { GitFile } from '../../git/models/file'; import type { IssueOrPullRequest } from '../../git/models/issue'; import type { PullRequest } from '../../git/models/pullRequest'; +import { toPullRequestShape } from '../../git/models/pullRequest'; import type { GitRevisionReference } from '../../git/models/reference'; import { Logger } from '../../logger'; import type { ShowCommitInGraphCommandArgs } from '../../plus/webviews/graph/graphWebview'; @@ -306,7 +307,7 @@ export class CommitDetailsWebviewView extends WebviewViewBase { if (cancellation.isCancellationRequested) return; - void this.updateRichState(cancellation); + void this.updateRichState(current, cancellation); }, 100); } } @@ -320,15 +321,14 @@ export class CommitDetailsWebviewView extends WebviewViewBase { - const commit = this._context.commit; + private async updateRichState(current: Context, cancellation: CancellationToken): Promise { + const commit = current.commit; if (commit == null) return; const remotes = await this.container.git.getRemotesWithProviders(commit.repoPath, { sort: true }); @@ -508,18 +508,23 @@ export class CommitDetailsWebviewView extends WebviewViewBase