Adds timeline diff on click and icon support

This commit is contained in:
Eric Amodio
2020-01-17 17:19:52 -05:00
committed by Eric Amodio
parent 70e1e9b4f4
commit 87c2332fed
17 changed files with 424 additions and 248 deletions

View File

@@ -0,0 +1,53 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { CancellationToken, Disposable, TimelineItem, TimelineProvider, Uri, workspace, ThemeIcon } from 'vscode';
import { Model } from './model';
export class GitTimelineProvider implements TimelineProvider {
readonly source = 'git-history';
readonly sourceDescription = 'Git History';
private _disposable: Disposable;
constructor(private readonly _model: Model) {
this._disposable = workspace.registerTimelineProvider('*', this);
}
dispose() {
this._disposable.dispose();
}
async provideTimeline(uri: Uri, _since: number, _token: CancellationToken): Promise<TimelineItem[]> {
const repo = this._model.getRepository(uri);
if (!repo) {
return [];
}
const commits = await repo.logFile(uri, { maxEntries: 10 });
return commits.map<TimelineItem>(c => {
let message = c.message;
const index = message.indexOf('\n');
if (index !== -1) {
message = `${message.substring(0, index)} \u2026`;
}
return {
id: c.hash,
date: c.authorDate?.getTime() ?? 0,
iconPath: new ThemeIcon('git-commit'),
label: message,
description: `${c.authorName} (${c.authorEmail}) \u2022 ${c.hash.substr(0, 8)}`,
detail: `${c.authorName} (${c.authorEmail})\n${c.authorDate}\n\n${c.message}`,
command: {
title: 'Open Diff',
command: 'git.openDiff',
arguments: [uri, c.hash]
}
};
});
}
}