Browse Source

Closes #954 - uses codicons in hovers

main
Eric Amodio 4 years ago
parent
commit
acfca80dbd
2 changed files with 41 additions and 36 deletions
  1. +14
    -14
      src/git/formatters/commitFormatter.ts
  2. +27
    -22
      src/hovers/hovers.ts

+ 14
- 14
src/git/formatters/commitFormatter.ts View File

@ -235,33 +235,33 @@ export class CommitFormatter extends Formatter {
return commands; return commands;
} }
const separator = '  ';
const separator = '   |   ';
commands = `[\`${this.id}\`](${ShowQuickCommitDetailsCommand.getMarkdownCommandArgs(
commands = `---\n\n[$(git-commit) ${this.id}](${ShowQuickCommitDetailsCommand.getMarkdownCommandArgs(
this._item.sha this._item.sha
)} "Show Commit Details")${separator}`; )} "Show Commit Details")${separator}`;
const { pullRequestOrRemote: pr } = this._options; const { pullRequestOrRemote: pr } = this._options;
if (pr != null) { if (pr != null) {
if (PullRequest.is(pr)) { if (PullRequest.is(pr)) {
commands += `[\`PR #${pr.number}\`](${pr.url} "Open Pull Request \\#${pr.number} on ${
commands += `[$(git-pull-request) PR #${pr.number}](${pr.url} "Open Pull Request \\#${pr.number} on ${
pr.provider pr.provider
}\n${GlyphChars.Dash.repeat(2)}\n${pr.title}\n${pr.state}, ${pr.formatDateFromNow()}")${separator}`; }\n${GlyphChars.Dash.repeat(2)}\n${pr.title}\n${pr.state}, ${pr.formatDateFromNow()}")${separator}`;
} else if (pr instanceof Promises.CancellationError) { } else if (pr instanceof Promises.CancellationError) {
commands += `[\`PR ${GlyphChars.Ellipsis}\`](# "Searching for a Pull Request (if any) that introduced this commit...")${separator}`;
commands += `[$(git-pull-request) PR (${GlyphChars.Ellipsis})](# "Searching for a Pull Request (if any) that introduced this commit...")${separator}`;
} else if (pr.provider != null) { } else if (pr.provider != null) {
commands += `[\`Connect to ${pr.provider.name}${
commands += `[$(plug) Connect to ${pr.provider.name}${
GlyphChars.Ellipsis GlyphChars.Ellipsis
}\`](${ConnectRemoteProviderCommand.getMarkdownCommandArgs(pr)} "Connect to ${
}](${ConnectRemoteProviderCommand.getMarkdownCommandArgs(pr)} "Connect to ${
pr.provider.name pr.provider.name
} to enable the display of the Pull Request (if any) that introduced this commit")${separator}`; } to enable the display of the Pull Request (if any) that introduced this commit")${separator}`;
} }
} }
commands += `**[\`${GlyphChars.MuchLessThan}\`](${DiffWithCommand.getMarkdownCommandArgs(
commands += `[$(compare-changes)](${DiffWithCommand.getMarkdownCommandArgs(
this._item, this._item,
this._options.line this._options.line
)} "Open Changes")**${separator}`;
)} "Open Changes")${separator}`;
if (this._item.previousSha !== undefined) { if (this._item.previousSha !== undefined) {
let annotationType = this._options.annotationType; let annotationType = this._options.annotationType;
@ -274,29 +274,29 @@ export class CommitFormatter extends Formatter {
this._item.previousUri.fsPath, this._item.previousUri.fsPath,
this._item.repoPath this._item.repoPath
); );
commands += `**[\` ${GlyphChars.EqualsTriple} \`](${OpenFileRevisionCommand.getMarkdownCommandArgs(
commands += `[$(history)](${OpenFileRevisionCommand.getMarkdownCommandArgs(
uri, uri,
annotationType || FileAnnotationType.Blame, annotationType || FileAnnotationType.Blame,
this._options.line this._options.line
)} "Blame Previous Revision")**${separator}`;
)} "Blame Previous Revision")${separator}`;
} }
if (this._options.remotes !== undefined && this._options.remotes.length !== 0) { if (this._options.remotes !== undefined && this._options.remotes.length !== 0) {
commands += `**[\` ${GlyphChars.ArrowUpRight} \`](${OpenCommitInRemoteCommand.getMarkdownCommandArgs(
commands += `[$(link-external)](${OpenCommitInRemoteCommand.getMarkdownCommandArgs(
this._item.sha this._item.sha
)} "Open on Remote")**${separator}`;
)} "Open on Remote")${separator}`;
} }
if (this._item.author !== 'You') { if (this._item.author !== 'You') {
const presence = this._options.presence; const presence = this._options.presence;
if (presence != null) { if (presence != null) {
commands += `[\` ${GlyphChars.Envelope}+ \`](${InviteToLiveShareCommand.getMarkdownCommandArgs(
commands += `[$(live-share)](${InviteToLiveShareCommand.getMarkdownCommandArgs(
this._item.email this._item.email
)} "Invite ${this._item.author} (${presence.statusText}) to a Live Share Session")${separator}`; )} "Invite ${this._item.author} (${presence.statusText}) to a Live Share Session")${separator}`;
} }
} }
commands += `[\`${GlyphChars.MiddleEllipsis}\`](${ShowQuickCommitFileDetailsCommand.getMarkdownCommandArgs({
commands += `[$(ellipsis)](${ShowQuickCommitFileDetailsCommand.getMarkdownCommandArgs({
revisionUri: GitUri.toRevisionUri(this._item.toGitUri()).toString(true) revisionUri: GitUri.toRevisionUri(this._item.toGitUri()).toString(true)
})} "Show More Actions")`; })} "Show More Actions")`;

+ 27
- 22
src/hovers/hovers.ts View File

@ -85,7 +85,7 @@ export namespace Hovers {
return undefined; return undefined;
} }
message = `[\`Changes\`](${DiffWithCommand.getMarkdownCommandArgs({
message = `[$(compare-changes) Changes](${DiffWithCommand.getMarkdownCommandArgs({
lhs: { lhs: {
sha: diffUris.previous.sha || '', sha: diffUris.previous.sha || '',
uri: diffUris.previous.documentUri() uri: diffUris.previous.documentUri()
@ -105,9 +105,9 @@ export namespace Hovers {
working: 'Working Tree' working: 'Working Tree'
} }
})}_` })}_`
: `[\`${GitService.shortenSha(
: `[$(git-commit) ${GitService.shortenSha(
diffUris.previous.sha || '' diffUris.previous.sha || ''
)}\`](${ShowQuickCommitDetailsCommand.getMarkdownCommandArgs(
)}](${ShowQuickCommitDetailsCommand.getMarkdownCommandArgs(
diffUris.previous.sha || '' diffUris.previous.sha || ''
)} "Show Commit Details")`; )} "Show Commit Details")`;
@ -118,26 +118,29 @@ export namespace Hovers {
working: 'Working Tree' working: 'Working Tree'
} }
})}_` })}_`
: `[\`${GitService.shortenSha(
: `[$(git-commit) ${GitService.shortenSha(
diffUris.current.sha || '' diffUris.current.sha || ''
)}\`](${ShowQuickCommitDetailsCommand.getMarkdownCommandArgs(
)}](${ShowQuickCommitDetailsCommand.getMarkdownCommandArgs(
diffUris.current.sha || '' diffUris.current.sha || ''
)} "Show Commit Details")`; )} "Show Commit Details")`;
} else { } else {
message = `[\`Changes\`](${DiffWithCommand.getMarkdownCommandArgs(commit, editorLine)} "Open Changes")`;
message = `[$(compare-changes) Changes](${DiffWithCommand.getMarkdownCommandArgs(
commit,
editorLine
)} "Open Changes")`;
previous = `[\`${commit.previousShortSha}\`](${ShowQuickCommitDetailsCommand.getMarkdownCommandArgs(
commit.previousSha
)} "Show Commit Details")`;
previous = `[$(git-commit) ${
commit.previousShortSha
}](${ShowQuickCommitDetailsCommand.getMarkdownCommandArgs(commit.previousSha)} "Show Commit Details")`;
current = `[\`${commit.shortSha}\`](${ShowQuickCommitDetailsCommand.getMarkdownCommandArgs(
current = `[$(git-commit) ${commit.shortSha}](${ShowQuickCommitDetailsCommand.getMarkdownCommandArgs(
commit.sha commit.sha
)} "Show Commit Details")`; )} "Show Commit Details")`;
} }
message += `   ${GlyphChars.Dash}   ${previous}  ${GlyphChars.ArrowLeftRightLong}  ${current}\n${diff}`; message += `   ${GlyphChars.Dash}   ${previous}  ${GlyphChars.ArrowLeftRightLong}  ${current}\n${diff}`;
const markdown = new MarkdownString(message);
const markdown = new MarkdownString(message, true);
markdown.isTrusted = true; markdown.isTrusted = true;
return markdown; return markdown;
} }
@ -155,16 +158,16 @@ export namespace Hovers {
const remotes = await Container.git.getRemotes(commit.repoPath, { sort: true }); const remotes = await Container.git.getRemotes(commit.repoPath, { sort: true });
const [previousLineDiffUris, autolinkedIssues, pr, presence] = await Promise.all([
const [previousLineDiffUris, autolinkedIssuesOrPullRequests, pr, presence] = await Promise.all([
commit.isUncommitted ? commit.getPreviousLineDiffUris(uri, editorLine, uri.sha) : undefined, commit.isUncommitted ? commit.getPreviousLineDiffUris(uri, editorLine, uri.sha) : undefined,
getAutoLinkedIssues(commit.message, remotes),
getAutoLinkedIssuesOrPullRequests(commit.message, remotes),
getPullRequestForCommit(commit.ref, remotes), getPullRequestForCommit(commit.ref, remotes),
Container.vsls.maybeGetPresence(commit.email).catch(reason => undefined) Container.vsls.maybeGetPresence(commit.email).catch(reason => undefined)
]); ]);
const details = CommitFormatter.fromTemplate(Container.config.hovers.detailsMarkdownFormat, commit, { const details = CommitFormatter.fromTemplate(Container.config.hovers.detailsMarkdownFormat, commit, {
annotationType: annotationType, annotationType: annotationType,
autolinkedIssues: autolinkedIssues,
autolinkedIssuesOrPullRequests: autolinkedIssuesOrPullRequests,
dateFormat: dateFormat, dateFormat: dateFormat,
line: editorLine, line: editorLine,
markdown: true, markdown: true,
@ -174,7 +177,7 @@ export namespace Hovers {
remotes: remotes remotes: remotes
}); });
const markdown = new MarkdownString(details);
const markdown = new MarkdownString(details, true);
markdown.isTrusted = true; markdown.isTrusted = true;
return markdown; return markdown;
} }
@ -189,7 +192,7 @@ export namespace Hovers {
}\n\`\`\``; }\n\`\`\``;
} }
async function getAutoLinkedIssues(message: string, remotes: GitRemote[]) {
async function getAutoLinkedIssuesOrPullRequests(message: string, remotes: GitRemote[]) {
const cc = Logger.getNewCorrelationContext('Hovers.getAutoLinkedIssues'); const cc = Logger.getNewCorrelationContext('Hovers.getAutoLinkedIssues');
Logger.debug(cc, `${GlyphChars.Dash} message=<message>`); Logger.debug(cc, `${GlyphChars.Dash} message=<message>`);
@ -216,11 +219,13 @@ export namespace Hovers {
const timeout = 250; const timeout = 250;
try { try {
const autolinkedIssues = await Container.autolinks.getIssueLinks(message, remote, { timeout: timeout });
const autolinks = await Container.autolinks.getIssueOrPullRequestLinks(message, remote, {
timeout: timeout
});
if (autolinkedIssues !== undefined && (Logger.level === TraceLevel.Debug || Logger.isDebugging)) {
if (autolinks !== undefined && (Logger.level === TraceLevel.Debug || Logger.isDebugging)) {
const timeouts = [ const timeouts = [
...Iterables.filterMap(autolinkedIssues.values(), issue =>
...Iterables.filterMap(autolinks.values(), issue =>
issue instanceof Promises.CancellationError ? issue.promise : undefined issue instanceof Promises.CancellationError ? issue.promise : undefined
) )
]; ];
@ -229,20 +234,20 @@ export namespace Hovers {
if (timeouts.length !== 0) { if (timeouts.length !== 0) {
Logger.debug( Logger.debug(
cc, cc,
`timed out ${GlyphChars.Dash} issue queries (${
`timed out ${GlyphChars.Dash} issue/pr queries (${
timeouts.length timeouts.length
}) took too long (over ${timeout} ms) ${GlyphChars.Dot} ${Strings.getDurationMilliseconds( }) took too long (over ${timeout} ms) ${GlyphChars.Dot} ${Strings.getDurationMilliseconds(
start start
)} ms` )} ms`
); );
return autolinkedIssues;
return autolinks;
} }
} }
Logger.debug(cc, `completed ${GlyphChars.Dot} ${Strings.getDurationMilliseconds(start)} ms`); Logger.debug(cc, `completed ${GlyphChars.Dot} ${Strings.getDurationMilliseconds(start)} ms`);
return autolinkedIssues;
return autolinks;
} catch (ex) { } catch (ex) {
Logger.error(ex, cc, `failed ${GlyphChars.Dot} ${Strings.getDurationMilliseconds(start)} ms`); Logger.error(ex, cc, `failed ${GlyphChars.Dot} ${Strings.getDurationMilliseconds(start)} ms`);

Loading…
Cancel
Save