瀏覽代碼

Moves formats into options

- Allows for easier pre-calc/cache of options
main
Eric Amodio 1 年之前
父節點
當前提交
40f471ba12
共有 4 個檔案被更改,包括 31 行新增50 行删除
  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 查看文件

@ -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,
},
);
});
}
}

+ 9
- 13
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<Promise<PullRequest | undefined>>;
};
}>;
getBranchAndTagTips?: (
sha: string,
options?: { compact?: boolean | undefined; icons?: boolean | undefined },
) => string | undefined;
},
}>,
): Promise<MarkdownString> {
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,

+ 7
- 12
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);
}

+ 8
- 13
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;

Loading…
取消
儲存