diff --git a/src/vs/workbench/electron-browser/main.ts b/src/vs/workbench/electron-browser/main.ts index 3a9b7e9cd7bd598c4c731b573a284548a1f11d5c..f1b566e63dab8a5a23522f9f4c462f2796bc2010 100644 --- a/src/vs/workbench/electron-browser/main.ts +++ b/src/vs/workbench/electron-browser/main.ts @@ -112,9 +112,12 @@ function openWorkbench(configuration: IWindowConfiguration): TPromise { function createAndInitializeWorkspaceService(configuration: IWindowConfiguration, environmentService: EnvironmentService, workspacesService: IWorkspacesService): TPromise { return validateWorkspacePath(configuration).then(() => { - const workspaceConfigPath = configuration.workspace ? uri.file(configuration.workspace.configPath) : null; - const folderPath = configuration.folderPath ? uri.file(configuration.folderPath) : null; - const workspaceService = (workspaceConfigPath || configuration.folderPath) ? new WorkspaceServiceImpl(workspaceConfigPath, folderPath, environmentService, workspacesService) : new EmptyWorkspaceServiceImpl(environmentService); + let workspaceService: WorkspaceServiceImpl | EmptyWorkspaceServiceImpl; + if (configuration.workspace || configuration.folderPath) { + workspaceService = new WorkspaceServiceImpl(configuration.workspace || configuration.folderPath, environmentService, workspacesService); + } else { + workspaceService = new EmptyWorkspaceServiceImpl(environmentService); + } return workspaceService.initialize().then(() => workspaceService, error => new EmptyWorkspaceServiceImpl(environmentService)); }); diff --git a/src/vs/workbench/services/configuration/common/configurationModels.ts b/src/vs/workbench/services/configuration/common/configurationModels.ts index 9a0226735f8d8ab22b9eb94d3dd987603940fefd..74c1d65e249692ccc831df7a8c4a3aa5fe983518 100644 --- a/src/vs/workbench/services/configuration/common/configurationModels.ts +++ b/src/vs/workbench/services/configuration/common/configurationModels.ts @@ -29,10 +29,6 @@ export class WorkspaceConfigurationModel extends CustomConfigurationModel this._workspaceConfiguration = this.consolidate(); } - get id(): string { - return this._raw['id']; - } - get folders(): URI[] { return this._folders; } diff --git a/src/vs/workbench/services/configuration/node/configuration.ts b/src/vs/workbench/services/configuration/node/configuration.ts index ef2d4e4313b2308db182163a59bbb669a10b71a7..d9779ee22193c66e7475aaa4fe5f891669f0dbbd 100644 --- a/src/vs/workbench/services/configuration/node/configuration.ts +++ b/src/vs/workbench/services/configuration/node/configuration.ts @@ -33,7 +33,7 @@ import { Registry } from 'vs/platform/registry/common/platform'; import { ExtensionsRegistry, ExtensionMessageCollector } from 'vs/platform/extensions/common/extensionsRegistry'; import { IConfigurationNode, IConfigurationRegistry, Extensions, editorConfigurationSchemaId, IDefaultConfigurationExtension, validateProperty, ConfigurationScope, schemaId } from 'vs/platform/configuration/common/configurationRegistry'; import { createHash } from 'crypto'; -import { getWorkspaceLabel, IWorkspacesService } from 'vs/platform/workspaces/common/workspaces'; +import { getWorkspaceLabel, IWorkspacesService, IWorkspaceIdentifier, ISingleFolderWorkspaceIdentifier, isSingleFolderWorkspaceIdentifier } from 'vs/platform/workspaces/common/workspaces'; interface IStat { resource: URI; @@ -338,12 +338,21 @@ export class WorkspaceServiceImpl extends WorkspaceService { public _serviceBrand: any; + private workspaceConfigPath: URI; + private folderPath: URI; private baseConfigurationService: GlobalConfigurationService; private workspaceConfiguration: WorkspaceConfiguration; private cachedFolderConfigs: StrictResourceMap>; - constructor(private workspaceConfigPath: URI, private folderPath: URI, private environmentService: IEnvironmentService, private workspacesService: IWorkspacesService, private workspaceSettingsRootFolder: string = WORKSPACE_CONFIG_FOLDER_DEFAULT_NAME) { + constructor(private workspaceIdentifier: IWorkspaceIdentifier | ISingleFolderWorkspaceIdentifier, private environmentService: IEnvironmentService, private workspacesService: IWorkspacesService, private workspaceSettingsRootFolder: string = WORKSPACE_CONFIG_FOLDER_DEFAULT_NAME) { super(); + + if (isSingleFolderWorkspaceIdentifier(workspaceIdentifier)) { + this.folderPath = URI.file(workspaceIdentifier); + } else { + this.workspaceConfigPath = URI.file(workspaceIdentifier.configPath); + } + this.workspaceConfiguration = this._register(new WorkspaceConfiguration()); this.baseConfigurationService = this._register(new GlobalConfigurationService(environmentService)); } @@ -435,11 +444,12 @@ export class WorkspaceServiceImpl extends WorkspaceService { return this.workspaceConfiguration.load(this.workspaceConfigPath) .then(() => { const workspaceConfigurationModel = this.workspaceConfiguration.workspaceConfigurationModel; - if (!workspaceConfigurationModel.id || !workspaceConfigurationModel.folders.length) { + if (!workspaceConfigurationModel.folders.length) { return TPromise.wrapError(new Error('Invalid workspace configuraton file ' + this.workspaceConfigPath)); } - const workspaceName = getWorkspaceLabel({ id: workspaceConfigurationModel.id, configPath: this.workspaceConfigPath.fsPath }, this.environmentService); - this.workspace = new Workspace(workspaceConfigurationModel.id, workspaceName, workspaceConfigurationModel.folders, this.workspaceConfigPath); + const workspaceId = (this.workspaceIdentifier as IWorkspaceIdentifier).id; + const workspaceName = getWorkspaceLabel({ id: workspaceId, configPath: this.workspaceConfigPath.fsPath }, this.environmentService); + this.workspace = new Workspace(workspaceId, workspaceName, workspaceConfigurationModel.folders, this.workspaceConfigPath); this.legacyWorkspace = new LegacyWorkspace(this.workspace.roots[0]); this._register(this.workspaceConfiguration.onDidUpdateConfiguration(() => this.onWorkspaceConfigurationChanged())); return null; diff --git a/src/vs/workbench/services/configuration/test/node/configuration.test.ts b/src/vs/workbench/services/configuration/test/node/configuration.test.ts index aba215904febf67871d070ac9fc489378effdcfb..1ee691bae5f690aa6751a182b448b98da71db558 100644 --- a/src/vs/workbench/services/configuration/test/node/configuration.test.ts +++ b/src/vs/workbench/services/configuration/test/node/configuration.test.ts @@ -47,7 +47,7 @@ suite('WorkspaceConfigurationService - Node', () => { function createService(workspaceDir: string, globalSettingsFile: string): TPromise { const environmentService = new SettingsTestEnvironmentService(parseArgs(process.argv), process.execPath, globalSettingsFile); - const service = new WorkspaceServiceImpl(null, URI.file(workspaceDir), environmentService, null); + const service = new WorkspaceServiceImpl(workspaceDir, environmentService, null); return service.initialize().then(() => service); } diff --git a/src/vs/workbench/services/configuration/test/node/configurationEditingService.test.ts b/src/vs/workbench/services/configuration/test/node/configurationEditingService.test.ts index 7224039236d59c532a18ea96cba4012040ee4fc3..b5c9099cde40eb9375e995744f815f78953be859 100644 --- a/src/vs/workbench/services/configuration/test/node/configurationEditingService.test.ts +++ b/src/vs/workbench/services/configuration/test/node/configurationEditingService.test.ts @@ -11,7 +11,6 @@ import os = require('os'); import path = require('path'); import fs = require('fs'); import * as json from 'vs/base/common/json'; -import URI from 'vs/base/common/uri'; import { TPromise } from 'vs/base/common/winjs.base'; import { Registry } from 'vs/platform/registry/common/platform'; import { ParsedArgs, IEnvironmentService } from 'vs/platform/environment/common/environment'; @@ -118,7 +117,7 @@ suite('ConfigurationEditingService', () => { const environmentService = new SettingsTestEnvironmentService(parseArgs(process.argv), process.execPath, globalSettingsFile); instantiationService.stub(IEnvironmentService, environmentService); const workspacesService = instantiationService.stub(IWorkspacesService, {}); - const workspaceService = noWorkspace ? new EmptyWorkspaceServiceImpl(environmentService) : new WorkspaceServiceImpl(null, URI.file(workspaceDir), environmentService, workspacesService); + const workspaceService = noWorkspace ? new EmptyWorkspaceServiceImpl(environmentService) : new WorkspaceServiceImpl(workspaceDir, environmentService, workspacesService); instantiationService.stub(IWorkspaceContextService, workspaceService); instantiationService.stub(IConfigurationService, workspaceService); instantiationService.stub(ILifecycleService, new TestLifecycleService());