77import URI , { UriComponents } from 'vs/base/common/uri' ;
88import { Emitter } from 'vs/base/common/event' ;
99import { IDisposable , dispose } from 'vs/base/common/lifecycle' ;
10- import { ExtHostContext , MainContext , IExtHostContext , MainThreadDecorationsShape , ExtHostDecorationsShape } from '../node/extHost.protocol' ;
10+ import { ExtHostContext , MainContext , IExtHostContext , MainThreadDecorationsShape , ExtHostDecorationsShape , DecorationData , DecorationRequest } from '../node/extHost.protocol' ;
1111import { extHostNamedCustomer } from 'vs/workbench/api/electron-browser/extHostCustomers' ;
1212import { IDecorationsService , IDecorationData } from 'vs/workbench/services/decorations/browser/decorations' ;
1313
14+ class DecorationRequestsQueue {
15+
16+ private _idPool = 0 ;
17+ private _requests : DecorationRequest [ ] = [ ] ;
18+ private _resolver : { [ id : number ] : Function } = Object . create ( null ) ;
19+
20+ private _timer : number ;
21+
22+ constructor (
23+ private _proxy : ExtHostDecorationsShape
24+ ) {
25+ //
26+ }
27+
28+ enqueue ( handle : number , uri : URI ) : Thenable < DecorationData > {
29+ return new Promise ( ( resolve , reject ) => {
30+ const id = ++ this . _idPool ;
31+ this . _requests . push ( { id, handle, uri } ) ;
32+ this . _resolver [ id ] = resolve ;
33+ this . _processQueue ( ) ;
34+ } ) ;
35+ }
36+
37+ private _processQueue ( ) : void {
38+ if ( typeof this . _timer === 'number' ) {
39+ // already queued
40+ return ;
41+ }
42+ this . _timer = setTimeout ( ( ) => {
43+ // make request
44+ const requests = this . _requests ;
45+ const resolver = this . _resolver ;
46+ this . _proxy . $provideDecorations ( requests ) . then ( data => {
47+ for ( const id in resolver ) {
48+ resolver [ id ] ( data [ id ] ) ;
49+ }
50+ } ) ;
51+
52+ // reset
53+ this . _requests = [ ] ;
54+ this . _resolver = [ ] ;
55+ this . _timer = void 0 ;
56+ } , 0 ) ;
57+ }
58+ }
59+
1460@extHostNamedCustomer ( MainContext . MainThreadDecorations )
1561export class MainThreadDecorations implements MainThreadDecorationsShape {
1662
1763 private readonly _provider = new Map < number , [ Emitter < URI [ ] > , IDisposable ] > ( ) ;
1864 private readonly _proxy : ExtHostDecorationsShape ;
65+ private readonly _requestQueue : DecorationRequestsQueue ;
1966
2067 constructor (
2168 context : IExtHostContext ,
2269 @IDecorationsService private readonly _decorationsService : IDecorationsService
2370 ) {
2471 this . _proxy = context . getProxy ( ExtHostContext . ExtHostDecorations ) ;
72+ this . _requestQueue = new DecorationRequestsQueue ( this . _proxy ) ;
2573 }
2674
2775 dispose ( ) {
@@ -30,12 +78,12 @@ export class MainThreadDecorations implements MainThreadDecorationsShape {
3078 }
3179
3280 $registerDecorationProvider ( handle : number , label : string ) : void {
33- let emitter = new Emitter < URI [ ] > ( ) ;
34- let registration = this . _decorationsService . registerDecorationsProvider ( {
81+ const emitter = new Emitter < URI [ ] > ( ) ;
82+ const registration = this . _decorationsService . registerDecorationsProvider ( {
3583 label,
3684 onDidChange : emitter . event ,
3785 provideDecorations : ( uri ) => {
38- return this . _proxy . $provideDecorations ( handle , uri ) . then ( data => {
86+ return this . _requestQueue . enqueue ( handle , uri ) . then ( data => {
3987 if ( ! data ) {
4088 return undefined ;
4189 }
0 commit comments