/*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ 'use strict'; import { IWorkspacesMainService, IWorkspace, IStoredWorkspace } from "vs/platform/workspaces/common/workspaces"; import { TPromise } from "vs/base/common/winjs.base"; import { isParent } from "vs/platform/files/common/files"; import { IEnvironmentService } from "vs/platform/environment/common/environment"; import { extname, join } from "path"; import { mkdirp, writeFile } from "vs/base/node/pfs"; export class WorkspacesMainService implements IWorkspacesMainService { public _serviceBrand: any; protected workspacesHome: string; constructor( @IEnvironmentService private environmentService: IEnvironmentService) { this.workspacesHome = environmentService.workspacesHome; } public isWorkspace(path: string): boolean { return isParent(path, this.environmentService.workspacesHome) || extname(path) === '.vscode'; } public createWorkspace(folders: string[] = []): TPromise { const workspaceId = this.nextWorkspaceId(); const workspaceConfigFolder = join(this.workspacesHome, workspaceId); const workspaceConfigPath = join(workspaceConfigFolder, 'workspace.json'); return mkdirp(workspaceConfigFolder).then(() => { const storedWorkspace: IStoredWorkspace = { id: workspaceId, folders }; return writeFile(workspaceConfigPath, JSON.stringify(storedWorkspace, null, '\t')).then(() => ({ id: workspaceId, folders, workspaceConfigPath })); }); } private nextWorkspaceId(): string { return (Date.now() + Math.round(Math.random() * 1000)).toString(); } }