Adds refresh for when timeline changes

This commit is contained in:
Eric Amodio
2020-01-22 15:42:43 -05:00
committed by Eric Amodio
parent 87c2332fed
commit d7b5fe4cc7
8 changed files with 144 additions and 21 deletions

View File

@@ -3,15 +3,25 @@
* 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 { CancellationToken, Disposable, Event, EventEmitter, ThemeIcon, TimelineItem, TimelineProvider, Uri, workspace } from 'vscode';
import { Model } from './model';
import { Repository } from './repository';
import { debounce } from './decorators';
export class GitTimelineProvider implements TimelineProvider {
private _onDidChange = new EventEmitter<Uri | undefined>();
get onDidChange(): Event<Uri | undefined> {
return this._onDidChange.event;
}
readonly source = 'git-history';
readonly sourceDescription = 'Git History';
private _disposable: Disposable;
private _repo: Repository | undefined;
private _repoDisposable: Disposable | undefined;
constructor(private readonly _model: Model) {
this._disposable = workspace.registerTimelineProvider('*', this);
}
@@ -21,12 +31,35 @@ export class GitTimelineProvider implements TimelineProvider {
}
async provideTimeline(uri: Uri, _since: number, _token: CancellationToken): Promise<TimelineItem[]> {
console.log(`GitTimelineProvider.provideTimeline: uri=${uri} state=${this._model.state}`);
const repo = this._model.getRepository(uri);
if (!repo) {
console.log(`GitTimelineProvider.provideTimeline: repo NOT found`);
this._repoDisposable?.dispose();
this._repo = undefined;
return [];
}
console.log(`GitTimelineProvider.provideTimeline: repo found`);
if (this._repo?.root !== repo.root) {
this._repoDisposable?.dispose();
this._repo = repo;
this._repoDisposable = Disposable.from(
repo.onDidChangeRepository(() => this.onRepositoryChanged(), this)
);
}
// TODO: Ensure that the uri is a file -- if not we could get the history of the repo?
const commits = await repo.logFile(uri, { maxEntries: 10 });
console.log(`GitTimelineProvider.provideTimeline: commits=${commits.length}`);
return commits.map<TimelineItem>(c => {
let message = c.message;
@@ -50,4 +83,11 @@ export class GitTimelineProvider implements TimelineProvider {
};
});
}
@debounce(500)
private onRepositoryChanged() {
console.log(`GitTimelineProvider.onRepositoryChanged`);
this._onDidChange.fire();
}
}