提交 c387f80b 编写于 作者: B Benjamin Pasero

💄 multi root initialization

上级 8d6b6cdd
......@@ -112,9 +112,12 @@ function openWorkbench(configuration: IWindowConfiguration): TPromise<void> {
function createAndInitializeWorkspaceService(configuration: IWindowConfiguration, environmentService: EnvironmentService, workspacesService: IWorkspacesService): TPromise<WorkspaceService> {
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));
});
......
......@@ -29,10 +29,6 @@ export class WorkspaceConfigurationModel<T> extends CustomConfigurationModel<T>
this._workspaceConfiguration = this.consolidate();
}
get id(): string {
return this._raw['id'];
}
get folders(): URI[] {
return this._folders;
}
......
......@@ -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<any>;
private workspaceConfiguration: WorkspaceConfiguration;
private cachedFolderConfigs: StrictResourceMap<FolderConfiguration<any>>;
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<void>(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;
......
......@@ -47,7 +47,7 @@ suite('WorkspaceConfigurationService - Node', () => {
function createService(workspaceDir: string, globalSettingsFile: string): TPromise<WorkspaceService> {
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);
}
......
......@@ -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());
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册