Skip to content

Commit 6bd03bf

Browse files
committed
add overrides information to change event
1 parent 77b257a commit 6bd03bf

4 files changed

Lines changed: 105 additions & 39 deletions

File tree

src/vs/platform/configuration/common/configuration.ts

Lines changed: 66 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { IWorkspaceFolder } from 'vs/platform/workspace/common/workspace';
1212
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
1313
import { IConfigurationRegistry, Extensions, OVERRIDE_PROPERTY_PATTERN } from 'vs/platform/configuration/common/configurationRegistry';
1414
import { ResourceMap } from 'vs/base/common/map';
15+
import { IStringDictionary } from 'vs/base/common/collections';
1516

1617
export const IConfigurationService = createDecorator<IConfigurationService>('configurationService');
1718

@@ -132,6 +133,7 @@ export interface IConfigurationModel {
132133
}
133134

134135
export interface IOverrides {
136+
keys: string[];
135137
contents: any;
136138
identifiers: string[];
137139
}
@@ -143,20 +145,74 @@ export interface IConfigurationData {
143145
folders: [UriComponents, IConfigurationModel][];
144146
}
145147

146-
export function compare(from: IConfigurationModel, to: IConfigurationModel): { added: string[], removed: string[], updated: string[] } {
147-
const added = to.keys.filter(key => from.keys.indexOf(key) === -1);
148-
const removed = from.keys.filter(key => to.keys.indexOf(key) === -1);
148+
export interface IConfigurationCompareResult {
149+
added: string[];
150+
removed: string[];
151+
updated: string[];
152+
overrides: [string, string[]][];
153+
}
154+
155+
export function compare(from: IConfigurationModel | undefined, to: IConfigurationModel | undefined): IConfigurationCompareResult {
156+
const added = to
157+
? from ? to.keys.filter(key => from.keys.indexOf(key) === -1) : [...to.keys]
158+
: [];
159+
const removed = from
160+
? to ? from.keys.filter(key => to.keys.indexOf(key) === -1) : [...from.keys]
161+
: [];
149162
const updated: string[] = [];
150163

151-
for (const key of from.keys) {
152-
const value1 = getConfigurationValue(from.contents, key);
153-
const value2 = getConfigurationValue(to.contents, key);
154-
if (!objects.equals(value1, value2)) {
155-
updated.push(key);
164+
if (to && from) {
165+
for (const key of from.keys) {
166+
const value1 = getConfigurationValue(from.contents, key);
167+
const value2 = getConfigurationValue(to.contents, key);
168+
if (!objects.equals(value1, value2)) {
169+
updated.push(key);
170+
}
171+
}
172+
}
173+
174+
const overrides: [string, string[]][] = [];
175+
const byOverrideIdentifier = (overrides: IOverrides[]): IStringDictionary<IOverrides> => {
176+
const result: IStringDictionary<IOverrides> = {};
177+
for (const override of overrides) {
178+
for (const identifier of override.identifiers) {
179+
result[identifier] = override;
180+
}
181+
}
182+
return result;
183+
};
184+
const toOverridesByIdentifier: IStringDictionary<IOverrides> = to ? byOverrideIdentifier(to.overrides) : {};
185+
const fromOverridesByIdentifier: IStringDictionary<IOverrides> = from ? byOverrideIdentifier(from.overrides) : {};
186+
187+
if (Object.keys(toOverridesByIdentifier).length) {
188+
for (const key of added) {
189+
const override = toOverridesByIdentifier[key];
190+
if (override) {
191+
overrides.push([key, override.keys]);
192+
}
193+
}
194+
}
195+
if (Object.keys(fromOverridesByIdentifier).length) {
196+
for (const key of removed) {
197+
const override = fromOverridesByIdentifier[key];
198+
if (override) {
199+
overrides.push([key, override.keys]);
200+
}
201+
}
202+
}
203+
204+
if (Object.keys(toOverridesByIdentifier).length && Object.keys(fromOverridesByIdentifier).length) {
205+
for (const key of updated) {
206+
const fromOverride = fromOverridesByIdentifier[key];
207+
const toOverride = toOverridesByIdentifier[key];
208+
if (fromOverride && toOverride) {
209+
const result = compare({ contents: fromOverride.contents, keys: fromOverride.keys, overrides: [] }, { contents: toOverride.contents, keys: toOverride.keys, overrides: [] });
210+
overrides.push([key, [...result.added, ...result.removed, ...result.updated]]);
211+
}
156212
}
157213
}
158214

159-
return { added, removed, updated };
215+
return { added, removed, updated, overrides };
160216
}
161217

162218
export function toOverrides(raw: any, conflictReporter: (message: string) => void): IOverrides[] {
@@ -172,6 +228,7 @@ export function toOverrides(raw: any, conflictReporter: (message: string) => voi
172228
}
173229
overrides.push({
174230
identifiers: [overrideIdentifierFromKey(key).trim()],
231+
keys: Object.keys(overrideRaw),
175232
contents: toValuesTree(overrideRaw, conflictReporter)
176233
});
177234
}

src/vs/platform/configuration/common/configurationModels.ts

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,8 @@ export class DefaultConfigurationModel extends ConfigurationModel {
192192
if (OVERRIDE_PROPERTY_PATTERN.test(key)) {
193193
overrides.push({
194194
identifiers: [overrideIdentifierFromKey(key).trim()],
195-
contents: toValuesTree(contents[key], message => console.error(`Conflict in default settings file: ${message}`))
195+
keys: Object.keys(contents[key]),
196+
contents: toValuesTree(contents[key], message => console.error(`Conflict in default settings file: ${message}`)),
196197
});
197198
}
198199
}
@@ -638,13 +639,21 @@ export class AbstractConfigurationChangeEvent {
638639
return true;
639640
}
640641

641-
protected updateKeys(configuration: ConfigurationModel, keys: string[], resource?: URI): void {
642+
protected updateKeys(configuration: ConfigurationModel, { keys, overrides }: IConfigurationChange, resource?: URI): void {
642643
for (const key of keys) {
643644
configuration.setValue(key, {});
644645
}
646+
for (const [overrideIdentifier, keys] of overrides) {
647+
configuration.setValue(overrideIdentifier, keys.reduce((value: any, key) => { value[key] = {}; return value; }, {}));
648+
}
645649
}
646650
}
647651

652+
export interface IConfigurationChange {
653+
keys: string[];
654+
overrides: [string, string[]][];
655+
}
656+
648657
export class ConfigurationChangeEvent extends AbstractConfigurationChangeEvent implements IConfigurationChangeEvent {
649658

650659
private _source: ConfigurationTarget;
@@ -665,8 +674,8 @@ export class ConfigurationChangeEvent extends AbstractConfigurationChangeEvent i
665674
return this._changedConfigurationByResource;
666675
}
667676

668-
change(event: ConfigurationChangeEvent): ConfigurationChangeEvent;
669-
change(keys: string[], resource?: URI): ConfigurationChangeEvent;
677+
change(changeEvent: ConfigurationChangeEvent): ConfigurationChangeEvent;
678+
change(change: IConfigurationChange, resource?: URI): ConfigurationChangeEvent;
670679
change(arg1: any, arg2?: any): ConfigurationChangeEvent {
671680
if (arg1 instanceof ConfigurationChangeEvent) {
672681
this._changedConfiguration = this._changedConfiguration.merge(arg1._changedConfiguration);
@@ -716,9 +725,9 @@ export class ConfigurationChangeEvent extends AbstractConfigurationChangeEvent i
716725
return configurationModelsToSearch.some(configuration => this.doesConfigurationContains(configuration, config));
717726
}
718727

719-
private changeWithKeys(keys: string[], resource?: URI): void {
728+
private changeWithKeys(change: IConfigurationChange, resource?: URI): void {
720729
let changedConfiguration = resource ? this.getOrSetChangedConfigurationForResource(resource) : this._changedConfiguration;
721-
this.updateKeys(changedConfiguration, keys);
730+
this.updateKeys(changedConfiguration, change);
722731
}
723732

724733
private getOrSetChangedConfigurationForResource(resource: URI): ConfigurationModel {

src/vs/workbench/api/node/extHostLogService.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,13 @@ export class ExtHostLogService extends DelegatedLogService implements ILogServic
2020

2121
constructor(
2222
@IExtHostInitDataService initData: IExtHostInitDataService,
23+
@IExtHostOutputService outputSerice: IExtHostOutputService,
2324
) {
2425
if (initData.logFile.scheme !== Schemas.file) { throw new Error('Only file-logging supported'); }
2526
super(new SpdLogService(ExtensionHostLogFileName, dirname(initData.logFile).fsPath, initData.logLevel));
27+
outputSerice.createOutputChannelFromLogFile(
28+
initData.remote.isRemote ? localize('remote extension host Log', "Remote Extension Host") : localize('extension host Log', "Extension Host"),
29+
initData.logFile);
2630
}
2731

2832
$setLevel(level: LogLevel): void {

src/vs/workbench/services/configuration/common/configurationModels.ts

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -128,45 +128,40 @@ export class Configuration extends BaseConfiguration {
128128
}
129129

130130
compareAndUpdateLocalUserConfiguration(user: ConfigurationModel): ConfigurationChangeEvent {
131-
const { added, updated, removed } = compare(this.localUserConfiguration, user);
132-
let changedKeys = [...added, ...updated, ...removed];
133-
if (changedKeys.length) {
131+
const { added, updated, removed, overrides } = compare(this.localUserConfiguration, user);
132+
const keys = [...added, ...updated, ...removed];
133+
if (keys.length) {
134134
super.updateLocalUserConfiguration(user);
135135
}
136-
return new ConfigurationChangeEvent().change(changedKeys);
136+
return new ConfigurationChangeEvent().change({ keys, overrides });
137137
}
138138

139139
compareAndUpdateRemoteUserConfiguration(user: ConfigurationModel): ConfigurationChangeEvent {
140-
const { added, updated, removed } = compare(this.remoteUserConfiguration, user);
141-
let changedKeys = [...added, ...updated, ...removed];
142-
if (changedKeys.length) {
140+
const { added, updated, removed, overrides } = compare(this.remoteUserConfiguration, user);
141+
let keys = [...added, ...updated, ...removed];
142+
if (keys.length) {
143143
super.updateRemoteUserConfiguration(user);
144144
}
145-
return new ConfigurationChangeEvent().change(changedKeys);
145+
return new ConfigurationChangeEvent().change({ keys, overrides });
146146
}
147147

148148
compareAndUpdateWorkspaceConfiguration(workspaceConfiguration: ConfigurationModel): ConfigurationChangeEvent {
149-
const { added, updated, removed } = compare(this.workspaceConfiguration, workspaceConfiguration);
150-
let changedKeys = [...added, ...updated, ...removed];
151-
if (changedKeys.length) {
149+
const { added, updated, removed, overrides } = compare(this.workspaceConfiguration, workspaceConfiguration);
150+
let keys = [...added, ...updated, ...removed];
151+
if (keys.length) {
152152
super.updateWorkspaceConfiguration(workspaceConfiguration);
153153
}
154-
return new ConfigurationChangeEvent().change(changedKeys);
154+
return new ConfigurationChangeEvent().change({ keys, overrides });
155155
}
156156

157157
compareAndUpdateFolderConfiguration(resource: URI, folderConfiguration: ConfigurationModel): ConfigurationChangeEvent {
158158
const currentFolderConfiguration = this.folderConfigurations.get(resource);
159-
if (currentFolderConfiguration) {
160-
const { added, updated, removed } = compare(currentFolderConfiguration, folderConfiguration);
161-
let changedKeys = [...added, ...updated, ...removed];
162-
if (changedKeys.length) {
163-
super.updateFolderConfiguration(resource, folderConfiguration);
164-
}
165-
return new ConfigurationChangeEvent().change(changedKeys, resource);
166-
} else {
159+
const { added, updated, removed, overrides } = compare(currentFolderConfiguration, folderConfiguration);
160+
let keys = [...added, ...updated, ...removed];
161+
if (keys.length) {
167162
super.updateFolderConfiguration(resource, folderConfiguration);
168-
return new ConfigurationChangeEvent().change(folderConfiguration.keys, resource);
169163
}
164+
return new ConfigurationChangeEvent().change({ keys, overrides }, resource);
170165
}
171166

172167
compareAndDeleteFolderConfiguration(folder: URI): ConfigurationChangeEvent {
@@ -178,9 +173,9 @@ export class Configuration extends BaseConfiguration {
178173
if (!folderConfig) {
179174
throw new Error('Unknown folder');
180175
}
181-
const keys = folderConfig.keys;
182176
super.deleteFolderConfiguration(folder);
183-
return new ConfigurationChangeEvent().change(keys, folder);
177+
const { added, updated, removed, overrides } = compare(folderConfig, undefined);
178+
return new ConfigurationChangeEvent().change({ keys: [...added, ...updated, ...removed], overrides }, folder);
184179
}
185180

186181
compare(other: Configuration): string[] {
@@ -208,7 +203,8 @@ export class AllKeysConfigurationChangeEvent extends AbstractConfigurationChange
208203
get changedConfiguration(): ConfigurationModel {
209204
if (!this._changedConfiguration) {
210205
this._changedConfiguration = new ConfigurationModel();
211-
this.updateKeys(this._changedConfiguration, this.affectedKeys);
206+
const { added, updated, removed, overrides } = compare(undefined, this._changedConfiguration);
207+
this.updateKeys(this._changedConfiguration, { keys: [...added, ...updated, ...removed], overrides });
212208
}
213209
return this._changedConfiguration;
214210
}

0 commit comments

Comments
 (0)