Skip to content

Commit

Permalink
delay hosted plugins' initialization
Browse files Browse the repository at this point in the history
- 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 <[email protected]>
  • Loading branch information
elaihau authored and elaihau committed Feb 21, 2019
1 parent 167ff06 commit 0702db1
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 9 deletions.
6 changes: 2 additions & 4 deletions packages/plugin-ext/src/hosted/browser/hosted-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
Expand Down
7 changes: 2 additions & 5 deletions packages/plugin-ext/src/main/browser/workspace-main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand All @@ -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 {
Expand Down

0 comments on commit 0702db1

Please sign in to comment.