Browse Source

Moves formats into options

- Allows for easier pre-calc/cache of options
main
Eric Amodio 1 year ago
parent
commit
40f471ba12
4 changed files with 31 additions and 50 deletions
  1. +7
    -12
      src/annotations/blameAnnotationProvider.ts
  2. +9
    -13
      src/hovers/hovers.ts
  3. +7
    -12
      src/hovers/lineHoverController.ts
  4. +8
    -13
      src/statusbar/statusBarController.ts

+ 7
- 12
src/annotations/blameAnnotationProvider.ts View File

@ -190,19 +190,14 @@ export abstract class BlameAnnotationProviderBase extends AnnotationProviderBase
editorLine = commitLine.originalLine - 1; editorLine = commitLine.originalLine - 1;
const cfg = configuration.get('hovers'); 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,
}, },
);
});
} }
} }

+ 9
- 13
src/hovers/hovers.ts View File

@ -191,25 +191,21 @@ export async function detailsMessage(
commit: GitCommit, commit: GitCommit,
uri: GitUri, uri: GitUri,
editorLine: number, // 0-based, Git is 1-based editorLine: number, // 0-based, Git is 1-based
format: string,
dateFormat: string | null,
options?: {
options: Readonly<{
autolinks?: boolean; autolinks?: boolean;
cancellationToken?: CancellationToken; cancellationToken?: CancellationToken;
pullRequests?: {
dateFormat: string | null;
format: string;
pullRequests?: Readonly<{
enabled: boolean; enabled: boolean;
pr?: PullRequest | PromiseCancelledError<Promise<PullRequest | undefined>>; pr?: PullRequest | PromiseCancelledError<Promise<PullRequest | undefined>>;
};
}>;
getBranchAndTagTips?: ( getBranchAndTagTips?: (
sha: string, sha: string,
options?: { compact?: boolean | undefined; icons?: boolean | undefined }, options?: { compact?: boolean | undefined; icons?: boolean | undefined },
) => string | undefined; ) => string | undefined;
},
}>,
): Promise<MarkdownString> { ): Promise<MarkdownString> {
if (dateFormat === null) {
dateFormat = 'MMMM Do, YYYY h:mma';
}
let message = commit.message ?? commit.summary; let message = commit.message ?? commit.summary;
if (commit.message == null && !commit.isUncommitted) { if (commit.message == null && !commit.isUncommitted) {
await commit.ensureFullDetails(); await commit.ensureFullDetails();
@ -231,7 +227,7 @@ export async function detailsMessage(
pullRequests: pullRequests:
options?.pullRequests?.enabled !== false && options?.pullRequests?.enabled !== false &&
CommitFormatter.has( CommitFormatter.has(
format,
options.format,
'pullRequest', 'pullRequest',
'pullRequestAgo', 'pullRequestAgo',
'pullRequestAgoOrDate', 'pullRequestAgoOrDate',
@ -254,9 +250,9 @@ export async function detailsMessage(
autolinkedIssuesOrPullRequests?.delete(pr.id); autolinkedIssuesOrPullRequests?.delete(pr.id);
} }
const details = await CommitFormatter.fromTemplateAsync(format, commit, {
const details = await CommitFormatter.fromTemplateAsync(options.format, commit, {
autolinkedIssuesOrPullRequests: autolinkedIssuesOrPullRequests, autolinkedIssuesOrPullRequests: autolinkedIssuesOrPullRequests,
dateFormat: dateFormat,
dateFormat: options.dateFormat === null ? 'MMMM Do, YYYY h:mma' : options.dateFormat,
editor: { editor: {
line: editorLine, line: editorLine,
uri: uri, uri: uri,

+ 7
- 12
src/hovers/lineHoverController.ts View File

@ -124,19 +124,14 @@ export class LineHoverController implements Disposable {
const trackedDocument = await this.container.tracker.get(document); const trackedDocument = await this.container.tracker.get(document);
if (trackedDocument == null) return undefined; 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); return new Hover(message, range);
} }

+ 8
- 13
src/statusbar/statusBarController.ts View File

@ -374,19 +374,14 @@ export class StatusBarController implements Disposable {
) { ) {
if (cancellationToken.isCancellationRequested) return; 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; if (cancellationToken.isCancellationRequested) return;

Loading…
Cancel
Save