@@ -8,15 +8,19 @@ import { Event, Emitter } from 'vs/base/common/event';
88import { IDisposable } from 'vs/base/common/lifecycle' ;
99import { URI } from 'vs/base/common/uri' ;
1010import { ILogService } from 'vs/platform/log/common/log' ;
11- import { ITimelineService , TimelineProvider } from './timeline' ;
11+ import { ITimelineService , TimelineProvider , TimelineItem } from './timeline' ;
1212
1313export 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
110131function * map < T , TMapped > ( source : Iterable < T > | IterableIterator < T > , mapper : ( item : T ) => TMapped ) : Iterable < TMapped > {
0 commit comments