environmentService.ts 2.8 KB
Newer Older
J
Joao Moreno 已提交
1 2 3 4 5
/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/

6
import {IEnvironmentService} from 'vs/platform/environment/common/environment';
J
Joao Moreno 已提交
7 8 9 10
import * as paths from 'vs/base/node/paths';
import product from 'vs/platform/product';
import * as os from 'os';
import * as path from 'path';
11
import {ParsedArgs} from 'vs/code/node/argv';
12
import URI from 'vs/base/common/uri';
13
import { memoize } from 'vs/base/common/decorators';
J
Joao Moreno 已提交
14

15 16
// TODO@Ben TODO@Joao this interface should be composed once the main => renderer
// communication is also fit for that
17 18 19 20
export interface IEnvironment extends ParsedArgs {
	execPath: string;
}

J
Joao Moreno 已提交
21 22
export class EnvironmentService implements IEnvironmentService {

23
	_serviceBrand: any;
J
Joao Moreno 已提交
24

25 26
	@memoize
	get appRoot(): string { return path.dirname(URI.parse(require.toUrl('')).fsPath); }
27 28
	get execPath(): string { return this.args.execPath; }

29 30
	@memoize
	get userHome(): string { return path.join(os.homedir(), product.dataFolderName); }
J
Joao Moreno 已提交
31

32 33
	@memoize
	get userDataPath(): string { return this.args['user-data-dir'] || paths.getDefaultUserDataPath(process.platform); }
J
Joao Moreno 已提交
34

35 36
	@memoize
	get appSettingsHome(): string { return path.join(this.userDataPath, 'User'); }
37

38 39
	@memoize
	get appSettingsPath(): string { return path.join(this.appSettingsHome, 'settings.json'); }
40

41 42
	@memoize
	get appKeybindingsPath(): string { return path.join(this.appSettingsHome, 'keybindings.json'); }
43

44 45
	@memoize
	get extensionsPath(): string { return path.normalize(this.args.extensionHomePath || path.join(this.userHome, 'extensions')); }
J
Joao Moreno 已提交
46

47
	get extensionDevelopmentPath(): string { return this.args.extensionDevelopmentPath; }
48

B
Benjamin Pasero 已提交
49
	get extensionTestsPath(): string { return this.args.extensionTestsPath; }
B
Benjamin Pasero 已提交
50
	get disableExtensions(): boolean { return this.args['disable-extensions'];  }
B
Benjamin Pasero 已提交
51

52
	@memoize
J
Joao Moreno 已提交
53
	get debugExtensionHost(): { port: number; break: boolean; } { return parseExtensionHostPort(this.args, this.isBuilt); }
54

55
	get isBuilt(): boolean { return !process.env['VSCODE_DEV']; }
J
Joao Moreno 已提交
56
	get verbose(): boolean { return this.args.verbose; }
B
Benjamin Pasero 已提交
57
	get performance(): boolean { return this.args.performance; }
58
	get logExtensionHostCommunication(): boolean { return this.args.logExtensionHostCommunication; }
59

60
	constructor(private args: IEnvironment) {}
61 62
}

J
Joao Moreno 已提交
63
export function parseExtensionHostPort(args: ParsedArgs, isBuild: boolean): { port: number; break: boolean; } {
64 65 66
	const portStr = args.debugBrkPluginHost || args.debugPluginHost;
	const port = Number(portStr) || (!isBuild ? 5870 : null);
	const brk = port ? Boolean(!!args.debugBrkPluginHost) : false;
J
Joao Moreno 已提交
67
	return { port, break: brk };
J
Joao Moreno 已提交
68
}