start with a step back and use IWorkspace where needed, nuke workspace context service from ext host, #28526

This commit is contained in:
Johannes Rieken
2017-06-12 15:39:39 +02:00
parent def13c6d78
commit 7c1c21c158
5 changed files with 21 additions and 40 deletions

View File

@@ -15,7 +15,7 @@ import { ExtHostStorage } from 'vs/workbench/api/node/extHostStorage';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { createApiFactory, initializeExtensionApi } from 'vs/workbench/api/node/extHost.api.impl';
import { IThreadService } from 'vs/workbench/services/thread/common/threadService';
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
import { IWorkspace } from 'vs/platform/workspace/common/workspace';
import { MainContext, MainProcessExtensionServiceShape, IEnvironment, IInitData } from './extHost.protocol';
import { createHash } from 'crypto';
@@ -103,14 +103,14 @@ class ExtensionMemento implements IExtensionMemento {
class ExtensionStoragePath {
private readonly _contextService: IWorkspaceContextService;
private readonly _workspace: IWorkspace;
private readonly _environment: IEnvironment;
private readonly _ready: TPromise<string>;
private _value: string;
constructor(contextService: IWorkspaceContextService, environment: IEnvironment) {
this._contextService = contextService;
constructor(workspace: IWorkspace, environment: IEnvironment) {
this._workspace = workspace;
this._environment = environment;
this._ready = this._getOrCreateWorkspaceStoragePath().then(value => this._value = value);
}
@@ -127,16 +127,13 @@ class ExtensionStoragePath {
}
private _getOrCreateWorkspaceStoragePath(): TPromise<string> {
const workspace = this._contextService.getWorkspace();
if (!workspace) {
if (!this._workspace) {
return TPromise.as(undefined);
}
const storageName = createHash('md5')
.update(workspace.resource.fsPath)
.update(workspace.uid ? workspace.uid.toString() : '')
.update(this._workspace.resource.fsPath)
.update(this._workspace.uid ? this._workspace.uid.toString() : '')
.digest('hex');
const storagePath = join(this._environment.appSettingsHome, 'workspaceStorage', storageName);
@@ -171,23 +168,21 @@ export class ExtHostExtensionService extends AbstractExtensionService<ExtHostExt
private _storagePath: ExtensionStoragePath;
private _proxy: MainProcessExtensionServiceShape;
private _telemetryService: ITelemetryService;
private _contextService: IWorkspaceContextService;
/**
* This class is constructed manually because it is a service, so it doesn't use any ctor injection
*/
constructor(initData: IInitData, threadService: IThreadService, telemetryService: ITelemetryService, contextService: IWorkspaceContextService) {
constructor(initData: IInitData, threadService: IThreadService, telemetryService: ITelemetryService) {
super(false);
this._registry.registerExtensions(initData.extensions);
this._threadService = threadService;
this._storage = new ExtHostStorage(threadService);
this._storagePath = new ExtensionStoragePath(contextService, initData.environment);
this._storagePath = new ExtensionStoragePath(initData.workspace, initData.environment);
this._proxy = this._threadService.get(MainContext.MainProcessExtensionService);
this._telemetryService = telemetryService;
this._contextService = contextService;
// initialize API first
const apiFactory = createApiFactory(initData, threadService, this, this._contextService, this._telemetryService);
const apiFactory = createApiFactory(initData, threadService, this, this._telemetryService);
initializeExtensionApi(this, apiFactory).then(() => this._triggerOnReady());
}