Skip to content

Commit

Permalink
Fix #74661
Browse files Browse the repository at this point in the history
  • Loading branch information
sandy081 committed Jun 4, 2019
1 parent f256ab1 commit 3dc76ed
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 121 deletions.
11 changes: 7 additions & 4 deletions src/vs/code/electron-browser/sharedProcess/sharedProcessMain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class MainProcessService implements IMainProcessService {
}
}

function main(server: Server, initData: ISharedProcessInitData, configuration: ISharedProcessConfiguration): void {
async function main(server: Server, initData: ISharedProcessInitData, configuration: ISharedProcessConfiguration): Promise<void> {
const services = new ServiceCollection();

const disposables: IDisposable[] = [];
Expand All @@ -96,12 +96,15 @@ function main(server: Server, initData: ISharedProcessInitData, configuration: I
const logLevelClient = new LogLevelSetterChannelClient(server.getChannel('loglevel', mainRouter));
const logService = new FollowerLogService(logLevelClient, new SpdLogService('sharedprocess', environmentService.logsPath, initData.logLevel));
disposables.push(logService);

logService.info('main', JSON.stringify(configuration));

const configurationService = new ConfigurationService(environmentService.appSettingsPath);
disposables.push(configurationService);
await configurationService.initialize();

services.set(IEnvironmentService, environmentService);
services.set(ILogService, logService);
services.set(IConfigurationService, new SyncDescriptor(ConfigurationService, [environmentService.appSettingsPath]));
services.set(IConfigurationService, configurationService);
services.set(IRequestService, new SyncDescriptor(RequestService));
services.set(IDownloadService, new SyncDescriptor(DownloadService));

Expand Down Expand Up @@ -218,6 +221,6 @@ async function handshake(configuration: ISharedProcessConfiguration): Promise<vo

const server = await setupIPC(data.sharedIPCHandle);

main(server, data, configuration);
await main(server, data, configuration);
ipcRenderer.send('handshake:im ready');
}
3 changes: 1 addition & 2 deletions src/vs/code/electron-main/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ import product from 'vs/platform/product/node/product';
import pkg from 'vs/platform/product/node/package';
import { ProxyAuthHandler } from 'vs/code/electron-main/auth';
import { Disposable } from 'vs/base/common/lifecycle';
import { ConfigurationService } from 'vs/platform/configuration/node/configurationService';
import { IWindowsMainService, ICodeWindow } from 'vs/platform/windows/electron-main/windows';
import { IHistoryMainService } from 'vs/platform/history/common/history';
import { withUndefinedAsNull } from 'vs/base/common/types';
Expand Down Expand Up @@ -98,7 +97,7 @@ export class CodeApplication extends Disposable {
@ILogService private readonly logService: ILogService,
@IEnvironmentService private readonly environmentService: IEnvironmentService,
@ILifecycleService private readonly lifecycleService: ILifecycleService,
@IConfigurationService private readonly configurationService: ConfigurationService,
@IConfigurationService private readonly configurationService: IConfigurationService,
@IStateService private readonly stateService: IStateService
) {
super();
Expand Down
12 changes: 8 additions & 4 deletions src/vs/code/electron-main/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,11 @@ class CodeMain {
// Init services
await instantiationService.invokeFunction(async accessor => {
const environmentService = accessor.get(IEnvironmentService);
const configurationService = accessor.get(IConfigurationService);
const stateService = accessor.get(IStateService);

try {
await this.initServices(environmentService, stateService as StateService);
await this.initServices(environmentService, configurationService as ConfigurationService, stateService as StateService);
} catch (error) {

// Show a dialog for errors that can be resolved by the user
Expand Down Expand Up @@ -140,17 +141,17 @@ class CodeMain {
process.once('exit', () => logService.dispose());
services.set(ILogService, logService);

services.set(IConfigurationService, new ConfigurationService(environmentService.appSettingsPath));
services.set(ILifecycleService, new SyncDescriptor(LifecycleService));
services.set(IStateService, new SyncDescriptor(StateService));
services.set(IConfigurationService, new SyncDescriptor(ConfigurationService, [environmentService.appSettingsPath]));
services.set(IRequestService, new SyncDescriptor(RequestService));
services.set(IDiagnosticsService, new SyncDescriptor(DiagnosticsService));
services.set(IThemeMainService, new SyncDescriptor(ThemeMainService));

return [new InstantiationService(services, true), instanceEnvironment];
}

private initServices(environmentService: IEnvironmentService, stateService: StateService): Promise<unknown> {
private initServices(environmentService: IEnvironmentService, configurationService: ConfigurationService, stateService: StateService): Promise<unknown> {

// Environment service (paths)
const environmentServiceInitialization = Promise.all<void | undefined>([
Expand All @@ -162,10 +163,13 @@ class CodeMain {
environmentService.backupHome
].map((path): undefined | Promise<void> => path ? mkdirp(path) : undefined));

// Configuration service
const configurationServiceInitialization = configurationService.initialize();

// State service
const stateServiceInitialization = stateService.init();

return Promise.all([environmentServiceInitialization, stateServiceInitialization]);
return Promise.all([environmentServiceInitialization, configurationServiceInitialization, stateServiceInitialization]);
}

private patchEnvironment(environmentService: IEnvironmentService): typeof process.env {
Expand Down
60 changes: 31 additions & 29 deletions src/vs/code/node/cliProcessMain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,17 +275,22 @@ export class Main {

const eventPrefix = 'monacoworkbench';

export function main(argv: ParsedArgs): Promise<void> {
export async function main(argv: ParsedArgs): Promise<void> {
const services = new ServiceCollection();

const environmentService = new EnvironmentService(argv, process.execPath);
const logService: ILogService = new SpdLogService('cli', environmentService.logsPath, getLogLevel(environmentService));
process.once('exit', () => logService.dispose());

logService.info('main', argv);

await Promise.all([environmentService.appSettingsHome, environmentService.extensionsPath].map(p => mkdirp(p)));

const configurationService = new ConfigurationService(environmentService.appSettingsPath);
await configurationService.initialize();

services.set(IEnvironmentService, environmentService);
services.set(ILogService, logService);
services.set(IConfigurationService, configurationService);
services.set(IStateService, new SyncDescriptor(StateService));

const instantiationService: IInstantiationService = new InstantiationService(services);
Expand All @@ -294,40 +299,37 @@ export function main(argv: ParsedArgs): Promise<void> {
const envService = accessor.get(IEnvironmentService);
const stateService = accessor.get(IStateService);

return Promise.all([envService.appSettingsHome, envService.extensionsPath].map(p => mkdirp(p))).then(() => {
const { appRoot, extensionsPath, extensionDevelopmentLocationURI: extensionDevelopmentLocationURI, isBuilt, installSourcePath } = envService;
const { appRoot, extensionsPath, extensionDevelopmentLocationURI: extensionDevelopmentLocationURI, isBuilt, installSourcePath } = envService;

const services = new ServiceCollection();
services.set(IConfigurationService, new SyncDescriptor(ConfigurationService, [environmentService.appSettingsPath]));
services.set(IRequestService, new SyncDescriptor(RequestService));
services.set(IExtensionManagementService, new SyncDescriptor(ExtensionManagementService));
services.set(IExtensionGalleryService, new SyncDescriptor(ExtensionGalleryService));
const services = new ServiceCollection();
services.set(IRequestService, new SyncDescriptor(RequestService));
services.set(IExtensionManagementService, new SyncDescriptor(ExtensionManagementService));
services.set(IExtensionGalleryService, new SyncDescriptor(ExtensionGalleryService));

const appenders: AppInsightsAppender[] = [];
if (isBuilt && !extensionDevelopmentLocationURI && !envService.args['disable-telemetry'] && product.enableTelemetry) {
const appenders: AppInsightsAppender[] = [];
if (isBuilt && !extensionDevelopmentLocationURI && !envService.args['disable-telemetry'] && product.enableTelemetry) {

if (product.aiConfig && product.aiConfig.asimovKey) {
appenders.push(new AppInsightsAppender(eventPrefix, null, product.aiConfig.asimovKey, logService));
}
if (product.aiConfig && product.aiConfig.asimovKey) {
appenders.push(new AppInsightsAppender(eventPrefix, null, product.aiConfig.asimovKey, logService));
}

const config: ITelemetryServiceConfig = {
appender: combinedAppender(...appenders),
commonProperties: resolveCommonProperties(product.commit, pkg.version, stateService.getItem('telemetry.machineId'), installSourcePath),
piiPaths: [appRoot, extensionsPath]
};
const config: ITelemetryServiceConfig = {
appender: combinedAppender(...appenders),
commonProperties: resolveCommonProperties(product.commit, pkg.version, stateService.getItem('telemetry.machineId'), installSourcePath),
piiPaths: [appRoot, extensionsPath]
};

services.set(ITelemetryService, new SyncDescriptor(TelemetryService, [config]));
} else {
services.set(ITelemetryService, NullTelemetryService);
}
services.set(ITelemetryService, new SyncDescriptor(TelemetryService, [config]));
} else {
services.set(ITelemetryService, NullTelemetryService);
}

const instantiationService2 = instantiationService.createChild(services);
const main = instantiationService2.createInstance(Main);
const instantiationService2 = instantiationService.createChild(services);
const main = instantiationService2.createInstance(Main);

return main.run(argv).then(() => {
// Dispose the AI adapter so that remaining data gets flushed.
return combinedAppender(...appenders).dispose();
});
return main.run(argv).then(() => {
// Dispose the AI adapter so that remaining data gets flushed.
return combinedAppender(...appenders).dispose();
});
});
}
56 changes: 0 additions & 56 deletions src/vs/platform/configuration/node/configuration.ts

This file was deleted.

62 changes: 38 additions & 24 deletions src/vs/platform/configuration/node/configurationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,40 +7,49 @@ import { Registry } from 'vs/platform/registry/common/platform';
import { IConfigurationRegistry, Extensions } from 'vs/platform/configuration/common/configurationRegistry';
import { IDisposable, Disposable } from 'vs/base/common/lifecycle';
import { IConfigurationService, IConfigurationChangeEvent, IConfigurationOverrides, ConfigurationTarget, compare, isConfigurationOverrides, IConfigurationData } from 'vs/platform/configuration/common/configuration';
import { DefaultConfigurationModel, Configuration, ConfigurationChangeEvent, ConfigurationModel } from 'vs/platform/configuration/common/configurationModels';
import { DefaultConfigurationModel, Configuration, ConfigurationChangeEvent, ConfigurationModel, ConfigurationModelParser } from 'vs/platform/configuration/common/configurationModels';
import { Event, Emitter } from 'vs/base/common/event';
import { IWorkspaceFolder } from 'vs/platform/workspace/common/workspace';
import { NodeBasedUserConfiguration } from 'vs/platform/configuration/node/configuration';
import { ConfigWatcher } from 'vs/base/node/config';
import { onUnexpectedError } from 'vs/base/common/errors';

export class ConfigurationService extends Disposable implements IConfigurationService, IDisposable {

_serviceBrand: any;

private _configuration: Configuration;
private userConfiguration: NodeBasedUserConfiguration;
private configuration: Configuration;
private userConfigModelWatcher: ConfigWatcher<ConfigurationModelParser> | undefined;

private readonly _onDidChangeConfiguration: Emitter<IConfigurationChangeEvent> = this._register(new Emitter<IConfigurationChangeEvent>());
readonly onDidChangeConfiguration: Event<IConfigurationChangeEvent> = this._onDidChangeConfiguration.event;

constructor(
configurationPath: string
private readonly configurationPath: string
) {
super();

this.userConfiguration = this._register(new NodeBasedUserConfiguration(configurationPath));

// Initialize
const defaults = new DefaultConfigurationModel();
const user = this.userConfiguration.initializeSync();
this._configuration = new Configuration(defaults, user);

// Listeners
this._register(this.userConfiguration.onDidChangeConfiguration(userConfigurationModel => this.onDidChangeUserConfiguration(userConfigurationModel)));
this.configuration = new Configuration(new DefaultConfigurationModel(), new ConfigurationModel());
this._register(Registry.as<IConfigurationRegistry>(Extensions.Configuration).onDidUpdateConfiguration(configurationProperties => this.onDidDefaultConfigurationChange(configurationProperties)));
}

get configuration(): Configuration {
return this._configuration;
initialize(): Promise<void> {
if (this.userConfigModelWatcher) {
this.userConfigModelWatcher.dispose();
}

return new Promise<void>((c, e) => {
this.userConfigModelWatcher = this._register(new ConfigWatcher(this.configurationPath, {
changeBufferDelay: 300, onError: error => onUnexpectedError(error), defaultConfig: new ConfigurationModelParser(this.configurationPath), parse: (content: string, parseErrors: any[]) => {
const userConfigModelParser = new ConfigurationModelParser(this.configurationPath);
userConfigModelParser.parseContent(content);
parseErrors = [...userConfigModelParser.errors];
return userConfigModelParser;
}, initCallback: () => {
this.configuration = new Configuration(new DefaultConfigurationModel(), this.userConfigModelWatcher!.getConfig().configurationModel);
this._register(this.userConfigModelWatcher!.onDidUpdateConfiguration(() => this.onDidChangeUserConfiguration(this.userConfigModelWatcher!.getConfig().configurationModel)));
c();
}
}));
});
}

getConfigurationData(): IConfigurationData {
Expand Down Expand Up @@ -85,21 +94,26 @@ export class ConfigurationService extends Disposable implements IConfigurationSe
}

reloadConfiguration(folder?: IWorkspaceFolder): Promise<void> {
return folder ? Promise.resolve(undefined) :
this.userConfiguration.reload().then(userConfigurationModel => this.onDidChangeUserConfiguration(userConfigurationModel));
if (this.userConfigModelWatcher) {
return new Promise<void>(c => this.userConfigModelWatcher!.reload(userConfigModelParser => {
this.onDidChangeUserConfiguration(userConfigModelParser.configurationModel);
c();
}));
}
return this.initialize();
}

private onDidChangeUserConfiguration(userConfigurationModel: ConfigurationModel): void {
const { added, updated, removed } = compare(this._configuration.localUserConfiguration, userConfigurationModel);
const { added, updated, removed } = compare(this.configuration.localUserConfiguration, userConfigurationModel);
const changedKeys = [...added, ...updated, ...removed];
if (changedKeys.length) {
this._configuration.updateLocalUserConfiguration(userConfigurationModel);
this.configuration.updateLocalUserConfiguration(userConfigurationModel);
this.trigger(changedKeys, ConfigurationTarget.USER);
}
}

private onDidDefaultConfigurationChange(keys: string[]): void {
this._configuration.updateDefaultConfiguration(new DefaultConfigurationModel());
this.configuration.updateDefaultConfiguration(new DefaultConfigurationModel());
this.trigger(keys, ConfigurationTarget.DEFAULT);
}

Expand All @@ -110,9 +124,9 @@ export class ConfigurationService extends Disposable implements IConfigurationSe
private getTargetConfiguration(target: ConfigurationTarget): any {
switch (target) {
case ConfigurationTarget.DEFAULT:
return this._configuration.defaults.contents;
return this.configuration.defaults.contents;
case ConfigurationTarget.USER:
return this._configuration.localUserConfiguration.contents;
return this.configuration.localUserConfiguration.contents;
}
return {};
}
Expand Down
Loading

0 comments on commit 3dc76ed

Please sign in to comment.