Skip to content

Commit bc03bc9

Browse files
committed
Viewlet service: Open viewlet wait until extensions are registered
1 parent e32aba6 commit bc03bc9

1 file changed

Lines changed: 6 additions & 17 deletions

File tree

src/vs/workbench/services/viewlet/browser/viewletService.ts

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { ViewletDescriptor, ViewletRegistry, Extensions as ViewletExtensions } f
1414
import { IProgressService } from 'vs/platform/progress/common/progress';
1515
import { IContextKeyService, RawContextKey, IContextKey } from 'vs/platform/contextkey/common/contextkey';
1616
import { dispose, IDisposable } from 'vs/base/common/lifecycle';
17+
import { IExtensionService } from 'vs/workbench/services/extensions/common/extensions';
1718

1819
const ActiveViewletContextId = 'activeViewlet';
1920
export const ActiveViewletContext = new RawContextKey<string>(ActiveViewletContextId, '');
@@ -25,7 +26,6 @@ export class ViewletService implements IViewletService {
2526
private sidebarPart: SidebarPart;
2627
private viewletRegistry: ViewletRegistry;
2728

28-
private extensionViewletsLoaded: TPromise<void>;
2929
private activeViewletContextKey: IContextKey<string>;
3030
private _onDidViewletEnable = new Emitter<{ id: string, enabled: boolean }>();
3131
private disposables: IDisposable[] = [];
@@ -37,7 +37,8 @@ export class ViewletService implements IViewletService {
3737

3838
constructor(
3939
sidebarPart: SidebarPart,
40-
@IContextKeyService contextKeyService: IContextKeyService
40+
@IContextKeyService contextKeyService: IContextKeyService,
41+
@IExtensionService private extensionService: IExtensionService
4142
) {
4243
this.sidebarPart = sidebarPart;
4344
this.viewletRegistry = Registry.as<ViewletRegistry>(ViewletExtensions.Viewlets);
@@ -69,23 +70,11 @@ export class ViewletService implements IViewletService {
6970
}
7071

7172
public openViewlet(id: string, focus?: boolean): TPromise<IViewlet> {
72-
73-
// Built in viewlets do not need to wait for extensions to be loaded
74-
const builtInViewletIds = this.getBuiltInViewlets().map(v => v.id);
75-
const isBuiltInViewlet = builtInViewletIds.indexOf(id) !== -1;
76-
if (isBuiltInViewlet) {
73+
if (this.getViewlet(id)) {
7774
return this.sidebarPart.openViewlet(id, focus);
7875
}
79-
80-
// Extension viewlets need to be loaded first which can take time
81-
return this.extensionViewletsLoaded.then(() => {
82-
if (this.viewletRegistry.getViewlet(id)) {
83-
return this.sidebarPart.openViewlet(id, focus);
84-
}
85-
86-
// Fallback to default viewlet if extension viewlet is still not found (e.g. uninstalled)
87-
return this.sidebarPart.openViewlet(this.getDefaultViewletId(), focus);
88-
});
76+
return this.extensionService.whenInstalledExtensionsRegistered()
77+
.then(() => this.sidebarPart.openViewlet(id, focus));
8978
}
9079

9180
public getActiveViewlet(): IViewlet {

0 commit comments

Comments
 (0)