Skip to content

Commit

Permalink
Adds rich hovers to the status bar
Browse files Browse the repository at this point in the history
  • Loading branch information
eamodio committed Nov 4, 2021
1 parent 89dbf6c commit 20e6bfe
Show file tree
Hide file tree
Showing 8 changed files with 179 additions and 50 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Expand Up @@ -8,6 +8,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p

### Added

- Adds a new rich commit details hover to the blame information in the status bar
- Adds a `gitlens.statusBar.tooltipFormat` setting to specify the format (in markdown) of hover shown over the blame information in the status bar
- Adds a new rich hover to the GitLens mode in the status bar
- Adds a new _Cherry Pick without Committing_ confirmation option to the _Git Command Palette_'s _cherry-pick_ command — closes [#1693](https://github.com/eamodio/vscode-gitlens/issues/1693)
- Adds new _Open File_ command (with _Open Revision_ as an `alt-click`) to files in comparisons — closes [#1710](https://github.com/eamodio/vscode-gitlens/issues/1710)

Expand Down
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -719,6 +719,7 @@ GitLens is highly customizable and provides many configuration settings to allow
| `gitlens.statusBar.format` | Specifies the format of the blame information in the status bar. See [_Commit Tokens_](https://github.com/eamodio/vscode-gitlens/wiki/Custom-Formatting#commit-tokens) in the GitLens docs. Date formatting is controlled by the `gitlens.statusBar.dateFormat` setting |
| `gitlens.statusBar.pullRequests.enabled` | Specifies whether to provide information about the Pull Request (if any) that introduced the commit in the status bar. Requires a connection to a supported remote service (e.g. GitHub) |
| `gitlens.statusBar.reduceFlicker` | Specifies whether to avoid clearing the previous blame information when changing lines to reduce status bar "flashing" |
| `gitlens.statusBar.tooltipFormat` | Specifies the format (in markdown) of hover shown over the blame information in the status bar. See [_Commit Tokens_](https://github.com/eamodio/vscode-gitlens/wiki/Custom-Formatting#commit-tokens) in the GitLens docs |

## Hover Settings [#](#hover-settings- 'Hover Settings')

Expand Down
6 changes: 6 additions & 0 deletions package.json
Expand Up @@ -1723,6 +1723,12 @@
"markdownDescription": "Specifies whether to avoid clearing the previous blame information when changing lines to reduce status bar \"flashing\"",
"scope": "window"
},
"gitlens.statusBar.tooltipFormat": {
"type": "string",
"default": "${avatar}  __${author}__, ${ago}${' via 'pullRequest}   _(${date})_ \n\n${message}\n\n${commands}${\n\n---\n\nfootnotes}",
"markdownDescription": "Specifies the format (in markdown) of hover shown over the blame information in the status bar. See [_Commit Tokens_](https://github.com/eamodio/vscode-gitlens/wiki/Custom-Formatting#commit-tokens) in the GitLens docs",
"scope": "window"
},
"gitlens.strings.codeLens.unsavedChanges.recentChangeAndAuthors": {
"type": "string",
"default": "$(ellipsis)",
Expand Down
7 changes: 7 additions & 0 deletions src/annotations/blameAnnotationProvider.ts
Expand Up @@ -194,7 +194,14 @@ export abstract class BlameAnnotationProviderBase extends AnnotationProviderBase
logCommit ?? commit,
await GitUri.fromUri(document.uri),
editorLine,
Container.config.hovers.detailsMarkdownFormat,
Container.config.defaultDateFormat,
{
autolinks: Container.config.hovers.autolinks.enabled,
pullRequests: {
enabled: Container.config.hovers.pullRequests.enabled,
},
},
);
}
}
Expand Down
1 change: 1 addition & 0 deletions src/config.ts
Expand Up @@ -134,6 +134,7 @@ export interface Config {
pullRequests: {
enabled: boolean;
};
tooltipFormat: string;
};
strings: {
codeLens: {
Expand Down
52 changes: 37 additions & 15 deletions src/hovers/hovers.ts
Expand Up @@ -12,6 +12,7 @@ import {
GitLogCommit,
GitRemote,
GitRevision,
PullRequest,
} from '../git/git';
import { GitUri } from '../git/gitUri';
import { Logger } from '../logger';
Expand Down Expand Up @@ -181,7 +182,19 @@ export namespace Hovers {
commit: GitCommit,
uri: GitUri,
editorLine: number,
format: string,
dateFormat: string | null,
options?: {
autolinks?: boolean;
pullRequests?: {
enabled: boolean;
pr?: PullRequest | Promises.CancellationError<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';
Expand All @@ -192,19 +205,32 @@ export namespace Hovers {
const [previousLineDiffUris, autolinkedIssuesOrPullRequests, pr, presence] = await Promise.all([
commit.isUncommitted ? commit.getPreviousLineDiffUris(uri, editorLine, uri.sha) : undefined,
getAutoLinkedIssuesOrPullRequests(commit.message, remotes),
getPullRequestForCommit(commit.ref, remotes),
options?.pullRequests?.pr ??
getPullRequestForCommit(commit.ref, remotes, {
pullRequests:
options?.pullRequests?.enabled ||
CommitFormatter.has(
format,
'pullRequest',
'pullRequestAgo',
'pullRequestAgoOrDate',
'pullRequestDate',
'pullRequestState',
),
}),
Container.vsls.maybeGetPresence(commit.email),
]);

const details = await CommitFormatter.fromTemplateAsync(Container.config.hovers.detailsMarkdownFormat, commit, {
const details = await CommitFormatter.fromTemplateAsync(format, commit, {
autolinkedIssuesOrPullRequests: autolinkedIssuesOrPullRequests,
dateFormat: dateFormat,
editor: {
line: editorLine,
uri: uri,
},
getBranchAndTagTips: options?.getBranchAndTagTips,
markdown: true,
messageAutolinks: Container.config.hovers.autolinks.enabled,
messageAutolinks: options?.autolinks,
pullRequestOrRemote: pr,
presence: presence,
previousLineDiffUris: previousLineDiffUris,
Expand Down Expand Up @@ -303,23 +329,19 @@ export namespace Hovers {
}
}

async function getPullRequestForCommit(ref: string, remotes: GitRemote[]) {
async function getPullRequestForCommit(
ref: string,
remotes: GitRemote[],
options?: {
pullRequests?: boolean;
},
) {
const cc = Logger.getNewCorrelationContext('Hovers.getPullRequestForCommit');
Logger.debug(cc, `${GlyphChars.Dash} ref=${ref}`);

const start = process.hrtime();

if (
!Container.config.hovers.pullRequests.enabled ||
!CommitFormatter.has(
Container.config.hovers.detailsMarkdownFormat,
'pullRequest',
'pullRequestAgo',
'pullRequestAgoOrDate',
'pullRequestDate',
'pullRequestState',
)
) {
if (!options?.pullRequests) {
Logger.debug(cc, `completed ${GlyphChars.Dot} ${Strings.getDurationMilliseconds(start)} ms`);

return undefined;
Expand Down
7 changes: 7 additions & 0 deletions src/hovers/lineHoverController.ts
Expand Up @@ -138,7 +138,14 @@ export class LineHoverController implements Disposable {
logCommit ?? commit,
trackedDocument.uri,
editorLine,
Container.config.hovers.detailsMarkdownFormat,
Container.config.defaultDateFormat,
{
autolinks: Container.config.hovers.autolinks.enabled,
pullRequests: {
enabled: Container.config.hovers.pullRequests.enabled,
},
},
);
return new Hover(message, range);
}
Expand Down

0 comments on commit 20e6bfe

Please sign in to comment.