mirror of
https://github.com/ckaczor/vscode-gitlens.git
synced 2026-01-17 01:35:37 -05:00
Fixes #39 - adds date options for status bar blame
Adds data formatting option to blame annotations Preps v2.8.2
This commit is contained in:
@@ -208,7 +208,24 @@ export default class BlameActiveLineController extends Disposable {
|
||||
|
||||
async show(commit: GitCommit, blameLine: IGitCommitLine, editor: TextEditor) {
|
||||
if (this._config.statusBar.enabled) {
|
||||
this._statusBarItem.text = `$(git-commit) ${commit.author}, ${moment(commit.date).fromNow()}`;
|
||||
switch (this._config.statusBar.date) {
|
||||
case 'off':
|
||||
this._statusBarItem.text = `$(git-commit) ${commit.author}`;
|
||||
break;
|
||||
case 'absolute':
|
||||
const dateFormat = this._config.statusBar.dateFormat || 'MMMM Do, YYYY h:MMa';
|
||||
let date: string;
|
||||
try {
|
||||
date = moment(commit.date).format(dateFormat);
|
||||
} catch (ex) {
|
||||
date = moment(commit.date).format('MMMM Do, YYYY h:MMa');
|
||||
}
|
||||
this._statusBarItem.text = `$(git-commit) ${commit.author}, ${date}`;
|
||||
break;
|
||||
default:
|
||||
this._statusBarItem.text = `$(git-commit) ${commit.author}, ${moment(commit.date).fromNow()}`;
|
||||
break;
|
||||
}
|
||||
|
||||
switch (this._config.statusBar.command) {
|
||||
case StatusBarCommand.BlameAnnotate:
|
||||
|
||||
@@ -38,7 +38,7 @@ export default class BlameAnnotationFormatter {
|
||||
let message = this.getMessage(config, commit, format === BlameAnnotationFormat.Unconstrained ? 0 : defaultMessageLength);
|
||||
|
||||
if (format === BlameAnnotationFormat.Unconstrained) {
|
||||
const authorAndDate = this.getAuthorAndDate(config, commit, 'MMMM Do, YYYY h:MMa');
|
||||
const authorAndDate = this.getAuthorAndDate(config, commit, config.annotation.dateFormat || 'MMMM Do, YYYY h:MMa');
|
||||
if (config.annotation.sha) {
|
||||
message = `${sha}${(authorAndDate ? `${cssPadding}${cssSeparator}${cssPadding}${authorAndDate}` : '')}${(message ? `${cssPadding}${cssSeparator}${cssPadding}${message}` : '')}`;
|
||||
}
|
||||
@@ -50,7 +50,7 @@ export default class BlameAnnotationFormatter {
|
||||
}
|
||||
|
||||
const author = this.getAuthor(config, commit, defaultAuthorLength);
|
||||
const date = this.getDate(config, commit, 'MM/DD/YYYY', true);
|
||||
const date = this.getDate(config, commit, config.annotation.dateFormat || 'MM/DD/YYYY', true);
|
||||
if (config.annotation.sha) {
|
||||
message = `${sha}${(author ? `${cssPadding}${cssSeparator}${cssPadding}${author}` : '')}${(date ? `${cssPadding}${cssSeparator}${cssPadding}${date}` : '')}${(message ? `${cssPadding}${cssSeparator}${cssPadding}${message}` : '')}`;
|
||||
}
|
||||
@@ -70,10 +70,10 @@ export default class BlameAnnotationFormatter {
|
||||
return `\`${'0'.repeat(8)}\` __Uncommitted changes__`;
|
||||
}
|
||||
|
||||
return `\`${commit.sha}\` __${commit.author}__, ${moment(commit.date).fromNow()} _(${moment(commit.date).format('MMMM Do, YYYY h:MMa')})_ \n\n${message}`;
|
||||
return `\`${commit.sha}\` __${commit.author}__, ${moment(commit.date).fromNow()} _(${moment(commit.date).format(config.annotation.dateFormat || 'MMMM Do, YYYY h:MMa')})_ \n\n${message}`;
|
||||
}
|
||||
|
||||
static getAuthorAndDate(config: IBlameConfig, commit: GitCommit, format?: string, force: boolean = false) {
|
||||
static getAuthorAndDate(config: IBlameConfig, commit: GitCommit, format: string, force: boolean = false) {
|
||||
if (!force && !config.annotation.author && (!config.annotation.date || config.annotation.date === 'off')) return '';
|
||||
|
||||
if (!config.annotation.author) {
|
||||
@@ -101,7 +101,7 @@ export default class BlameAnnotationFormatter {
|
||||
return author + cssPadding.repeat(truncateTo - author.length);
|
||||
}
|
||||
|
||||
static getDate(config: IBlameConfig, commit: GitCommit, format?: string, truncate: boolean = false, force: boolean = false) {
|
||||
static getDate(config: IBlameConfig, commit: GitCommit, format: string, truncate: boolean = false, force: boolean = false) {
|
||||
if (!force && (!config.annotation.date || config.annotation.date === 'off')) return '';
|
||||
|
||||
const date = config.annotation.date === 'relative'
|
||||
|
||||
@@ -157,7 +157,7 @@ export class BlameAnnotationProvider extends Disposable {
|
||||
gutter = `${cssIndent} ${BlameAnnotationFormatter.getAuthor(this._config, commit, defaultAuthorLength, true)}`;
|
||||
break;
|
||||
case 2:
|
||||
gutter = `${cssIndent} ${BlameAnnotationFormatter.getDate(this._config, commit, 'MM/DD/YYYY', true, true)}`;
|
||||
gutter = `${cssIndent} ${BlameAnnotationFormatter.getDate(this._config, commit, this._config.annotation.dateFormat || 'MM/DD/YYYY', true, true)}`;
|
||||
break;
|
||||
default:
|
||||
gutter = `${cssIndent}`;
|
||||
|
||||
@@ -16,6 +16,7 @@ export interface IBlameConfig {
|
||||
sha: boolean;
|
||||
author: boolean;
|
||||
date: 'off' | 'relative' | 'absolute';
|
||||
dateFormat: string;
|
||||
message: boolean;
|
||||
activeLine: 'off' | 'inline' | 'hover' | 'both';
|
||||
characters: {
|
||||
@@ -89,6 +90,8 @@ export const StatusBarCommand = {
|
||||
export interface IStatusBarConfig {
|
||||
enabled: boolean;
|
||||
command: StatusBarCommand;
|
||||
date: 'off' | 'relative' | 'absolute';
|
||||
dateFormat: string;
|
||||
}
|
||||
|
||||
export interface IAdvancedConfig {
|
||||
|
||||
Reference in New Issue
Block a user