Merge pull request #10611 from Microsoft/ben/env-debt

Use IEnvironmentService everywhere
This commit is contained in:
Benjamin Pasero
2016-08-17 16:52:36 +02:00
committed by GitHub
43 changed files with 325 additions and 408 deletions
+20 -34
View File
@@ -20,32 +20,15 @@ import URI from 'vs/base/common/uri';
import * as types from 'vs/base/common/types';
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
import product, { IProductConfiguration } from 'vs/platform/product';
import { parseArgs } from 'vs/code/node/argv';
import { parseArgs, ParsedArgs } from 'vs/code/node/argv';
import pkg from 'vs/platform/package';
export interface IProcessEnvironment {
[key: string]: string;
}
export interface ICommandLineArguments {
verboseLogging: boolean;
debugExtensionHostPort: number;
debugBrkExtensionHost: boolean;
debugBrkFileWatcherPort: number;
logExtensionHostCommunication: boolean;
disableExtensions: boolean;
extensionsHomePath: string;
extensionDevelopmentPath: string;
extensionTestsPath: string;
programStart: number;
export interface ICommandLineArguments extends ParsedArgs {
pathArguments?: string[];
enablePerformance?: boolean;
openNewWindow?: boolean;
openInSameWindow?: boolean;
gotoLineMode?: boolean;
diffMode?: boolean;
locale?: string;
waitForWindowClose?: boolean;
}
export const IEnvService = createDecorator<IEnvService>('mainEnvironmentService');
@@ -162,34 +145,37 @@ export class EnvService implements IEnvService {
const debugBrkExtensionHostPort = getNumericValue(argv.debugBrkPluginHost, 5870);
const debugExtensionHostPort = getNumericValue(argv.debugPluginHost, 5870, this.isBuilt ? void 0 : 5870);
const debugPluginHost = debugBrkExtensionHostPort ? String(debugBrkExtensionHostPort) : debugExtensionHostPort ? String(debugExtensionHostPort): void 0;
const debugBrkPluginHost = debugBrkExtensionHostPort ? String(true) : void 0;
const pathArguments = parsePathArguments(this._currentWorkingDirectory, argv._, argv.goto);
const timestamp = parseInt(argv.timestamp);
const debugBrkFileWatcherPort = getNumericValue(argv.debugBrkFileWatcherPort, void 0);
this._cliArgs = Object.freeze({
_: [],
pathArguments: pathArguments,
programStart: types.isNumber(timestamp) ? timestamp : 0,
enablePerformance: argv.performance,
verboseLogging: argv.verbose,
debugExtensionHostPort: debugBrkExtensionHostPort || debugExtensionHostPort,
debugBrkExtensionHost: !!debugBrkExtensionHostPort,
timestamp: types.isNumber(timestamp) ? String(timestamp) : '0',
performance: argv.performance,
verbose: argv.verbose,
debugPluginHost,
debugBrkPluginHost,
logExtensionHostCommunication: argv.logExtensionHostCommunication,
debugBrkFileWatcherPort: debugBrkFileWatcherPort,
openNewWindow: argv['new-window'],
openInSameWindow: argv['reuse-window'],
gotoLineMode: argv.goto,
diffMode: argv.diff && pathArguments.length === 2,
extensionsHomePath: normalizePath(argv.extensionHomePath),
debugBrkFileWatcherPort: debugBrkFileWatcherPort ? String(debugBrkFileWatcherPort) : void 0,
'new-window': argv['new-window'],
'reuse-window': argv['reuse-window'],
goto: argv.goto,
diff: argv.diff && pathArguments.length === 2,
extensionHomePath: normalizePath(argv.extensionHomePath),
extensionDevelopmentPath: normalizePath(argv.extensionDevelopmentPath),
extensionTestsPath: normalizePath(argv.extensionTestsPath),
disableExtensions: argv['disable-extensions'],
'disable-extensions': argv['disable-extensions'],
locale: argv.locale,
waitForWindowClose: argv.wait
wait: argv.wait
});
this._isTestingFromCli = this.cliArgs.extensionTestsPath && !this.cliArgs.debugBrkExtensionHost;
this._isTestingFromCli = this.cliArgs.extensionTestsPath && !this.cliArgs.debugBrkPluginHost;
this._userHome = path.join(os.homedir(), product.dataFolderName);
this._userExtensionsHome = this.cliArgs.extensionsHomePath || path.join(this._userHome, 'extensions');
this._userExtensionsHome = this.cliArgs.extensionHomePath || path.join(this._userHome, 'extensions');
const prefix = this.getIPCHandleBaseName();
const suffix = process.platform === 'win32' ? '-sock' : '.sock';
+5 -5
View File
@@ -62,7 +62,7 @@ export class LaunchService implements ILaunchService {
let usedWindows: VSCodeWindow[];
if (!!args.extensionDevelopmentPath) {
this.windowsService.openPluginDevelopmentHostWindow({ cli: args, userEnv });
} else if (args.pathArguments.length === 0 && args.openNewWindow) {
} else if (args.pathArguments.length === 0 && args['new-window']) {
usedWindows = this.windowsService.open({ cli: args, userEnv, forceNewWindow: true, forceEmpty: true });
} else if (args.pathArguments.length === 0) {
usedWindows = [this.windowsService.focusLastActive(args)];
@@ -70,15 +70,15 @@ export class LaunchService implements ILaunchService {
usedWindows = this.windowsService.open({
cli: args,
userEnv,
forceNewWindow: args.waitForWindowClose || args.openNewWindow,
preferNewWindow: !args.openInSameWindow,
diffMode: args.diffMode
forceNewWindow: args.wait || args['new-window'],
preferNewWindow: !args['reuse-window'],
diffMode: args.diff
});
}
// If the other instance is waiting to be killed, we hook up a window listener if one window
// is being used and only then resolve the startup promise which will kill this second instance
if (args.waitForWindowClose && usedWindows && usedWindows.length === 1 && usedWindows[0]) {
if (args.wait && usedWindows && usedWindows.length === 1 && usedWindows[0]) {
const windowId = usedWindows[0].id;
return new TPromise<void>((c, e) => {
+1 -1
View File
@@ -109,7 +109,7 @@ export class LifecycleService implements ILifecycleService {
// Windows/Linux: we quit when all windows have closed
// Mac: we only quit when quit was requested
// --wait: we quit when all windows are closed
if (this.quitRequested || process.platform !== 'darwin' || this.envService.cliArgs.waitForWindowClose) {
if (this.quitRequested || process.platform !== 'darwin' || this.envService.cliArgs.wait) {
app.quit();
}
});
+2 -2
View File
@@ -23,9 +23,9 @@ export class MainLogService implements ILogService {
}
log(...args: any[]): void {
const { verboseLogging } = this.envService.cliArgs;
const { verbose } = this.envService.cliArgs;
if (verboseLogging) {
if (verbose) {
console.log(`(${new Date().toLocaleTimeString()})`, ...args);
}
}
+4 -4
View File
@@ -122,7 +122,7 @@ function main(accessor: ServicesAccessor, mainIpcServer: Server, userEnv: IProce
// Spawn shared process
const sharedProcess = spawnSharedProcess({
allowOutput: !envService.isBuilt || envService.cliArgs.verboseLogging,
allowOutput: !envService.isBuilt || envService.cliArgs.verbose,
debugPort: envService.isBuilt ? null : 5871
});
@@ -135,7 +135,7 @@ function main(accessor: ServicesAccessor, mainIpcServer: Server, userEnv: IProce
}
// Set programStart in the global scope
global.programStart = envService.cliArgs.programStart;
global.programStart = envService.cliArgs.timestamp;
function dispose() {
if (mainIpcServer) {
@@ -195,12 +195,12 @@ function main(accessor: ServicesAccessor, mainIpcServer: Server, userEnv: IProce
updateService.initialize();
// Open our first window
if (envService.cliArgs.openNewWindow && envService.cliArgs.pathArguments.length === 0) {
if (envService.cliArgs['new-window'] && envService.cliArgs.pathArguments.length === 0) {
windowsService.open({ cli: envService.cliArgs, forceNewWindow: true, forceEmpty: true }); // new window if "-n" was used without paths
} else if (global.macOpenFiles && global.macOpenFiles.length && (!envService.cliArgs.pathArguments || !envService.cliArgs.pathArguments.length)) {
windowsService.open({ cli: envService.cliArgs, pathsToOpen: global.macOpenFiles }); // mac: open-file event received on startup
} else {
windowsService.open({ cli: envService.cliArgs, forceNewWindow: envService.cliArgs.openNewWindow, diffMode: envService.cliArgs.diffMode }); // default: read paths from cli
windowsService.open({ cli: envService.cliArgs, forceNewWindow: envService.cliArgs['new-window'], diffMode: envService.cliArgs.diff }); // default: read paths from cli
}
}
+2 -2
View File
@@ -93,7 +93,7 @@ export class StorageService implements IStorageService {
try {
return JSON.parse(fs.readFileSync(this.dbPath).toString()); // invalid JSON or permission issue can happen here
} catch (error) {
if (this.envService.cliArgs.verboseLogging) {
if (this.envService.cliArgs.verbose) {
console.error(error);
}
@@ -105,7 +105,7 @@ export class StorageService implements IStorageService {
try {
fs.writeFileSync(this.dbPath, JSON.stringify(this.database, null, 4)); // permission issue can happen here
} catch (error) {
if (this.envService.cliArgs.verboseLogging) {
if (this.envService.cliArgs.verbose) {
console.error(error);
}
}
+19 -44
View File
@@ -13,6 +13,7 @@ import { shell, screen, BrowserWindow } from 'electron';
import { TPromise, TValueCallback } from 'vs/base/common/winjs.base';
import { ICommandLineArguments, IEnvService, IProcessEnvironment } from 'vs/code/electron-main/env';
import { ILogService } from 'vs/code/electron-main/log';
import { parseArgs } from 'vs/code/node/argv';
export interface IWindowState {
width?: number;
@@ -88,49 +89,21 @@ export interface IPath {
}
export interface IWindowConfiguration extends ICommandLineArguments {
execPath: string;
version: string;
appName: string;
applicationName: string;
darwinBundleIdentifier: string;
appSettingsHome: string;
appSettingsPath: string;
appKeybindingsPath: string;
userExtensionsHome: string;
mainIPCHandle: string;
sharedIPCHandle: string;
appRoot: string;
isBuilt: boolean;
commitHash: string;
updateFeedUrl: string;
updateChannel: string;
execPath: string;
userEnv: IProcessEnvironment;
workspacePath?: string;
recentFiles: string[];
recentFolders: string[];
workspacePath?: string;
filesToOpen?: IPath[];
filesToCreate?: IPath[];
filesToDiff?: IPath[];
extensionsToInstall: string[];
crashReporter: Electron.CrashReporterStartOptions;
extensionsGallery: {
serviceUrl: string;
itemUrl: string;
};
extensionTips: { [id: string]: string; };
welcomePage: string;
releaseNotesUrl: string;
licenseUrl: string;
productDownloadUrl: string;
enableTelemetry: boolean;
userEnv: IProcessEnvironment;
aiConfig: {
key: string;
asimovKey: string;
};
sendASmile: {
reportIssueUrl: string,
requestFeatureUrl: string
};
}
export class VSCodeWindow {
@@ -384,7 +357,7 @@ export class VSCodeWindow {
this._win.loadURL(this.getUrl(config));
// Make window visible if it did not open in N seconds because this indicates an error
if (!config.isBuilt) {
if (!this.envService.isBuilt) {
this.showTimeoutHandle = setTimeout(() => {
if (this._win && !this._win.isVisible() && !this._win.isMinimized()) {
this._win.show();
@@ -407,22 +380,24 @@ export class VSCodeWindow {
// Some configuration things get inherited if the window is being reloaded and we are
// in plugin development mode. These options are all development related.
if (this.isPluginDevelopmentHost && cli) {
configuration.verboseLogging = cli.verboseLogging;
configuration.logExtensionHostCommunication = cli.logExtensionHostCommunication;
configuration.verbose = cli.verbose;
configuration.debugBrkFileWatcherPort = cli.debugBrkFileWatcherPort;
configuration.debugExtensionHostPort = cli.debugExtensionHostPort;
configuration.debugBrkExtensionHost = cli.debugBrkExtensionHost;
configuration.extensionsHomePath = cli.extensionsHomePath;
configuration.debugPluginHost = cli.debugPluginHost;
configuration.debugBrkPluginHost = cli.debugBrkPluginHost;
configuration.extensionHomePath = cli.extensionHomePath;
}
// Load config
this.load(configuration);
}
private getUrl(config: IWindowConfiguration): string {
private getUrl(windowConfiguration: IWindowConfiguration): string {
let url = require.toUrl('vs/workbench/electron-browser/bootstrap/index.html');
// Config
// Config (combination of process.argv and window configuration)
const environment = parseArgs(process.argv);
const config = objects.assign(environment, windowConfiguration);
url += '?config=' + encodeURIComponent(JSON.stringify(config));
return url;
+8 -34
View File
@@ -12,7 +12,6 @@ import * as nls from 'vs/nls';
import * as paths from 'vs/base/common/paths';
import * as arrays from 'vs/base/common/arrays';
import { assign, mixin } from 'vs/base/common/objects';
import pkg from 'vs/platform/package';
import { EventEmitter } from 'events';
import { IStorageService } from 'vs/code/electron-main/storage';
import { IPath, VSCodeWindow, ReadyState, IWindowConfiguration, IWindowState as ISingleWindowState, defaultWindowState } from 'vs/code/electron-main/window';
@@ -502,7 +501,7 @@ export class WindowsManager implements IWindowsService {
// Find paths from provided paths if any
if (openConfig.pathsToOpen && openConfig.pathsToOpen.length > 0) {
iPathsToOpen = openConfig.pathsToOpen.map((pathToOpen) => {
let iPath = this.toIPath(pathToOpen, false, openConfig.cli && openConfig.cli.gotoLineMode);
let iPath = this.toIPath(pathToOpen, false, openConfig.cli && openConfig.cli.goto);
// Warn if the requested path to open does not exist
if (!iPath) {
@@ -727,38 +726,14 @@ export class WindowsManager implements IWindowsService {
private toConfiguration(userEnv: IProcessEnvironment, cli: ICommandLineArguments, workspacePath?: string, filesToOpen?: IPath[], filesToCreate?: IPath[], filesToDiff?: IPath[], extensionsToInstall?: string[]): IWindowConfiguration {
let configuration: IWindowConfiguration = mixin({}, cli); // inherit all properties from CLI
configuration.appRoot = this.envService.appRoot;
configuration.execPath = process.execPath;
configuration.userEnv = userEnv;
configuration.workspacePath = workspacePath;
configuration.filesToOpen = filesToOpen;
configuration.filesToCreate = filesToCreate;
configuration.filesToDiff = filesToDiff;
configuration.extensionsToInstall = extensionsToInstall;
configuration.appName = this.envService.product.nameLong;
configuration.applicationName = this.envService.product.applicationName;
configuration.darwinBundleIdentifier = this.envService.product.darwinBundleIdentifier;
configuration.appRoot = this.envService.appRoot;
configuration.version = pkg.version;
configuration.commitHash = this.envService.product.commit;
configuration.appSettingsHome = this.envService.appSettingsHome;
configuration.appSettingsPath = this.envService.appSettingsPath;
configuration.appKeybindingsPath = this.envService.appKeybindingsPath;
configuration.userExtensionsHome = this.envService.userExtensionsHome;
configuration.extensionTips = this.envService.product.extensionTips;
configuration.mainIPCHandle = this.envService.mainIPCHandle;
configuration.sharedIPCHandle = this.envService.sharedIPCHandle;
configuration.isBuilt = this.envService.isBuilt;
configuration.crashReporter = this.envService.product.crashReporter;
configuration.extensionsGallery = this.envService.product.extensionsGallery;
configuration.welcomePage = this.envService.product.welcomePage;
configuration.productDownloadUrl = this.envService.product.downloadUrl;
configuration.releaseNotesUrl = this.envService.product.releaseNotesUrl;
configuration.licenseUrl = this.envService.product.licenseUrl;
configuration.updateFeedUrl = this.updateService.feedUrl;
configuration.updateChannel = this.updateService.channel;
configuration.aiConfig = this.envService.product.aiConfig;
configuration.sendASmile = this.envService.product.sendASmile;
configuration.enableTelemetry = this.envService.product.enableTelemetry;
configuration.userEnv = userEnv;
const recents = this.getRecentlyOpenedPaths(workspacePath, filesToOpen);
configuration.recentFiles = recents.files;
@@ -873,7 +848,7 @@ export class WindowsManager implements IWindowsService {
}
}
let iPaths = candidates.map((candidate) => this.toIPath(candidate, ignoreFileNotFound, cli.gotoLineMode)).filter((path) => !!path);
let iPaths = candidates.map((candidate) => this.toIPath(candidate, ignoreFileNotFound, cli.goto)).filter((path) => !!path);
if (iPaths.length > 0) {
return iPaths;
}
@@ -923,12 +898,11 @@ export class WindowsManager implements IWindowsService {
let currentWindowConfig = vscodeWindow.config;
if (!configuration.extensionDevelopmentPath && currentWindowConfig && !!currentWindowConfig.extensionDevelopmentPath) {
configuration.extensionDevelopmentPath = currentWindowConfig.extensionDevelopmentPath;
configuration.verboseLogging = currentWindowConfig.verboseLogging;
configuration.logExtensionHostCommunication = currentWindowConfig.logExtensionHostCommunication;
configuration.verbose = currentWindowConfig.verbose;
configuration.debugBrkFileWatcherPort = currentWindowConfig.debugBrkFileWatcherPort;
configuration.debugBrkExtensionHost = currentWindowConfig.debugBrkExtensionHost;
configuration.debugExtensionHostPort = currentWindowConfig.debugExtensionHostPort;
configuration.extensionsHomePath = currentWindowConfig.extensionsHomePath;
configuration.debugBrkPluginHost = currentWindowConfig.debugBrkPluginHost;
configuration.debugPluginHost = currentWindowConfig.debugPluginHost;
configuration.extensionHomePath = currentWindowConfig.extensionHomePath;
}
}
+23 -23
View File
@@ -8,29 +8,29 @@ import * as minimist from 'minimist';
import { localize } from 'vs/nls';
export interface ParsedArgs extends minimist.ParsedArgs {
help: boolean;
version: boolean;
wait: boolean;
diff: boolean;
goto: boolean;
'new-window': boolean;
'reuse-window': boolean;
locale: string;
'user-data-dir': string;
performance: boolean;
verbose: boolean;
logExtensionHostCommunication: boolean;
debugBrkFileWatcherPort: string;
'disable-extensions': boolean;
extensionHomePath: string;
extensionDevelopmentPath: string;
extensionTestsPath: string;
timestamp: string;
debugBrkPluginHost: string;
debugPluginHost: string;
'list-extensions': boolean;
'install-extension': string | string[];
'uninstall-extension': string | string[];
help?: boolean;
version?: boolean;
wait?: boolean;
diff?: boolean;
goto?: boolean;
'new-window'?: boolean;
'reuse-window'?: boolean;
locale?: string;
'user-data-dir'?: string;
performance?: boolean;
verbose?: boolean;
logExtensionHostCommunication?: boolean;
debugBrkFileWatcherPort?: string;
'disable-extensions'?: boolean;
extensionHomePath?: string;
extensionDevelopmentPath?: string;
extensionTestsPath?: string;
timestamp?: string;
debugBrkPluginHost?: string;
debugPluginHost?: string;
'list-extensions'?: boolean;
'install-extension'?: string | string[];
'uninstall-extension'?: string | string[];
}
const options: minimist.Opts = {
+2 -1
View File
@@ -10,6 +10,7 @@ import * as path from 'path';
import { parseArgs, ParsedArgs } from 'vs/code/node/argv';
import { TPromise } from 'vs/base/common/winjs.base';
import { sequence } from 'vs/base/common/async';
import * as objects from 'vs/base/common/objects';
import { IPager } from 'vs/base/common/paging';
import { ServiceCollection } from 'vs/platform/instantiation/common/serviceCollection';
import { SyncDescriptor } from 'vs/platform/instantiation/common/descriptors';
@@ -145,7 +146,7 @@ const eventPrefix = 'monacoworkbench';
export function main(argv: ParsedArgs): TPromise<void> {
const services = new ServiceCollection();
services.set(IEnvironmentService, new SyncDescriptor(EnvironmentService, parseArgs(process.argv)));
services.set(IEnvironmentService, new SyncDescriptor(EnvironmentService, objects.assign(parseArgs(process.argv), { execPath: process.execPath })));
const instantiationService: IInstantiationService = new InstantiationService(services);
+2 -1
View File
@@ -6,6 +6,7 @@
import * as fs from 'fs';
import * as platform from 'vs/base/common/platform';
import product from 'vs/platform/product';
import * as objects from 'vs/base/common/objects';
import pkg from 'vs/platform/package';
import { serve, Server, connect } from 'vs/base/parts/ipc/node/ipc.net';
import { TPromise } from 'vs/base/common/winjs.base';
@@ -58,7 +59,7 @@ function main(server: Server): void {
const services = new ServiceCollection();
services.set(IEventService, new SyncDescriptor(EventService));
services.set(IEnvironmentService, new SyncDescriptor(EnvironmentService, parseArgs(process.argv)));
services.set(IEnvironmentService, new SyncDescriptor(EnvironmentService, objects.assign(parseArgs(process.argv), { execPath: process.execPath })));
services.set(IConfigurationService, new SyncDescriptor(NodeConfigurationService));
services.set(IRequestService, new SyncDescriptor(RequestService));