Skip to content

Commit d7b5fe4

Browse files
Eric Amodioeamodio
authored andcommitted
Adds refresh for when timeline changes
1 parent 87c2332 commit d7b5fe4

8 files changed

Lines changed: 144 additions & 21 deletions

File tree

extensions/git/src/timelineProvider.ts

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,25 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6-
import { CancellationToken, Disposable, TimelineItem, TimelineProvider, Uri, workspace, ThemeIcon } from 'vscode';
6+
import { CancellationToken, Disposable, Event, EventEmitter, ThemeIcon, TimelineItem, TimelineProvider, Uri, workspace } from 'vscode';
77
import { Model } from './model';
8+
import { Repository } from './repository';
9+
import { debounce } from './decorators';
810

911
export class GitTimelineProvider implements TimelineProvider {
12+
private _onDidChange = new EventEmitter<Uri | undefined>();
13+
get onDidChange(): Event<Uri | undefined> {
14+
return this._onDidChange.event;
15+
}
16+
1017
readonly source = 'git-history';
1118
readonly sourceDescription = 'Git History';
1219

1320
private _disposable: Disposable;
1421

22+
private _repo: Repository | undefined;
23+
private _repoDisposable: Disposable | undefined;
24+
1525
constructor(private readonly _model: Model) {
1626
this._disposable = workspace.registerTimelineProvider('*', this);
1727
}
@@ -21,12 +31,35 @@ export class GitTimelineProvider implements TimelineProvider {
2131
}
2232

2333
async provideTimeline(uri: Uri, _since: number, _token: CancellationToken): Promise<TimelineItem[]> {
34+
console.log(`GitTimelineProvider.provideTimeline: uri=${uri} state=${this._model.state}`);
35+
2436
const repo = this._model.getRepository(uri);
2537
if (!repo) {
38+
console.log(`GitTimelineProvider.provideTimeline: repo NOT found`);
39+
40+
this._repoDisposable?.dispose();
41+
this._repo = undefined;
42+
2643
return [];
2744
}
2845

46+
console.log(`GitTimelineProvider.provideTimeline: repo found`);
47+
48+
if (this._repo?.root !== repo.root) {
49+
this._repoDisposable?.dispose();
50+
51+
this._repo = repo;
52+
this._repoDisposable = Disposable.from(
53+
repo.onDidChangeRepository(() => this.onRepositoryChanged(), this)
54+
);
55+
}
56+
57+
// TODO: Ensure that the uri is a file -- if not we could get the history of the repo?
58+
2959
const commits = await repo.logFile(uri, { maxEntries: 10 });
60+
61+
console.log(`GitTimelineProvider.provideTimeline: commits=${commits.length}`);
62+
3063
return commits.map<TimelineItem>(c => {
3164
let message = c.message;
3265

@@ -50,4 +83,11 @@ export class GitTimelineProvider implements TimelineProvider {
5083
};
5184
});
5285
}
86+
87+
@debounce(500)
88+
private onRepositoryChanged() {
89+
console.log(`GitTimelineProvider.onRepositoryChanged`);
90+
91+
this._onDidChange.fire();
92+
}
5393
}

src/vs/vscode.proposed.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1549,7 +1549,7 @@ declare module 'vscode' {
15491549
// onDidAdd?: Event<TimelimeAddEvent>;
15501550
// onDidChange?: Event<TimelimeChangeEvent>;
15511551

1552-
onDidChange?: Event<void>;
1552+
onDidChange?: Event<Uri | undefined>;
15531553

15541554
/**
15551555
* An identifier of the source of the timeline items. This can be used for filtering and/or overriding existing sources.

src/vs/workbench/api/browser/mainThreadTimeline.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@ import { extHostNamedCustomer } from 'vs/workbench/api/common/extHostCustomers';
88
import { ITimelineService, TimelineItem, TimelineProviderDescriptor } from 'vs/workbench/contrib/timeline/common/timeline';
99
import { URI } from 'vs/base/common/uri';
1010
import { CancellationToken } from 'vs/base/common/cancellation';
11+
import { Emitter } from 'vs/base/common/event';
1112

1213
@extHostNamedCustomer(MainContext.MainThreadTimeline)
1314
export class MainThreadTimeline implements MainThreadTimelineShape {
1415
private readonly _proxy: ExtHostTimelineShape;
16+
private readonly _providerEmitters = new Map<string, Emitter<URI | undefined>>();
1517

1618
constructor(
1719
context: IExtHostContext,
@@ -29,12 +31,24 @@ export class MainThreadTimeline implements MainThreadTimelineShape {
2931

3032
const proxy = this._proxy;
3133

34+
const emitters = this._providerEmitters;
35+
let onDidChange = emitters.get(provider.source);
36+
// eslint-disable-next-line eqeqeq
37+
if (onDidChange == null) {
38+
onDidChange = new Emitter<URI | undefined>();
39+
emitters.set(provider.source, onDidChange);
40+
}
41+
3242
this._timelineService.registerTimelineProvider({
3343
...provider,
44+
onDidChange: onDidChange.event,
3445
provideTimeline(uri: URI, since: number, token: CancellationToken) {
3546
return proxy.$getTimeline(provider.source, uri, since, token);
3647
},
37-
dispose() { }
48+
dispose() {
49+
emitters.delete(provider.source);
50+
onDidChange?.dispose();
51+
}
3852
});
3953
}
4054

@@ -43,6 +57,13 @@ export class MainThreadTimeline implements MainThreadTimelineShape {
4357
this._timelineService.unregisterTimelineProvider(source);
4458
}
4559

60+
$emitTimelineChangeEvent(source: string, uri: URI | undefined): void {
61+
console.log(`MainThreadTimeline#emitChangeEvent: source=${source} uri=${uri?.toString(true)}`);
62+
63+
const emitter = this._providerEmitters.get(source);
64+
emitter?.fire(uri);
65+
}
66+
4667
dispose(): void {
4768
// noop
4869
}

src/vs/workbench/api/common/extHost.protocol.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -801,8 +801,9 @@ export interface MainThreadTunnelServiceShape extends IDisposable {
801801
export interface MainThreadTimelineShape extends IDisposable {
802802
$registerTimelineProvider(provider: TimelineProviderDescriptor): void;
803803
$unregisterTimelineProvider(source: string): void;
804+
$emitTimelineChangeEvent(source: string, uri: UriComponents | undefined): void;
804805

805-
$getTimeline(resource: UriComponents, since: number, token: CancellationToken): Promise<TimelineItem[]>;
806+
$getTimeline(uri: UriComponents, since: number, token: CancellationToken): Promise<TimelineItem[]>;
806807
}
807808

808809
// -- extension host

src/vs/workbench/api/common/extHostTimeline.ts

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,20 @@ export class ExtHostTimeline implements IExtHostTimeline {
3939
}
4040

4141
registerTimelineProvider(provider: vscode.TimelineProvider, commandConverter: CommandsConverter): IDisposable {
42-
const disposables = new DisposableStore();
42+
const timelineDisposables = new DisposableStore();
43+
44+
const convertTimelineItem = this.convertTimelineItem(provider.source, commandConverter, timelineDisposables);
45+
46+
let disposable: IDisposable | undefined;
47+
if (provider.onDidChange) {
48+
console.log(`ExtHostTimeline#registerTimelineProvider: provider=${provider.source} hooking up onDidChange`);
49+
disposable = provider.onDidChange(this.emitTimelineChangeEvent(provider.source), this);
50+
}
4351

44-
const convertTimelineItem = this.convertTimelineItem(provider.source, commandConverter, disposables);
4552
return this.registerTimelineProviderCore({
4653
...provider,
4754
async provideTimeline(uri: URI, since: number, token: CancellationToken) {
48-
disposables.clear();
55+
timelineDisposables.clear();
4956

5057
const results = await provider.provideTimeline(uri, since, token);
5158
// eslint-disable-next-line eqeqeq
@@ -54,7 +61,8 @@ export class ExtHostTimeline implements IExtHostTimeline {
5461
: [];
5562
},
5663
dispose() {
57-
disposables.dispose();
64+
disposable?.dispose();
65+
timelineDisposables.dispose();
5866
}
5967
});
6068
}
@@ -90,6 +98,13 @@ export class ExtHostTimeline implements IExtHostTimeline {
9098
};
9199
}
92100

101+
private emitTimelineChangeEvent(source: string) {
102+
return (uri: vscode.Uri | undefined) => {
103+
console.log(`ExtHostTimeline#registerTimelineProvider: provider=${source} onDidChange fired; uri=${uri?.toString(true)}`);
104+
this._proxy.$emitTimelineChangeEvent(source, uri);
105+
};
106+
}
107+
93108
private registerTimelineProviderCore(provider: TimelineProvider): IDisposable {
94109
console.log(`ExtHostTimeline#registerTimelineProvider: provider=${provider.source}`);
95110

src/vs/workbench/contrib/timeline/browser/timelinePane.ts

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { IconLabel } from 'vs/base/browser/ui/iconLabel/iconLabel';
1414
import { IListVirtualDelegate, IIdentityProvider, IKeyboardNavigationLabelProvider } from 'vs/base/browser/ui/list/list';
1515
import { ITreeNode, ITreeRenderer } from 'vs/base/browser/ui/tree/tree';
1616
import { ViewPane, IViewPaneOptions } from 'vs/workbench/browser/parts/views/viewPaneContainer';
17-
import { WorkbenchObjectTree, TreeResourceNavigator } from 'vs/platform/list/browser/listService';
17+
import { TreeResourceNavigator, WorkbenchObjectTree } from 'vs/platform/list/browser/listService';
1818
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
1919
import { IContextMenuService } from 'vs/platform/contextview/browser/contextView';
2020
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
@@ -62,17 +62,32 @@ export class TimelinePane extends ViewPane {
6262
uri = toResource(editor, { supportSideBySide: SideBySideEditor.MASTER });
6363
}
6464

65+
console.log(`TimelinePane.onActiveEditorChanged: uri=${uri?.toString(true)}`);
66+
6567
this.updateUri(uri);
6668
}
6769

6870
private onProvidersChanged() {
71+
console.log(`TimelinePane.onProvidersChanged`);
72+
6973
this.refresh();
7074
}
7175

76+
private onTimelineChanged(uri: URI | undefined) {
77+
console.log(`TimelinePane.onTimelineChanged: uri=${uri?.toString(true)} this._uri=${this._uri?.toString(true)}`);
78+
79+
// eslint-disable-next-line eqeqeq
80+
if (uri == null || uri.toString(true) !== this._uri?.toString(true)) {
81+
this.refresh();
82+
}
83+
}
84+
7285
private async refresh() {
7386
this._tokenSource?.cancel();
7487
this._tokenSource = new CancellationTokenSource();
7588

89+
console.log(`TimelinePane.refresh: uri=${this._uri?.toString(true)}`);
90+
7691
// TODO: Deal with no uri -- use a view title? or keep the last one cached?
7792
// TODO: Deal with no items -- use a view title?
7893

@@ -89,9 +104,12 @@ export class TimelinePane extends ViewPane {
89104

90105
private updateUri(uri: URI | undefined) {
91106
if (uri?.toString(true) === this._uri?.toString(true)) {
107+
console.log(`TimelinePane.updateUri(same): uri=${uri?.toString(true)}`);
108+
92109
return;
93110
}
94111

112+
console.log(`TimelinePane.updateUri: uri=${uri?.toString(true)}`);
95113
this._uri = uri;
96114
this.refresh();
97115
}
@@ -102,12 +120,15 @@ export class TimelinePane extends ViewPane {
102120
}
103121

104122
setVisible(visible: boolean): void {
123+
console.log(`TimelinePane.setVisible: visible=${visible}`);
124+
105125
if (visible) {
106126
this._visibilityDisposables = new DisposableStore();
107127

108128
this.timelineService.onDidChangeProviders(this.onProvidersChanged, this, this._visibilityDisposables);
109-
129+
this.timelineService.onDidChangeTimeline(this.onTimelineChanged, this, this._visibilityDisposables);
110130
this.editorService.onDidActiveEditorChange(this.onActiveEditorChanged, this, this._visibilityDisposables);
131+
111132
this.onActiveEditorChanged();
112133
} else {
113134
this._visibilityDisposables?.dispose();

src/vs/workbench/contrib/timeline/common/timeline.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ export interface TimelineItemWithSource extends TimelineItem {
3333
}
3434

3535
export interface TimelineProvider extends TimelineProviderDescriptor, IDisposable {
36+
onDidChange?: Event<URI | undefined>;
37+
3638
provideTimeline(uri: URI, since: number, token: CancellationToken): Promise<TimelineItem[]>;
3739
}
3840

@@ -48,6 +50,8 @@ export interface ITimelineService {
4850
readonly _serviceBrand: undefined;
4951

5052
onDidChangeProviders: Event<void>;
53+
onDidChangeTimeline: Event<URI | undefined>;
54+
5155
registerTimelineProvider(provider: TimelineProvider): IDisposable;
5256
unregisterTimelineProvider(source: string): void;
5357

src/vs/workbench/contrib/timeline/common/timelineService.ts

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,19 @@ import { Event, Emitter } from 'vs/base/common/event';
88
import { IDisposable } from 'vs/base/common/lifecycle';
99
import { URI } from 'vs/base/common/uri';
1010
import { ILogService } from 'vs/platform/log/common/log';
11-
import { ITimelineService, TimelineProvider } from './timeline';
11+
import { ITimelineService, TimelineProvider, TimelineItem } from './timeline';
1212

1313
export class TimelineService implements ITimelineService {
1414
_serviceBrand: undefined;
1515

1616
private readonly _onDidChangeProviders = new Emitter<void>();
1717
readonly onDidChangeProviders: Event<void> = this._onDidChangeProviders.event;
1818

19+
private readonly _onDidChangeTimeline = new Emitter<URI | undefined>();
20+
readonly onDidChangeTimeline: Event<URI | undefined> = this._onDidChangeTimeline.event;
21+
1922
private readonly _providers = new Map<string, TimelineProvider>();
23+
private readonly _providerSubscriptions = new Map<string, IDisposable>();
2024

2125
constructor(@ILogService private readonly logService: ILogService) {
2226
this.registerTimelineProvider({
@@ -42,27 +46,34 @@ export class TimelineService implements ITimelineService {
4246
});
4347
}
4448

45-
// TODO: Add filtering
46-
async getTimeline(uri: URI, since: number, token: CancellationToken) {
49+
async getTimeline(uri: URI, since: number, token: CancellationToken, sources?: Set<string>) {
4750
this.logService.trace(`TimelineService#getTimeline: uri=${uri.toString(true)}`);
48-
const requests = [];
51+
52+
console.log(`TimelineService.getTimeline providers=${this._providers.size}`);
53+
54+
const requests = new Map<string, Promise<TimelineItem[] | CancellationErrorWithId<string>>>();
4955

5056
for (const provider of this._providers.values()) {
51-
requests.push(
52-
provider.provideTimeline(uri, since, token).then(items => ({ source: provider.source, items: items }))
53-
);
57+
if (sources && !sources.has(provider.source)) {
58+
continue;
59+
}
60+
61+
requests.set(provider.source, provider.provideTimeline(uri, since, token));
5462
}
5563

5664
const timelines = await raceAll(requests /*, 5000*/);
5765

66+
console.log(`TimelineService.getTimeline timelines=${timelines.size}`);
67+
5868
const timeline = [];
59-
for (const result of timelines) {
60-
// eslint-disable-next-line eqeqeq
61-
if (result == null || result instanceof CancellationError) {
69+
for (const [source, items] of timelines) {
70+
if (items instanceof CancellationError) {
71+
console.log(`TimelineService.getTimeline source=${source} cancelled`);
6272
continue;
6373
}
6474

65-
const { source, items } = result;
75+
console.log(`TimelineService.getTimeline source=${source} items=${items.length}`);
76+
6677
if (items.length === 0) {
6778
continue;
6879
}
@@ -85,6 +96,9 @@ export class TimelineService implements ITimelineService {
8596
}
8697

8798
this._providers.set(source, provider);
99+
if (provider.onDidChange) {
100+
this._providerSubscriptions.set(source, provider.onDidChange(uri => this.onProviderTimelineChanged(provider.source, uri)));
101+
}
88102
this._onDidChangeProviders.fire();
89103

90104
return {
@@ -103,8 +117,15 @@ export class TimelineService implements ITimelineService {
103117
}
104118

105119
this._providers.delete(source);
120+
this._providerSubscriptions.delete(source);
106121
this._onDidChangeProviders.fire();
107122
}
123+
124+
private onProviderTimelineChanged(source: string, uri: URI | undefined) {
125+
console.log(`TimelineService.onProviderTimelineChanged: source=${source} uri=${uri?.toString(true)}`);
126+
127+
this._onDidChangeTimeline.fire(uri);
128+
}
108129
}
109130

110131
function* map<T, TMapped>(source: Iterable<T> | IterableIterator<T>, mapper: (item: T) => TMapped): Iterable<TMapped> {

0 commit comments

Comments
 (0)