@@ -187,8 +187,6 @@ export class Workbench extends Disposable implements IPartService {
187187
188188 private editorService : EditorService ;
189189 private editorGroupService : IEditorGroupsService ;
190- private contextViewService : ContextViewService ;
191- private windowService : IWindowService ;
192190
193191 private instantiationService : IInstantiationService ;
194192 private contextService : IWorkspaceContextService ;
@@ -326,8 +324,10 @@ export class Workbench extends Disposable implements IPartService {
326324 this . _register ( this . instantiationService . createInstance ( WorkbenchContextKeysHandler ) ) ;
327325
328326 // Register Listeners
329- this . registerListeners ( ) ;
330- this . registerLayoutListeners ( ) ;
327+ this . instantiationService . invokeFunction ( accessor => {
328+ this . registerListeners ( accessor ) ;
329+ this . registerLayoutListeners ( accessor ) ;
330+ } ) ;
331331
332332 // Layout State
333333 this . instantiationService . invokeFunction ( accessor => this . initLayoutState ( accessor ) ) ;
@@ -357,7 +357,7 @@ export class Workbench extends Disposable implements IPartService {
357357 private initServices ( serviceCollection : ServiceCollection ) : void {
358358
359359 // Parts
360- serviceCollection . set ( IPartService , this ) ;
360+ serviceCollection . set ( IPartService , this ) ; // TODO @Ben use SyncDescriptor
361361
362362 // Labels
363363 serviceCollection . set ( ILabelService , new SyncDescriptor ( LabelService , undefined , true ) ) ;
@@ -366,12 +366,11 @@ export class Workbench extends Disposable implements IPartService {
366366 serviceCollection . set ( INotificationService , new SyncDescriptor ( NotificationService , undefined , true ) ) ;
367367
368368 // Window
369- this . windowService = this . instantiationService . createInstance ( WindowService , this . configuration ) ;
370- serviceCollection . set ( IWindowService , this . windowService ) ;
369+ serviceCollection . set ( IWindowService , new SyncDescriptor ( WindowService , [ this . configuration ] ) ) ;
371370
372371 // Product
373372 const productService = new ProductService ( ) ;
374- serviceCollection . set ( IProductService , productService ) ;
373+ serviceCollection . set ( IProductService , productService ) ; // TODO @Ben use SyncDescriptor
375374
376375 // Shared Process
377376 const sharedProcess = this . windowsService . whenSharedProcessReady ( )
@@ -397,16 +396,10 @@ export class Workbench extends Disposable implements IPartService {
397396 telemetryService = NullTelemetryService ;
398397 }
399398
400- serviceCollection . set ( ITelemetryService , telemetryService ) ;
399+ serviceCollection . set ( ITelemetryService , telemetryService ) ; // TODO @Ben use SyncDescriptor
401400
402401 // Lifecycle
403- const lifecycleService = this . instantiationService . createInstance ( LifecycleService ) ;
404- serviceCollection . set ( ILifecycleService , lifecycleService ) ;
405- this . _register ( lifecycleService . onWillShutdown ( event => this . _onWillShutdown . fire ( event ) ) ) ;
406- this . _register ( lifecycleService . onShutdown ( ( ) => {
407- this . _onShutdown . fire ( ) ;
408- this . dispose ( ) ;
409- } ) ) ;
402+ serviceCollection . set ( ILifecycleService , new SyncDescriptor ( LifecycleService ) ) ;
410403
411404 // Request Service
412405 serviceCollection . set ( IRequestService , new SyncDescriptor ( RequestService , undefined , true ) ) ;
@@ -459,7 +452,7 @@ export class Workbench extends Disposable implements IPartService {
459452
460453 // Status bar
461454 this . statusbarPart = this . instantiationService . createInstance ( StatusbarPart , Identifiers . STATUSBAR_PART ) ;
462- serviceCollection . set ( IStatusbarService , this . statusbarPart ) ;
455+ serviceCollection . set ( IStatusbarService , this . statusbarPart ) ; // TODO @Ben use SyncDescriptor
463456
464457 // Context Keys
465458 serviceCollection . set ( IContextKeyService , new SyncDescriptor ( ContextKeyService ) ) ;
@@ -468,8 +461,7 @@ export class Workbench extends Disposable implements IPartService {
468461 serviceCollection . set ( IKeybindingService , new SyncDescriptor ( WorkbenchKeybindingService , [ window ] ) ) ;
469462
470463 // Context view service
471- this . contextViewService = this . instantiationService . createInstance ( ContextViewService , this . workbench ) ;
472- serviceCollection . set ( IContextViewService , this . contextViewService ) ;
464+ serviceCollection . set ( IContextViewService , new SyncDescriptor ( ContextViewService , [ this . workbench ] , true ) ) ;
473465
474466 // Use themable context menus when custom titlebar is enabled to match custom menubar
475467 if ( ! isMacintosh && getTitleBarStyle ( this . configurationService , this . environmentService ) === 'custom' ) {
@@ -478,15 +470,13 @@ export class Workbench extends Disposable implements IPartService {
478470 serviceCollection . set ( IContextMenuService , new SyncDescriptor ( NativeContextMenuService ) ) ;
479471 }
480472
481- // Sidebar part
473+ // Viewlet service (sidebar part)
482474 this . sidebarPart = this . instantiationService . createInstance ( SidebarPart , Identifiers . SIDEBAR_PART ) ;
483-
484- // Viewlet service
485- serviceCollection . set ( IViewletService , this . sidebarPart ) ;
475+ serviceCollection . set ( IViewletService , this . sidebarPart ) ; // TODO@Ben use SyncDescriptor
486476
487477 // Panel service (panel part)
488478 this . panelPart = this . instantiationService . createInstance ( PanelPart , Identifiers . PANEL_PART ) ;
489- serviceCollection . set ( IPanelService , this . panelPart ) ;
479+ serviceCollection . set ( IPanelService , this . panelPart ) ; // TODO @Ben use SyncDescriptor
490480
491481 // Views service
492482 serviceCollection . set ( IViewsService , new SyncDescriptor ( ViewsService ) ) ;
@@ -501,27 +491,27 @@ export class Workbench extends Disposable implements IPartService {
501491 // Editor and Group services
502492 this . editorPart = this . instantiationService . createInstance ( EditorPart , Identifiers . EDITOR_PART , ! this . hasInitialFilesToOpen ( ) ) ;
503493 this . editorGroupService = this . editorPart ;
504- serviceCollection . set ( IEditorGroupsService , this . editorPart ) ;
494+ serviceCollection . set ( IEditorGroupsService , this . editorPart ) ; // TODO @Ben use SyncDescriptor
505495 this . editorService = this . instantiationService . createInstance ( EditorService ) ;
506- serviceCollection . set ( IEditorService , this . editorService ) ;
496+ serviceCollection . set ( IEditorService , this . editorService ) ; // TODO @Ben use SyncDescriptor
507497
508498 // Accessibility
509499 serviceCollection . set ( IAccessibilityService , new SyncDescriptor ( AccessibilityService , undefined , true ) ) ;
510500
511501 // Title bar
512502 this . titlebarPart = this . instantiationService . createInstance ( TitlebarPart , Identifiers . TITLEBAR_PART ) ;
513- serviceCollection . set ( ITitleService , this . titlebarPart ) ;
503+ serviceCollection . set ( ITitleService , this . titlebarPart ) ; // TODO @Ben use SyncDescriptor
514504
515505 // History
516506 serviceCollection . set ( IHistoryService , new SyncDescriptor ( HistoryService ) ) ;
517507
518508 // Quick open service (quick open controller)
519509 this . quickOpen = this . instantiationService . createInstance ( QuickOpenController ) ;
520- serviceCollection . set ( IQuickOpenService , this . quickOpen ) ;
510+ serviceCollection . set ( IQuickOpenService , this . quickOpen ) ; // TODO @Ben use SyncDescriptor
521511
522512 // Quick input service
523513 this . quickInput = this . instantiationService . createInstance ( QuickInputService ) ;
524- serviceCollection . set ( IQuickInputService , this . quickInput ) ;
514+ serviceCollection . set ( IQuickInputService , this . quickInput ) ; // TODO @Ben use SyncDescriptor
525515
526516 // Contributed services
527517 const contributedServices = getServices ( ) ;
@@ -575,13 +565,23 @@ export class Workbench extends Disposable implements IPartService {
575565 ( this . configuration . filesToDiff && this . configuration . filesToDiff . length > 0 ) ) ;
576566 }
577567
578- private registerListeners ( ) : void {
568+ private registerListeners ( accessor : ServicesAccessor ) : void {
569+ const lifecycleService = accessor . get ( ILifecycleService ) ;
570+ const storageService = accessor . get ( IStorageService ) ;
571+ const configurationService = accessor . get ( IConfigurationService ) ;
572+
573+ // Lifecycle
574+ this . _register ( lifecycleService . onWillShutdown ( event => this . _onWillShutdown . fire ( event ) ) ) ;
575+ this . _register ( lifecycleService . onShutdown ( ( ) => {
576+ this . _onShutdown . fire ( ) ;
577+ this . dispose ( ) ;
578+ } ) ) ;
579579
580580 // Storage
581- this . _register ( this . storageService . onWillSaveState ( e => this . saveState ( e ) ) ) ;
581+ this . _register ( storageService . onWillSaveState ( e => this . saveState ( e ) ) ) ;
582582
583583 // Configuration changes
584- this . _register ( this . configurationService . onDidChangeConfiguration ( ( ) => this . setFontAliasing ( ) ) ) ;
584+ this . _register ( configurationService . onDidChangeConfiguration ( ( ) => this . setFontAliasing ( ) ) ) ;
585585 }
586586
587587 private fontAliasing : 'default' | 'antialiased' | 'none' | 'auto' ;
@@ -837,6 +837,9 @@ export class Workbench extends Disposable implements IPartService {
837837 private editorPartView : View ;
838838 private statusBarPartView : View ;
839839
840+ private contextViewService : IContextViewService ;
841+ private windowService : IWindowService ;
842+
840843 private readonly state = {
841844 fullscreen : false ,
842845
@@ -886,31 +889,37 @@ export class Workbench extends Disposable implements IPartService {
886889 }
887890 } ;
888891
889- private registerLayoutListeners ( ) : void {
892+ private registerLayoutListeners ( accessor : ServicesAccessor ) : void {
893+ const storageService = accessor . get ( IStorageService ) ;
894+ const editorService = accessor . get ( IEditorService ) ;
895+ const configurationService = accessor . get ( IConfigurationService ) ;
896+ const editorGroupService = accessor . get ( IEditorGroupsService ) ;
897+ const titleService = accessor . get ( ITitleService ) ;
898+ const environmentService = accessor . get ( IEnvironmentService ) ;
890899
891900 // Storage
892- this . _register ( this . storageService . onWillSaveState ( e => this . saveLayoutState ( e ) ) ) ;
901+ this . _register ( storageService . onWillSaveState ( e => this . saveLayoutState ( e ) ) ) ;
893902
894903 // Restore editor if hidden and it changes
895- this . _register ( this . editorService . onDidVisibleEditorsChange ( ( ) => this . setEditorHidden ( false ) ) ) ;
896- this . _register ( this . editorPart . onDidActivateGroup ( ( ) => this . setEditorHidden ( false ) ) ) ;
904+ this . _register ( editorService . onDidVisibleEditorsChange ( ( ) => this . setEditorHidden ( false ) ) ) ;
905+ this . _register ( editorGroupService . onDidActivateGroup ( ( ) => this . setEditorHidden ( false ) ) ) ;
897906
898907 // Configuration changes
899- this . _register ( this . configurationService . onDidChangeConfiguration ( ( ) => this . doUpdateLayoutConfiguration ( ) ) ) ;
908+ this . _register ( configurationService . onDidChangeConfiguration ( ( ) => this . doUpdateLayoutConfiguration ( ) ) ) ;
900909
901910 // Fullscreen changes
902911 this . _register ( onDidChangeFullscreen ( ( ) => this . onFullscreenChanged ( ) ) ) ;
903912
904913 // Group changes
905- this . _register ( this . editorGroupService . onDidAddGroup ( ( ) => this . centerEditorLayout ( this . state . editor . centered ) ) ) ;
906- this . _register ( this . editorGroupService . onDidRemoveGroup ( ( ) => this . centerEditorLayout ( this . state . editor . centered ) ) ) ;
914+ this . _register ( editorGroupService . onDidAddGroup ( ( ) => this . centerEditorLayout ( this . state . editor . centered ) ) ) ;
915+ this . _register ( editorGroupService . onDidRemoveGroup ( ( ) => this . centerEditorLayout ( this . state . editor . centered ) ) ) ;
907916
908917 // Prevent workbench from scrolling #55456
909918 this . _register ( addDisposableListener ( this . workbench , EventType . SCROLL , ( ) => this . workbench . scrollTop = 0 ) ) ;
910919
911920 // Menubar visibility changes
912- if ( ( isWindows || isLinux ) && getTitleBarStyle ( this . configurationService , this . environmentService ) === 'custom' ) {
913- this . _register ( this . titlebarPart . onMenubarVisibilityChange ( visible => this . onMenubarToggled ( visible ) ) ) ;
921+ if ( ( isWindows || isLinux ) && getTitleBarStyle ( configurationService , environmentService ) === 'custom' ) {
922+ this . _register ( titleService . onMenubarVisibilityChange ( visible => this . onMenubarToggled ( visible ) ) ) ;
914923 }
915924 }
916925
@@ -1025,6 +1034,9 @@ export class Workbench extends Disposable implements IPartService {
10251034 const contextService = accessor . get ( IWorkspaceContextService ) ;
10261035 const environmentService = accessor . get ( IEnvironmentService ) ;
10271036
1037+ this . windowService = accessor . get ( IWindowService ) ;
1038+ this . contextViewService = accessor . get ( IContextViewService ) ;
1039+
10281040 // Fullscreen
10291041 this . state . fullscreen = isFullscreen ( ) ;
10301042
@@ -1325,6 +1337,7 @@ export class Workbench extends Disposable implements IPartService {
13251337 if ( this . state . zenMode . transitionedToCenteredEditorLayout ) {
13261338 this . centerEditorLayout ( false , true ) ;
13271339 }
1340+
13281341 setLineNumbers ( this . configurationService . getValue ( 'editor.lineNumbers' ) ) ;
13291342
13301343 // Status bar and activity bar visibility come from settings -> update their visibility.
0 commit comments