From 40f471ba127e8b0cac5ed50df6e674a7d51bae99 Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Thu, 13 Apr 2023 01:21:06 -0400 Subject: [PATCH] Moves formats into options - Allows for easier pre-calc/cache of options --- src/annotations/blameAnnotationProvider.ts | 19 +++++++------------ src/hovers/hovers.ts | 22 +++++++++------------- src/hovers/lineHoverController.ts | 19 +++++++------------ src/statusbar/statusBarController.ts | 21 ++++++++------------- 4 files changed, 31 insertions(+), 50 deletions(-) diff --git a/src/annotations/blameAnnotationProvider.ts b/src/annotations/blameAnnotationProvider.ts index 2930b6c..88ebaae 100644 --- a/src/annotations/blameAnnotationProvider.ts +++ b/src/annotations/blameAnnotationProvider.ts @@ -190,19 +190,14 @@ export abstract class BlameAnnotationProviderBase extends AnnotationProviderBase editorLine = commitLine.originalLine - 1; const cfg = configuration.get('hovers'); - return detailsMessage( - commit, - await GitUri.fromUri(document.uri), - editorLine, - cfg.detailsMarkdownFormat, - configuration.get('defaultDateFormat'), - { - autolinks: cfg.autolinks.enabled, - pullRequests: { - enabled: cfg.pullRequests.enabled, - }, + return detailsMessage(commit, await GitUri.fromUri(document.uri), editorLine, { + autolinks: cfg.autolinks.enabled, + dateFormat: configuration.get('defaultDateFormat'), + format: cfg.detailsMarkdownFormat, + pullRequests: { + enabled: cfg.pullRequests.enabled, }, - ); + }); } } diff --git a/src/hovers/hovers.ts b/src/hovers/hovers.ts index 36f99ab..19a736a 100644 --- a/src/hovers/hovers.ts +++ b/src/hovers/hovers.ts @@ -191,25 +191,21 @@ export async function detailsMessage( commit: GitCommit, uri: GitUri, editorLine: number, // 0-based, Git is 1-based - format: string, - dateFormat: string | null, - options?: { + options: Readonly<{ autolinks?: boolean; cancellationToken?: CancellationToken; - pullRequests?: { + dateFormat: string | null; + format: string; + pullRequests?: Readonly<{ enabled: boolean; pr?: PullRequest | PromiseCancelledError>; - }; + }>; getBranchAndTagTips?: ( sha: string, options?: { compact?: boolean | undefined; icons?: boolean | undefined }, ) => string | undefined; - }, + }>, ): Promise { - if (dateFormat === null) { - dateFormat = 'MMMM Do, YYYY h:mma'; - } - let message = commit.message ?? commit.summary; if (commit.message == null && !commit.isUncommitted) { await commit.ensureFullDetails(); @@ -231,7 +227,7 @@ export async function detailsMessage( pullRequests: options?.pullRequests?.enabled !== false && CommitFormatter.has( - format, + options.format, 'pullRequest', 'pullRequestAgo', 'pullRequestAgoOrDate', @@ -254,9 +250,9 @@ export async function detailsMessage( autolinkedIssuesOrPullRequests?.delete(pr.id); } - const details = await CommitFormatter.fromTemplateAsync(format, commit, { + const details = await CommitFormatter.fromTemplateAsync(options.format, commit, { autolinkedIssuesOrPullRequests: autolinkedIssuesOrPullRequests, - dateFormat: dateFormat, + dateFormat: options.dateFormat === null ? 'MMMM Do, YYYY h:mma' : options.dateFormat, editor: { line: editorLine, uri: uri, diff --git a/src/hovers/lineHoverController.ts b/src/hovers/lineHoverController.ts index 5966a56..b231f08 100644 --- a/src/hovers/lineHoverController.ts +++ b/src/hovers/lineHoverController.ts @@ -124,19 +124,14 @@ export class LineHoverController implements Disposable { const trackedDocument = await this.container.tracker.get(document); if (trackedDocument == null) return undefined; - const message = await detailsMessage( - commit, - trackedDocument.uri, - editorLine, - cfg.detailsMarkdownFormat, - configuration.get('defaultDateFormat'), - { - autolinks: cfg.autolinks.enabled, - pullRequests: { - enabled: cfg.pullRequests.enabled, - }, + const message = await detailsMessage(commit, trackedDocument.uri, editorLine, { + autolinks: cfg.autolinks.enabled, + dateFormat: configuration.get('defaultDateFormat'), + format: cfg.detailsMarkdownFormat, + pullRequests: { + enabled: cfg.pullRequests.enabled, }, - ); + }); return new Hover(message, range); } diff --git a/src/statusbar/statusBarController.ts b/src/statusbar/statusBarController.ts index bcba214..aae1bda 100644 --- a/src/statusbar/statusBarController.ts +++ b/src/statusbar/statusBarController.ts @@ -374,19 +374,14 @@ export class StatusBarController implements Disposable { ) { if (cancellationToken.isCancellationRequested) return; - const tooltip = await detailsMessage( - commit, - commit.getGitUri(), - commit.lines[0].line, - configuration.get('statusBar.tooltipFormat'), - configuration.get('defaultDateFormat'), - { - autolinks: true, - cancellationToken: cancellationToken, - getBranchAndTagTips: getBranchAndTagTips, - pullRequests: pullRequests, - }, - ); + const tooltip = await detailsMessage(commit, commit.getGitUri(), commit.lines[0].line, { + autolinks: true, + cancellationToken: cancellationToken, + dateFormat: configuration.get('defaultDateFormat'), + format: configuration.get('statusBar.tooltipFormat'), + getBranchAndTagTips: getBranchAndTagTips, + pullRequests: pullRequests, + }); if (cancellationToken.isCancellationRequested) return;