Skip to content

Commit 593da8c

Browse files
committed
Adds new advanced date formatting tokens
- Adds `agoAndDate`, `agoAndDateShort`, and `agoAndDateBothSources` - `agoAndDateBothSources` shows relative and absolute date and the corresponding author/committer relative date (if they differ) - Updates default tooltip and status bar formats to utilize these new tokens
1 parent 814c2f0 commit 593da8c

File tree

4 files changed

+57
-15
lines changed

4 files changed

+57
-15
lines changed

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@
440440
},
441441
"gitlens.statusBar.tooltipFormat": {
442442
"type": "string",
443-
"default": "${avatar}  __${author}__  $(history) ${ago} _(${date})_${' via 'pullRequest} ${message}${\n\n---\n\nfootnotes}\n\n${commands}",
443+
"default": "${avatar}  __${author}__  $(history) ${agoAndDateBothSources}${' via 'pullRequest} ${message}${\n\n---\n\nfootnotes}\n\n${commands}",
444444
"editPresentation": "multilineText",
445445
"markdownDescription": "Specifies the format (in markdown) of hover shown over the blame information in the status bar. See [_Commit Tokens_](https://github.com/gitkraken/vscode-gitlens/wiki/Custom-Formatting#commit-tokens) in the GitLens docs",
446446
"scope": "window",
@@ -586,7 +586,7 @@
586586
},
587587
"gitlens.hovers.detailsMarkdownFormat": {
588588
"type": "string",
589-
"default": "${avatar}  __${author}__  $(history) ${ago} _(${date})_${' via 'pullRequest} ${message}${\n\n---\n\nfootnotes}\n\n${commands}",
589+
"default": "${avatar}  __${author}__  $(history) ${agoAndDateBothSources}${' via 'pullRequest} ${message}${\n\n---\n\nfootnotes}\n\n${commands}",
590590
"editPresentation": "multilineText",
591591
"markdownDescription": "Specifies the format (in markdown) of the _commit details_ hover. See [_Commit Tokens_](https://github.com/gitkraken/vscode-gitlens/wiki/Custom-Formatting#commit-tokens) in the GitLens docs",
592592
"scope": "window",
@@ -1746,14 +1746,14 @@
17461746
},
17471747
"gitlens.views.formats.commits.tooltip": {
17481748
"type": "string",
1749-
"default": "${avatar}  __${author}__  $(history) ${ago} _(${date})_ \\\n${link}${' via 'pullRequest}${'  'changesDetail} ${message}${\n\n---\n\nfootnotes}\n\n${tips}",
1749+
"default": "${avatar}  __${author}__  $(history) ${agoAndDateBothSources} \\\n${link}${' via 'pullRequest}${'  'changesDetail} ${message}${\n\n---\n\nfootnotes}\n\n${tips}",
17501750
"markdownDescription": "Specifies the tooltip format (in markdown) of commits in the views. See [_Commit Tokens_](https://github.com/eamodio/vscode-gitlens/wiki/Custom-Formatting#commit-tokens) in the GitLens docs",
17511751
"scope": "window",
17521752
"order": 32
17531753
},
17541754
"gitlens.views.formats.commits.tooltipWithStatus": {
17551755
"type": "string",
1756-
"default": "${avatar}  __${author}__  $(history) ${ago} _(${date})_ \\\n${link}${' via 'pullRequest}  •  {{slot-status}} ${message}${\n\n---\n\nfootnotes}\n\n${tips}",
1756+
"default": "${avatar}  __${author}__  $(history) ${agoAndDateBothSources} \\\n${link}${' via 'pullRequest}  •  {{slot-status}} ${message}${\n\n---\n\nfootnotes}\n\n${tips}",
17571757
"markdownDescription": "Specifies the tooltip format (in markdown) of \"file\" commits in the views. See [_Commit Tokens_](https://github.com/eamodio/vscode-gitlens/wiki/Custom-Formatting#commit-tokens) in the GitLens docs",
17581758
"scope": "window",
17591759
"order": 32
@@ -1788,7 +1788,7 @@
17881788
},
17891789
"gitlens.views.formats.stashes.tooltip": {
17901790
"type": "string",
1791-
"default": "${link}${' on `'stashOnRef`}${'\\\n  'changesDetail} \\\n  $(history) ${ago} _(${date})_ ${message}${\n\n---\n\nfootnotes}",
1791+
"default": "${link}${' on `'stashOnRef`}${'\\\n  'changesDetail} \\\n  $(history) ${agoAndDate} ${message}${\n\n---\n\nfootnotes}",
17921792
"markdownDescription": "Specifies the tooltip format (in markdown) of stashes in the views. See [_Commit Tokens_](https://github.com/eamodio/vscode-gitlens/wiki/Custom-Formatting#commit-tokens) in the GitLens docs",
17931793
"scope": "window",
17941794
"order": 52

src/container.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { setDefaultGravatarsStyle } from './avatars';
1717
import { CacheProvider } from './cache';
1818
import { GitCodeLensController } from './codelens/codeLensController';
1919
import type { ToggleFileAnnotationCommandArgs } from './commands/toggleFileAnnotations';
20-
import type { DateStyle, FileAnnotationType, Mode } from './config';
20+
import type { DateSource, DateStyle, FileAnnotationType, Mode } from './config';
2121
import { fromOutputLevel } from './config';
2222
import { extensionPrefix } from './constants';
2323
import type { GlCommands } from './constants.commands';
@@ -137,8 +137,8 @@ export class Container {
137137

138138
readonly CommitDateFormatting = {
139139
dateFormat: null as string | null,
140-
dateSource: 'authored',
141-
dateStyle: 'relative',
140+
dateSource: 'authored' as DateSource,
141+
dateStyle: 'relative' as DateStyle,
142142

143143
reset: (): void => {
144144
this.CommitDateFormatting.dateFormat = configuration.get('defaultDateFormat');

src/git/formatters/commitFormatter.ts

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { OpenFileAtRevisionCommand } from '../../commands/openFileAtRevision';
1717
import { ConnectRemoteProviderCommand } from '../../commands/remoteProviders';
1818
import type { ShowQuickCommitCommandArgs } from '../../commands/showQuickCommit';
1919
import { ShowQuickCommitFileCommand } from '../../commands/showQuickCommitFile';
20-
import type { DateStyle } from '../../config';
20+
import type { DateSource, DateStyle } from '../../config';
2121
import { GlyphChars } from '../../constants';
2222
import { actionCommandPrefix } from '../../constants.commands';
2323
import { Container } from '../../container';
@@ -51,6 +51,7 @@ import { Formatter } from './formatter';
5151
export interface CommitFormatOptions extends FormatOptions {
5252
aiEnabled?: boolean;
5353
avatarSize?: number;
54+
dateSource?: DateSource;
5455
dateStyle?: DateStyle;
5556
editor?: { line: number; uri: Uri };
5657
footnotes?: Map<number, string>;
@@ -86,6 +87,9 @@ export interface CommitFormatOptions extends FormatOptions {
8687
ago?: TokenOptions;
8788
agoOrDate?: TokenOptions;
8889
agoOrDateShort?: TokenOptions;
90+
agoAndDate?: TokenOptions;
91+
agoAndDateShort?: TokenOptions;
92+
agoAndDateBothSources?: TokenOptions;
8993
author?: TokenOptions;
9094
authorFirst?: TokenOptions;
9195
authorLast?: TokenOptions;
@@ -211,6 +215,49 @@ export class CommitFormatter extends Formatter<GitCommit, CommitFormatOptions> {
211215
);
212216
}
213217

218+
get agoAndDate(): string {
219+
return this._padOrTruncate(
220+
this._options.outputFormat === 'markdown'
221+
? `${this._dateAgo} _(${this._date})_`
222+
: `${this._dateAgo} (${this._date})`,
223+
this._options.tokenOptions.agoAndDate,
224+
);
225+
}
226+
227+
get agoAndDateBothSources(): string {
228+
const committerAgo = this.committerAgo;
229+
const committerDate = this.committerDate;
230+
const authorAgo = this.authorAgo;
231+
const authorDate = this.authorDate;
232+
233+
const source = this._options.dateSource ?? configuration.get('defaultDateSource');
234+
235+
if (source === 'committed') {
236+
return this._padOrTruncate(
237+
this._options.outputFormat === 'markdown'
238+
? `${committerAgo} _(${committerDate}${committerAgo === authorAgo ? '' : `, authored ${authorAgo}`})_`
239+
: `${committerAgo} (${committerDate}${committerAgo === authorAgo ? '' : `, authored ${authorAgo}`})`,
240+
this._options.tokenOptions.agoAndDateBothSources,
241+
);
242+
}
243+
244+
return this._padOrTruncate(
245+
this._options.outputFormat === 'markdown'
246+
? `${authorAgo} _(${authorDate}${committerAgo === authorAgo ? '' : `, committed ${committerAgo}`})_`
247+
: `${authorAgo} (${authorDate}${committerAgo === authorAgo ? '' : `, committed ${committerAgo}`})`,
248+
this._options.tokenOptions.agoAndDateBothSources,
249+
);
250+
}
251+
252+
get agoAndDateShort(): string {
253+
return this._padOrTruncate(
254+
this._options.outputFormat === 'markdown'
255+
? `${this._dateAgoShort} _(${this._date})_`
256+
: `${this._dateAgoShort} (${this._date})`,
257+
this._options.tokenOptions.agoAndDateShort,
258+
);
259+
}
260+
214261
get author(): string {
215262
return this.formatAuthor(this._item.author.name, this._item.author.email, this._options.tokenOptions.author);
216263
}

src/webviews/plus/graph/graphWebview.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1313,12 +1313,7 @@ export class GraphWebviewProvider implements WebviewProvider<State, State, Graph
13131313
pr = getSettledValue(prResult);
13141314
}
13151315

1316-
let template;
1317-
if (isStash(commit)) {
1318-
template = configuration.get('views.formats.stashes.tooltip');
1319-
} else {
1320-
template = configuration.get('views.formats.commits.tooltip');
1321-
}
1316+
const template = configuration.get(`views.formats.${isStash(commit) ? 'stashes' : 'commits'}.tooltip`);
13221317

13231318
this._getBranchesAndTagsTips ??= await svc.getBranchesAndTagsTipsLookup();
13241319

0 commit comments

Comments
 (0)