Skip to content

Commit

Permalink
Emit change events from the configuration service (microsoft/monaco-e…
Browse files Browse the repository at this point in the history
  • Loading branch information
alexdima committed Feb 19, 2020
1 parent da49b05 commit 1233630
Showing 1 changed file with 35 additions and 12 deletions.
47 changes: 35 additions & 12 deletions src/vs/editor/standalone/browser/simpleServices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { IResolvedTextEditorModel, ITextModelContentProvider, ITextModelService
import { ITextResourceConfigurationService, ITextResourcePropertiesService, ITextResourceConfigurationChangeEvent } from 'vs/editor/common/services/textResourceConfigurationService';
import { CommandsRegistry, ICommand, ICommandEvent, ICommandHandler, ICommandService } from 'vs/platform/commands/common/commands';
import { IConfigurationChangeEvent, IConfigurationData, IConfigurationOverrides, IConfigurationService, IConfigurationModel, IConfigurationValue, ConfigurationTarget } from 'vs/platform/configuration/common/configuration';
import { Configuration, ConfigurationModel, DefaultConfigurationModel } from 'vs/platform/configuration/common/configurationModels';
import { Configuration, ConfigurationModel, DefaultConfigurationModel, ConfigurationChangeEvent } from 'vs/platform/configuration/common/configurationModels';
import { ContextKeyExpr, IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
import { IConfirmation, IConfirmationResult, IDialogOptions, IDialogService, IShowResult } from 'vs/platform/dialogs/common/dialogs';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
Expand Down Expand Up @@ -448,31 +448,50 @@ export class SimpleConfigurationService implements IConfigurationService {
this._configuration = new Configuration(new DefaultConfigurationModel(), new ConfigurationModel());
}

private configuration(): Configuration {
return this._configuration;
}

getValue<T>(): T;
getValue<T>(section: string): T;
getValue<T>(overrides: IConfigurationOverrides): T;
getValue<T>(section: string, overrides: IConfigurationOverrides): T;
getValue(arg1?: any, arg2?: any): any {
const section = typeof arg1 === 'string' ? arg1 : undefined;
const overrides = isConfigurationOverrides(arg1) ? arg1 : isConfigurationOverrides(arg2) ? arg2 : {};
return this.configuration().getValue(section, overrides, undefined);
return this._configuration.getValue(section, overrides, undefined);
}

public updateValue(key: string, value: any, arg3?: any, arg4?: any): Promise<void> {
this.configuration().updateValue(key, value);
public updateValues(values: [string, any][]): Promise<void> {
const previous = { data: this._configuration.toData() };

let changedKeys: string[] = [];

for (const entry of values) {
const [key, value] = entry;
if (this.getValue(key) === value) {
continue;
}
this._configuration.updateValue(key, value);
changedKeys.push(key);
}

if (changedKeys.length > 0) {
const configurationChangeEvent = new ConfigurationChangeEvent({ keys: changedKeys, overrides: [] }, previous, this._configuration);
configurationChangeEvent.source = ConfigurationTarget.MEMORY;
configurationChangeEvent.sourceConfig = null;
this._onDidChangeConfiguration.fire(configurationChangeEvent);
}

return Promise.resolve();
}

public updateValue(key: string, value: any, arg3?: any, arg4?: any): Promise<void> {
return this.updateValues([[key, value]]);
}

public inspect<C>(key: string, options: IConfigurationOverrides = {}): IConfigurationValue<C> {
return this.configuration().inspect<C>(key, options, undefined);
return this._configuration.inspect<C>(key, options, undefined);
}

public keys() {
return this.configuration().keys(undefined);
return this._configuration.keys(undefined);
}

public reloadConfiguration(): Promise<void> {
Expand Down Expand Up @@ -622,14 +641,18 @@ export function applyConfigurationValues(configurationService: IConfigurationSer
if (!(configurationService instanceof SimpleConfigurationService)) {
return;
}
let toUpdate: [string, any][] = [];
Object.keys(source).forEach((key) => {
if (isEditorConfigurationKey(key)) {
configurationService.updateValue(`editor.${key}`, source[key]);
toUpdate.push([`editor.${key}`, source[key]]);
}
if (isDiffEditor && isDiffEditorConfigurationKey(key)) {
configurationService.updateValue(`diffEditor.${key}`, source[key]);
toUpdate.push([`diffEditor.${key}`, source[key]]);
}
});
if (toUpdate.length > 0) {
configurationService.updateValues(toUpdate);
}
}

export class SimpleBulkEditService implements IBulkEditService {
Expand Down

0 comments on commit 1233630

Please sign in to comment.