From 0702db135695ce1b618f7fb87d1431824e1e207b Mon Sep 17 00:00:00 2001 From: elaihau Date: Tue, 19 Feb 2019 17:34:30 -0500 Subject: [PATCH] delay hosted plugins' initialization - When plugins query the `workspace.workspaceFolders`, Theia plugin api returns `undefined` when there is no workspace open, or the opened workspace has not been resolved by `WorkspaceService`. And this is inconsistent with vsCode, where the extension host is not started until the `initialize` function of `WorkspaceService` returns. This change delays the initialization and loading of plugins to ensure workspace root(s) are resolved beforehand. Signed-off-by: elaihau --- packages/plugin-ext/src/hosted/browser/hosted-plugin.ts | 6 ++---- packages/plugin-ext/src/main/browser/workspace-main.ts | 7 ++----- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/packages/plugin-ext/src/hosted/browser/hosted-plugin.ts b/packages/plugin-ext/src/hosted/browser/hosted-plugin.ts index ef09d88ab1f03..6a4d44c2267a8 100644 --- a/packages/plugin-ext/src/hosted/browser/hosted-plugin.ts +++ b/packages/plugin-ext/src/hosted/browser/hosted-plugin.ts @@ -58,9 +58,6 @@ export class HostedPluginSupport { @inject(PluginServer) protected readonly pluginServer: PluginServer; - @inject(WorkspaceService) - protected readonly workspaceService: WorkspaceService; - @inject(PreferenceProviderProvider) protected readonly preferenceProviderProvider: PreferenceProviderProvider; @@ -72,8 +69,9 @@ export class HostedPluginSupport { @inject(PreferenceServiceImpl) private readonly preferenceServiceImpl: PreferenceServiceImpl, @inject(PluginPathsService) private readonly pluginPathsService: PluginPathsService, @inject(StoragePathService) private readonly storagePathService: StoragePathService, + @inject(WorkspaceService) protected readonly workspaceService: WorkspaceService, ) { - this.theiaReadyPromise = Promise.all([this.preferenceServiceImpl.ready]); + this.theiaReadyPromise = Promise.all([this.preferenceServiceImpl.ready, this.workspaceService.roots]); this.storagePathService.onStoragePathChanged(path => { this.updateStoragePath(path); diff --git a/packages/plugin-ext/src/main/browser/workspace-main.ts b/packages/plugin-ext/src/main/browser/workspace-main.ts index 76b5d39d62f37..c964ded16bb74 100644 --- a/packages/plugin-ext/src/main/browser/workspace-main.ts +++ b/packages/plugin-ext/src/main/browser/workspace-main.ts @@ -67,10 +67,7 @@ export class WorkspaceMainImpl implements WorkspaceMain { this.inPluginFileSystemWatcherManager = new InPluginFileSystemWatcherManager(this.proxy, container); - this.workspaceService.roots.then(roots => { - this.processWorkspaceFoldersChanged(roots); - }); - + this.processWorkspaceFoldersChanged(this.workspaceService.tryGetRoots()); this.workspaceService.onWorkspaceChanged(roots => { this.processWorkspaceFoldersChanged(roots); }); @@ -81,13 +78,13 @@ export class WorkspaceMainImpl implements WorkspaceMain { return; } this.roots = roots; + this.proxy.$onWorkspaceFoldersChanged({ roots }); await this.storagePathService.updateStoragePath(roots); const keyValueStorageWorkspacesData = await this.pluginServer.keyValueStorageGetAll(false); this.storageProxy.$updatePluginsWorkspaceData(keyValueStorageWorkspacesData); - this.proxy.$onWorkspaceFoldersChanged({ roots }); } private isAnyRootChanged(roots: FileStat[]): boolean {