create paths in cli process main

fixes #7505
This commit is contained in:
Joao Moreno
2016-07-13 12:51:58 +02:00
parent 1e6288fad7
commit 2cdcaf24ee
5 changed files with 67 additions and 48 deletions
+11
View File
@@ -10,9 +10,11 @@ import * as fs from 'original-fs';
import * as path from 'path';
import * as os from 'os';
import { app } from 'electron';
import { mkdirp } from 'vs/base/node/pfs';
import * as arrays from 'vs/base/common/arrays';
import * as strings from 'vs/base/common/strings';
import * as paths from 'vs/base/common/paths';
import { TPromise } from 'vs/base/common/winjs.base';
import * as platform from 'vs/base/common/platform';
import URI from 'vs/base/common/uri';
import * as types from 'vs/base/common/types';
@@ -66,6 +68,8 @@ export interface IEnvironmentService {
appKeybindingsPath: string;
mainIPCHandle: string;
sharedIPCHandle: string;
createPaths(): TPromise<void>;
}
function getNumericValue(value: string, defaultValue: number, fallback: number = void 0) {
@@ -226,6 +230,13 @@ export class EnvService implements IEnvironmentService {
// use sha256 to ensure the userid value can be used in filenames and are unique
return crypto.createHash('sha256').update(username).digest('hex').substr(0, 6);
}
createPaths(): TPromise<void> {
const promises = [this.appSettingsHome, this.userHome, this.userExtensionsHome]
.map(p => mkdirp(p));
return TPromise.join(promises) as TPromise<any>;
}
}
function parsePathArguments(cwd: string, args: string[], gotoLineMode?: boolean): string[] {
+1 -13
View File
@@ -9,7 +9,6 @@ import * as nls from 'vs/nls';
import * as fs from 'original-fs';
import { app, ipcMain as ipc } from 'electron';
import { assign } from 'vs/base/common/objects';
import { mkdirp } from 'vs/base/node/pfs';
import * as platform from 'vs/base/common/platform';
import { IProcessEnvironment, IEnvironmentService, EnvService } from 'vs/code/electron-main/env';
import { IWindowsService, WindowsManager } from 'vs/code/electron-main/windows';
@@ -255,17 +254,6 @@ function setupIPC(accessor: ServicesAccessor): TPromise<Server> {
return setup(true);
}
// TODO@Joao: what about in the cli process?
function createPaths(accessor: ServicesAccessor): TPromise<void> {
const environmentService = accessor.get(IEnvironmentService);
return TPromise.join([
mkdirp(environmentService.appSettingsHome),
mkdirp(environmentService.userHome),
mkdirp(environmentService.userExtensionsHome)
]) as any as TPromise<void>;
}
// TODO: isolate
const services = new ServiceCollection();
@@ -357,7 +345,7 @@ getUserEnvironment()
// See also https://github.com/Microsoft/vscode/issues/4558
userEnv['VSCODE_NLS_CONFIG'] = process.env['VSCODE_NLS_CONFIG'];
return instantiationService.invokeFunction(createPaths)
return instantiationService.invokeFunction(a => a.get(IEnvironmentService).createPaths())
.then(() => instantiationService.invokeFunction(setupIPC))
.then(ipcServer => instantiationService.invokeFunction(main, ipcServer, userEnv));
})
+37 -33
View File
@@ -134,44 +134,48 @@ export function main(argv: ParsedArgs): TPromise<void> {
const instantiationService: IInstantiationService = new InstantiationService(services);
return instantiationService.invokeFunction(accessor => {
const services = new ServiceCollection();
services.set(IEventService, new SyncDescriptor(EventService));
services.set(IConfigurationService, new SyncDescriptor(NodeConfigurationService));
services.set(IRequestService, new SyncDescriptor(NodeRequestService));
services.set(IExtensionManagementService, new SyncDescriptor(ExtensionManagementService));
services.set(IExtensionGalleryService, new SyncDescriptor(ExtensionGalleryService));
const envService = accessor.get(IEnvironmentService);
const { appRoot, extensionsPath, extensionDevelopmentPath, isBuilt } = accessor.get(IEnvironmentService);
return envService.createPaths().then(() => {
const { appRoot, extensionsPath, extensionDevelopmentPath, isBuilt } = envService;
if (isBuilt && !extensionDevelopmentPath && product.enableTelemetry) {
const appenders: AppInsightsAppender[] = [];
const services = new ServiceCollection();
services.set(IEventService, new SyncDescriptor(EventService));
services.set(IConfigurationService, new SyncDescriptor(NodeConfigurationService));
services.set(IRequestService, new SyncDescriptor(NodeRequestService));
services.set(IExtensionManagementService, new SyncDescriptor(ExtensionManagementService));
services.set(IExtensionGalleryService, new SyncDescriptor(ExtensionGalleryService));
if (product.aiConfig && product.aiConfig.key) {
appenders.push(new AppInsightsAppender(eventPrefix, null, product.aiConfig.key));
if (isBuilt && !extensionDevelopmentPath && product.enableTelemetry) {
const appenders: AppInsightsAppender[] = [];
if (product.aiConfig && product.aiConfig.key) {
appenders.push(new AppInsightsAppender(eventPrefix, null, product.aiConfig.key));
}
if (product.aiConfig && product.aiConfig.asimovKey) {
appenders.push(new AppInsightsAppender(eventPrefix, null, product.aiConfig.asimovKey));
}
// It is important to dispose the AI adapter properly because
// only then they flush remaining data.
process.once('exit', () => appenders.forEach(a => a.dispose()));
const config: ITelemetryServiceConfig = {
appender: combinedAppender(...appenders),
commonProperties: resolveCommonProperties(product.commit, pkg.version),
piiPaths: [appRoot, extensionsPath]
};
services.set(ITelemetryService, new SyncDescriptor(TelemetryService, config));
} else {
services.set(ITelemetryService, NullTelemetryService);
}
if (product.aiConfig && product.aiConfig.asimovKey) {
appenders.push(new AppInsightsAppender(eventPrefix, null, product.aiConfig.asimovKey));
}
const instantiationService2 = instantiationService.createChild(services);
const main = instantiationService2.createInstance(Main);
// It is important to dispose the AI adapter properly because
// only then they flush remaining data.
process.once('exit', () => appenders.forEach(a => a.dispose()));
const config: ITelemetryServiceConfig = {
appender: combinedAppender(...appenders),
commonProperties: resolveCommonProperties(product.commit, pkg.version),
piiPaths: [appRoot, extensionsPath]
};
services.set(ITelemetryService, new SyncDescriptor(TelemetryService, config));
} else {
services.set(ITelemetryService, NullTelemetryService);
}
const instantiationService2 = instantiationService.createChild(services);
const main = instantiationService2.createInstance(Main);
return main.run(argv);
return main.run(argv);
});
});
}