From bc0bf420f4b0a18c0ebfdd5d5a2d343954073bbb Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Wed, 2 Feb 2022 01:55:04 -0500 Subject: [PATCH] Adds `${link}` token to commits Improves commit tooltips --- src/git/formatters/commitFormatter.ts | 12 ++++ src/views/nodes/commitNode.ts | 2 +- src/views/nodes/fileRevisionAsCommitNode.ts | 2 +- src/views/nodes/mergeConflictCurrentChangesNode.ts | 2 +- src/views/nodes/mergeConflictFileNode.ts | 13 +++- .../nodes/mergeConflictIncomingChangesNode.ts | 2 +- src/views/nodes/rebaseStatusNode.ts | 69 ++++++++++++++++------ 7 files changed, 76 insertions(+), 26 deletions(-) diff --git a/src/git/formatters/commitFormatter.ts b/src/git/formatters/commitFormatter.ts index 5d35ca7..9c48c41 100644 --- a/src/git/formatters/commitFormatter.ts +++ b/src/git/formatters/commitFormatter.ts @@ -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; diff --git a/src/views/nodes/commitNode.ts b/src/views/nodes/commitNode.ts index efcb217..4fd437b 100644 --- a/src/views/nodes/commitNode.ts +++ b/src/views/nodes/commitNode.ts @@ -150,7 +150,7 @@ export class CommitNode extends ViewRefNode 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; diff --git a/src/views/nodes/mergeConflictIncomingChangesNode.ts b/src/views/nodes/mergeConflictIncomingChangesNode.ts index 6207f40..1514880 100644 --- a/src/views/nodes/mergeConflictIncomingChangesNode.ts +++ b/src/views/nodes/mergeConflictIncomingChangesNode.ts @@ -47,7 +47,7 @@ export class MergeConflictIncomingChangesNode extends ViewNode { const commit = this.commit; @@ -189,7 +172,6 @@ export class RebaseCommitNode extends ViewRefNode { + 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}\${'  \u2022  'changesDetail}\${'    'tips}\n\n\${avatar}  __\${author}__, \${ago}   _(\${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; + } }