mirror of
https://github.com/Microsoft/vscode
synced 2024-08-27 13:00:58 +00:00
#51935 use overrides from the model
This commit is contained in:
parent
303bd5d617
commit
4e29d28afb
|
@ -3,9 +3,7 @@
|
|||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { IStringDictionary } from 'vs/base/common/collections';
|
||||
import { Event } from 'vs/base/common/event';
|
||||
import * as objects from 'vs/base/common/objects';
|
||||
import * as types from 'vs/base/common/types';
|
||||
import { URI, UriComponents } from 'vs/base/common/uri';
|
||||
import { Extensions, IConfigurationRegistry, overrideIdentifierFromKey, OVERRIDE_PROPERTY_PATTERN } from 'vs/platform/configuration/common/configurationRegistry';
|
||||
|
@ -151,71 +149,6 @@ export interface IConfigurationCompareResult {
|
|||
overrides: [string, string[]][];
|
||||
}
|
||||
|
||||
export function compare(from: IConfigurationModel | undefined, to: IConfigurationModel | undefined): IConfigurationCompareResult {
|
||||
const added = to
|
||||
? from ? to.keys.filter(key => from.keys.indexOf(key) === -1) : [...to.keys]
|
||||
: [];
|
||||
const removed = from
|
||||
? to ? from.keys.filter(key => to.keys.indexOf(key) === -1) : [...from.keys]
|
||||
: [];
|
||||
const updated: string[] = [];
|
||||
|
||||
if (to && from) {
|
||||
for (const key of from.keys) {
|
||||
if (to.keys.indexOf(key) !== -1) {
|
||||
const value1 = getConfigurationValue(from.contents, key);
|
||||
const value2 = getConfigurationValue(to.contents, key);
|
||||
if (!objects.equals(value1, value2)) {
|
||||
updated.push(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const overrides: [string, string[]][] = [];
|
||||
const byOverrideIdentifier = (overrides: IOverrides[]): IStringDictionary<IOverrides> => {
|
||||
const result: IStringDictionary<IOverrides> = {};
|
||||
for (const override of overrides) {
|
||||
for (const identifier of override.identifiers) {
|
||||
result[keyFromOverrideIdentifier(identifier)] = override;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
};
|
||||
const toOverridesByIdentifier: IStringDictionary<IOverrides> = to ? byOverrideIdentifier(to.overrides) : {};
|
||||
const fromOverridesByIdentifier: IStringDictionary<IOverrides> = from ? byOverrideIdentifier(from.overrides) : {};
|
||||
|
||||
if (Object.keys(toOverridesByIdentifier).length) {
|
||||
for (const key of added) {
|
||||
const override = toOverridesByIdentifier[key];
|
||||
if (override) {
|
||||
overrides.push([overrideIdentifierFromKey(key), override.keys]);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (Object.keys(fromOverridesByIdentifier).length) {
|
||||
for (const key of removed) {
|
||||
const override = fromOverridesByIdentifier[key];
|
||||
if (override) {
|
||||
overrides.push([overrideIdentifierFromKey(key), override.keys]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (Object.keys(toOverridesByIdentifier).length && Object.keys(fromOverridesByIdentifier).length) {
|
||||
for (const key of updated) {
|
||||
const fromOverride = fromOverridesByIdentifier[key];
|
||||
const toOverride = toOverridesByIdentifier[key];
|
||||
if (fromOverride && toOverride) {
|
||||
const result = compare({ contents: fromOverride.contents, keys: fromOverride.keys, overrides: [] }, { contents: toOverride.contents, keys: toOverride.keys, overrides: [] });
|
||||
overrides.push([overrideIdentifierFromKey(key), [...result.added, ...result.removed, ...result.updated]]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return { added, removed, updated, overrides };
|
||||
}
|
||||
|
||||
export function toOverrides(raw: any, conflictReporter: (message: string) => void): IOverrides[] {
|
||||
const overrides: IOverrides[] = [];
|
||||
for (const key of Object.keys(raw)) {
|
||||
|
|
|
@ -13,7 +13,7 @@ import * as objects from 'vs/base/common/objects';
|
|||
import { IExtUri } from 'vs/base/common/resources';
|
||||
import * as types from 'vs/base/common/types';
|
||||
import { URI, UriComponents } from 'vs/base/common/uri';
|
||||
import { addToValueTree, compare, ConfigurationTarget, getConfigurationKeys, getConfigurationValue, getDefaultValues, IConfigurationChange, IConfigurationChangeEvent, IConfigurationData, IConfigurationModel, IConfigurationOverrides, IConfigurationValue, IOverrides, removeFromValueTree, toOverrides, toValuesTree } from 'vs/platform/configuration/common/configuration';
|
||||
import { addToValueTree, ConfigurationTarget, getConfigurationKeys, getConfigurationValue, getDefaultValues, IConfigurationChange, IConfigurationChangeEvent, IConfigurationCompareResult, IConfigurationData, IConfigurationModel, IConfigurationOverrides, IConfigurationValue, IOverrides, removeFromValueTree, toOverrides, toValuesTree } from 'vs/platform/configuration/common/configuration';
|
||||
import { ConfigurationScope, Extensions, IConfigurationPropertySchema, IConfigurationRegistry, overrideIdentifierFromKey, OVERRIDE_PROPERTY_PATTERN } from 'vs/platform/configuration/common/configurationRegistry';
|
||||
import { IFileService } from 'vs/platform/files/common/files';
|
||||
import { Registry } from 'vs/platform/registry/common/platform';
|
||||
|
@ -68,6 +68,14 @@ export class ConfigurationModel implements IConfigurationModel {
|
|||
return arrays.distinct(keys);
|
||||
}
|
||||
|
||||
getAllOverrideIdentifiers(): string[] {
|
||||
const result: string[] = [];
|
||||
for (const override of this.overrides) {
|
||||
result.push(...override.identifiers);
|
||||
}
|
||||
return arrays.distinct(result);
|
||||
}
|
||||
|
||||
override(identifier: string): ConfigurationModel {
|
||||
let overrideConfigurationModel = this.overrideConfigurations.get(identifier);
|
||||
if (!overrideConfigurationModel) {
|
||||
|
@ -562,9 +570,9 @@ export class Configuration {
|
|||
}
|
||||
|
||||
compareAndUpdateDefaultConfiguration(defaults: ConfigurationModel, keys: string[]): IConfigurationChange {
|
||||
const overrides: [string, string[]][] = keys
|
||||
.filter(key => OVERRIDE_PROPERTY_PATTERN.test(key))
|
||||
.map(key => {
|
||||
const overrides: [string, string[]][] = [];
|
||||
for (const key of keys) {
|
||||
if (OVERRIDE_PROPERTY_PATTERN.test(key)) {
|
||||
const overrideIdentifier = overrideIdentifierFromKey(key);
|
||||
const fromKeys = this._defaultConfiguration.getKeysForOverrideIdentifier(overrideIdentifier);
|
||||
const toKeys = defaults.getKeysForOverrideIdentifier(overrideIdentifier);
|
||||
|
@ -573,8 +581,9 @@ export class Configuration {
|
|||
...fromKeys.filter(key => toKeys.indexOf(key) === -1),
|
||||
...fromKeys.filter(key => !objects.equals(this._defaultConfiguration.override(overrideIdentifier).getValue(key), defaults.override(overrideIdentifier).getValue(key)))
|
||||
];
|
||||
return [overrideIdentifier, keys];
|
||||
});
|
||||
overrides.push([overrideIdentifier, keys]);
|
||||
}
|
||||
}
|
||||
this.updateDefaultConfiguration(defaults);
|
||||
return { keys, overrides };
|
||||
}
|
||||
|
@ -751,6 +760,15 @@ export class Configuration {
|
|||
return [...keys.values()];
|
||||
}
|
||||
|
||||
protected allOverrideIdentifiers(): string[] {
|
||||
const keys: Set<string> = new Set<string>();
|
||||
this._defaultConfiguration.freeze().getAllOverrideIdentifiers().forEach(key => keys.add(key));
|
||||
this.userConfiguration.freeze().getAllOverrideIdentifiers().forEach(key => keys.add(key));
|
||||
this._workspaceConfiguration.freeze().getAllOverrideIdentifiers().forEach(key => keys.add(key));
|
||||
this._folderConfigurations.forEach(folderConfiguraiton => folderConfiguraiton.freeze().getAllOverrideIdentifiers().forEach(key => keys.add(key)));
|
||||
return [...keys.values()];
|
||||
}
|
||||
|
||||
protected getAllKeysForOverrideIdentifier(overrideIdentifier: string): string[] {
|
||||
const keys: Set<string> = new Set<string>();
|
||||
this._defaultConfiguration.getKeysForOverrideIdentifier(overrideIdentifier).forEach(key => keys.add(key));
|
||||
|
@ -858,3 +876,60 @@ export class AllKeysConfigurationChangeEvent extends ConfigurationChangeEvent {
|
|||
this.sourceConfig = sourceConfig;
|
||||
}
|
||||
}
|
||||
|
||||
function compare(from: ConfigurationModel | undefined, to: ConfigurationModel | undefined): IConfigurationCompareResult {
|
||||
const { added, removed, updated } = compareConfigurationContents(to, from);
|
||||
const overrides: [string, string[]][] = [];
|
||||
|
||||
const fromOverrideIdentifiers = from?.getAllOverrideIdentifiers() || [];
|
||||
const toOverrideIdentifiers = to?.getAllOverrideIdentifiers() || [];
|
||||
|
||||
if (to) {
|
||||
const addedOverrideIdentifiers = toOverrideIdentifiers.filter(key => !fromOverrideIdentifiers.includes(key));
|
||||
for (const identifier of addedOverrideIdentifiers) {
|
||||
overrides.push([identifier, to.getKeysForOverrideIdentifier(identifier)]);
|
||||
}
|
||||
}
|
||||
|
||||
if (from) {
|
||||
const removedOverrideIdentifiers = fromOverrideIdentifiers.filter(key => !toOverrideIdentifiers.includes(key));
|
||||
for (const identifier of removedOverrideIdentifiers) {
|
||||
overrides.push([identifier, from.getKeysForOverrideIdentifier(identifier)]);
|
||||
}
|
||||
}
|
||||
|
||||
if (to && from) {
|
||||
for (const identifier of fromOverrideIdentifiers) {
|
||||
if (toOverrideIdentifiers.includes(identifier)) {
|
||||
const result = compareConfigurationContents({ contents: from.getOverrideValue(undefined, identifier) || {}, keys: from.getKeysForOverrideIdentifier(identifier) }, { contents: to.getOverrideValue(undefined, identifier) || {}, keys: to.getKeysForOverrideIdentifier(identifier) });
|
||||
overrides.push([identifier, [...result.added, ...result.removed, ...result.updated]]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return { added, removed, updated, overrides };
|
||||
}
|
||||
|
||||
function compareConfigurationContents(to: { keys: string[], contents: any } | undefined, from: { keys: string[], contents: any } | undefined) {
|
||||
const added = to
|
||||
? from ? to.keys.filter(key => from.keys.indexOf(key) === -1) : [...to.keys]
|
||||
: [];
|
||||
const removed = from
|
||||
? to ? from.keys.filter(key => to.keys.indexOf(key) === -1) : [...from.keys]
|
||||
: [];
|
||||
const updated: string[] = [];
|
||||
|
||||
if (to && from) {
|
||||
for (const key of from.keys) {
|
||||
if (to.keys.indexOf(key) !== -1) {
|
||||
const value1 = getConfigurationValue(from.contents, key);
|
||||
const value2 = getConfigurationValue(to.contents, key);
|
||||
if (!objects.equals(value1, value2)) {
|
||||
updated.push(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return { added, removed, updated };
|
||||
}
|
||||
|
||||
|
|
|
@ -10,8 +10,8 @@ import { IStoredWorkspaceFolder } from 'vs/platform/workspaces/common/workspaces
|
|||
import { Workspace } from 'vs/platform/workspace/common/workspace';
|
||||
import { ResourceMap } from 'vs/base/common/map';
|
||||
import { URI } from 'vs/base/common/uri';
|
||||
import { OVERRIDE_PROPERTY_PATTERN, overrideIdentifierFromKey } from 'vs/platform/configuration/common/configurationRegistry';
|
||||
import { isBoolean } from 'vs/base/common/types';
|
||||
import { distinct } from 'vs/base/common/arrays';
|
||||
|
||||
export class WorkspaceConfigurationModelParser extends ConfigurationModelParser {
|
||||
|
||||
|
@ -154,10 +154,11 @@ export class Configuration extends BaseConfiguration {
|
|||
};
|
||||
const keys = compare(this.allKeys(), other.allKeys());
|
||||
const overrides: [string, string[]][] = [];
|
||||
for (const key of keys) {
|
||||
if (OVERRIDE_PROPERTY_PATTERN.test(key)) {
|
||||
const overrideIdentifier = overrideIdentifierFromKey(key);
|
||||
overrides.push([overrideIdentifier, compare(this.getAllKeysForOverrideIdentifier(overrideIdentifier), other.getAllKeysForOverrideIdentifier(overrideIdentifier), overrideIdentifier)]);
|
||||
const allOverrideIdentifiers = distinct([...this.allOverrideIdentifiers(), ...other.allOverrideIdentifiers()]);
|
||||
for (const overrideIdentifier of allOverrideIdentifiers) {
|
||||
const keys = compare(this.getAllKeysForOverrideIdentifier(overrideIdentifier), other.getAllKeysForOverrideIdentifier(overrideIdentifier), overrideIdentifier);
|
||||
if (keys.length) {
|
||||
overrides.push([overrideIdentifier, keys]);
|
||||
}
|
||||
}
|
||||
return { keys, overrides };
|
||||
|
|
Loading…
Reference in a new issue