Sfoglia il codice sorgente

Adds `${link}` token to commits

Improves commit tooltips
main
Eric Amodio 2 anni fa
parent
commit
bc0bf420f4
7 ha cambiato i file con 76 aggiunte e 26 eliminazioni
  1. +12
    -0
      src/git/formatters/commitFormatter.ts
  2. +1
    -1
      src/views/nodes/commitNode.ts
  3. +1
    -1
      src/views/nodes/fileRevisionAsCommitNode.ts
  4. +1
    -1
      src/views/nodes/mergeConflictCurrentChangesNode.ts
  5. +10
    -3
      src/views/nodes/mergeConflictFileNode.ts
  6. +1
    -1
      src/views/nodes/mergeConflictIncomingChangesNode.ts
  7. +50
    -19
      src/views/nodes/rebaseStatusNode.ts

+ 12
- 0
src/git/formatters/commitFormatter.ts Vedi File

@ -65,6 +65,7 @@ export interface CommitFormatOptions extends FormatOptions {
email?: TokenOptions;
footnotes?: TokenOptions;
id?: TokenOptions;
link?: TokenOptions;
message?: TokenOptions;
pullRequest?: TokenOptions;
pullRequestAgo?: TokenOptions;
@ -459,6 +460,17 @@ export class CommitFormatter extends Formatter {
return sha;
}
get link(): string {
if (!this._options.markdown) return this.id;
const sha = this._padOrTruncate(this._item.shortSha ?? '', this._options.tokenOptions.id);
const link = `[\`$(git-commit) ${sha}\`](${ShowQuickCommitCommand.getMarkdownCommandArgs(
this._item.sha,
)} "Show Commit")`;
return this._padOrTruncate(link, this._options.tokenOptions.link);
}
get message(): string {
if (this._item.isUncommitted) {
const confliced = this._item.file?.hasConflicts ?? false;

+ 1
- 1
src/views/nodes/commitNode.ts Vedi File

@ -150,7 +150,7 @@ export class CommitNode extends ViewRefNode
}
const tooltip = await CommitFormatter.fromTemplateAsync(
`\${'\`$(git-commit) 'id\`}\${' via 'pullRequest}\${'  \u2022  'changesDetail}\${'    'tips}\n\n\${avatar}  __\${author}__, \${ago}   _(\${date})_ \n\n\${message}\${\n\n---\n\nfootnotes}`,
`\${link}\${' via 'pullRequest}\${'  \u2022  'changesDetail}\${'    'tips}\n\n\${avatar}  __\${author}__, \${ago}   _(\${date})_ \n\n\${message}\${\n\n---\n\nfootnotes}`,
this.commit,
{
autolinkedIssuesOrPullRequests: autolinkedIssuesOrPullRequests,

+ 1
- 1
src/views/nodes/fileRevisionAsCommitNode.ts Vedi File

@ -223,7 +223,7 @@ export class FileRevisionAsCommitNode extends ViewRefFileNode
const status = StatusFileFormatter.fromTemplate(`\${status}\${ (originalPath)}`, this.file);
const tooltip = await CommitFormatter.fromTemplateAsync(
`\${'\`$(git-commit) 'id\`}\${' via 'pullRequest} \u2022 ${status}\${ \u2022 changesDetail}\${'   'tips}\n\n\${avatar}  __\${author}__, \${ago}   _(\${date})_ \n\n\${message}\${\n\n---\n\nfootnotes}`,
`\${link}\${' via 'pullRequest} \u2022 ${status}\${ \u2022 changesDetail}\${'   'tips}\n\n\${avatar}  __\${author}__, \${ago}   _(\${date})_ \n\n\${message}\${\n\n---\n\nfootnotes}`,
this.commit,
{
autolinkedIssuesOrPullRequests: autolinkedIssuesOrPullRequests,

+ 1
- 1
src/views/nodes/mergeConflictCurrentChangesNode.ts Vedi File

@ -42,7 +42,7 @@ export class MergeConflictCurrentChangesNode extends ViewNode
)}${
commit != null
? `\n\n${await CommitFormatter.fromTemplateAsync(
`$(git-commit) \${id} ${GlyphChars.Dash} \${avatar} __\${author}__, \${ago}\${' via 'pullRequest}   _(\${date})_ \n\n\${message}`,
`\${avatar} __\${author}__, \${ago}   _(\${date})_ \n\n\${message}\n\n\${link}\${' via 'pullRequest}`,
commit,
{
avatarSize: 16,

+ 10
- 3
src/views/nodes/mergeConflictFileNode.ts Vedi File

@ -1,4 +1,4 @@
import { Command, ThemeIcon, TreeItem, TreeItemCollapsibleState, Uri } from 'vscode';
import { Command, MarkdownString, ThemeIcon, TreeItem, TreeItemCollapsibleState, Uri } from 'vscode';
import { BuiltInCommands } from '../../constants';
import { StatusFileFormatter } from '../../git/formatters';
import { GitUri } from '../../git/gitUri';
@ -47,10 +47,17 @@ export class MergeConflictFileNode extends ViewNode implements
const item = new TreeItem(this.label, TreeItemCollapsibleState.Collapsed);
item.description = this.description;
item.contextValue = `${ContextValues.File}+conflicted`;
item.tooltip = StatusFileFormatter.fromTemplate(
`\${file}\n\${directory}/\n\n\${status}\${ (originalPath)} in Index (staged)`,
const tooltip = StatusFileFormatter.fromTemplate(
`\${file}\${ \u2022 changesDetail}\${\\\\\ndirectory}\${\n\nstatus}\${ (originalPath)} in Index (staged)`,
this.file,
);
const markdown = new MarkdownString(tooltip, true);
markdown.isTrusted = true;
markdown.supportHtml = true;
item.tooltip = markdown;
// Use the file icon and decorations
item.resourceUri = this.view.container.git.getAbsoluteUri(this.file.path, this.repoPath);
item.iconPath = ThemeIcon.File;

+ 1
- 1
src/views/nodes/mergeConflictIncomingChangesNode.ts Vedi File

@ -47,7 +47,7 @@ export class MergeConflictIncomingChangesNode extends ViewNode
? ` from ${GitReference.toString(this.status.incoming)}${
commit != null
? `\n\n${await CommitFormatter.fromTemplateAsync(
`$(git-commit) \${id} ${GlyphChars.Dash} \${avatar} __\${author}__, \${ago}\${' via 'pullRequest}   _(\${date})_ \n\n\${message}`,
`\${avatar} __\${author}__, \${ago}   _(\${date})_ \n\n\${message}\n\n\${link}\${' via 'pullRequest}`,
commit,
{
avatarSize: 16,

+ 50
- 19
src/views/nodes/rebaseStatusNode.ts Vedi File

@ -10,7 +10,7 @@ import {
} from 'vscode';
import { Commands, DiffWithPreviousCommandArgs } from '../../commands';
import { ViewFilesLayout } from '../../configuration';
import { BuiltInCommands, GlyphChars } from '../../constants';
import { BuiltInCommands } from '../../constants';
import { CommitFormatter } from '../../git/formatters';
import { GitUri } from '../../git/gitUri';
import { GitBranch, GitCommit, GitRebaseStatus, GitReference, GitRevisionReference, GitStatus } from '../../git/models';
@ -140,23 +140,6 @@ export class RebaseCommitNode extends ViewRefNode
return this.commit;
}
private get tooltip() {
return CommitFormatter.fromTemplate(
`\${author}\${ (email)} ${
GlyphChars.Dash
} \${id}\${ (tips)}\n\${ago} (\${date})\${\n\nmessage}${this.commit.formatStats({
expand: true,
prefix: '\n\n',
separator: '\n',
})}\${\n\n${GlyphChars.Dash.repeat(2)}\nfootnotes}`,
this.commit,
{
dateFormat: this.view.container.config.defaultDateFormat,
messageIndent: 4,
},
);
}
async getChildren(): Promise<ViewNode[]> {
const commit = this.commit;
@ -189,7 +172,6 @@ export class RebaseCommitNode extends ViewRefNode
messageTruncateAtNewLine: true,
});
item.iconPath = new ThemeIcon('git-commit');
item.tooltip = this.tooltip;
return item;
}
@ -210,4 +192,53 @@ export class RebaseCommitNode extends ViewRefNode
arguments: [undefined, commandArgs],
};
}
override async resolveTreeItem(item: TreeItem): Promise<TreeItem> {
if (item.tooltip == null) {
item.tooltip = await this.getTooltip();
}
return item;
}
private async getTooltip() {
const remotes = await this.view.container.git.getRemotesWithProviders(this.commit.repoPath);
const remote = await this.view.container.git.getRichRemoteProvider(remotes);
if (this.commit.message == null) {
await this.commit.ensureFullDetails();
}
let autolinkedIssuesOrPullRequests;
let pr;
if (remote?.provider != null) {
[autolinkedIssuesOrPullRequests, pr] = await Promise.all([
this.view.container.autolinks.getIssueOrPullRequestLinks(
this.commit.message ?? this.commit.summary,
remote,
),
this.view.container.git.getPullRequestForCommit(this.commit.ref, remote.provider),
]);
}
const tooltip = await CommitFormatter.fromTemplateAsync(
`Rebase paused at \${link}\${' via 'pullRequest}\${'&nbsp;&nbsp;\u2022&nbsp;&nbsp;'changesDetail}\${'&nbsp;&nbsp;&nbsp;&nbsp;'tips}\n\n\${avatar} &nbsp;__\${author}__, \${ago} &nbsp; _(\${date})_ \n\n\${message}\${\n\n---\n\nfootnotes}`,
this.commit,
{
autolinkedIssuesOrPullRequests: autolinkedIssuesOrPullRequests,
dateFormat: this.view.container.config.defaultDateFormat,
markdown: true,
messageAutolinks: true,
messageIndent: 4,
pullRequestOrRemote: pr,
remotes: remotes,
},
);
const markdown = new MarkdownString(tooltip, true);
markdown.supportHtml = true;
markdown.isTrusted = true;
return markdown;
}
}

Caricamento…
Annulla
Salva