mirror of
https://github.com/Microsoft/vscode
synced 2024-08-27 13:00:58 +00:00
Fix #138154
This commit is contained in:
parent
8587a5d837
commit
4ee3ed1ff2
|
@ -595,12 +595,25 @@ export class Configuration {
|
|||
this._foldersConsolidatedConfigurations.delete(resource);
|
||||
}
|
||||
|
||||
compareAndUpdateDefaultConfiguration(defaults: ConfigurationModel): IConfigurationChange {
|
||||
const { added, updated, removed, overrides } = compare(this._defaultConfiguration, defaults);
|
||||
const keys = [...added, ...updated, ...removed];
|
||||
if (keys.length) {
|
||||
this.updateDefaultConfiguration(defaults);
|
||||
compareAndUpdateDefaultConfiguration(defaults: ConfigurationModel, keys?: string[]): IConfigurationChange {
|
||||
const overrides: [string, string[]][] = [];
|
||||
if (!keys) {
|
||||
const { added, updated, removed } = compare(this._defaultConfiguration, defaults);
|
||||
keys = [...added, ...updated, ...removed];
|
||||
}
|
||||
for (const key of keys) {
|
||||
for (const overrideIdentifier of overrideIdentifiersFromKey(key)) {
|
||||
const fromKeys = this._defaultConfiguration.getKeysForOverrideIdentifier(overrideIdentifier);
|
||||
const toKeys = defaults.getKeysForOverrideIdentifier(overrideIdentifier);
|
||||
const keys = [
|
||||
...toKeys.filter(key => fromKeys.indexOf(key) === -1),
|
||||
...fromKeys.filter(key => toKeys.indexOf(key) === -1),
|
||||
...fromKeys.filter(key => !objects.equals(this._defaultConfiguration.override(overrideIdentifier).getValue(key), defaults.override(overrideIdentifier).getValue(key)))
|
||||
];
|
||||
overrides.push([overrideIdentifier, keys]);
|
||||
}
|
||||
}
|
||||
this.updateDefaultConfiguration(defaults);
|
||||
return { keys, overrides };
|
||||
}
|
||||
|
||||
|
|
|
@ -215,6 +215,7 @@ export const windowSettings: { properties: IStringDictionary<IConfigurationPrope
|
|||
export const resourceSettings: { properties: IStringDictionary<IConfigurationPropertySchema>, patternProperties: IStringDictionary<IConfigurationPropertySchema> } = { properties: {}, patternProperties: {} };
|
||||
|
||||
export const resourceLanguageSettingsSchemaId = 'vscode://schemas/settings/resourceLanguage';
|
||||
export const configurationDefaultsSchemaId = 'vscode://schemas/settings/configurationDefaults';
|
||||
|
||||
const contributionRegistry = Registry.as<IJSONContributionRegistry>(JSONExtensions.JSONContribution);
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@ export class ConfigurationService extends Disposable implements IConfigurationSe
|
|||
this.configuration = new Configuration(new DefaultConfigurationModel(), new ConfigurationModel());
|
||||
|
||||
this.reloadConfigurationScheduler = this._register(new RunOnceScheduler(() => this.reloadConfiguration(), 50));
|
||||
this._register(Registry.as<IConfigurationRegistry>(Extensions.Configuration).onDidUpdateConfiguration(() => this.onDidDefaultConfigurationChange()));
|
||||
this._register(Registry.as<IConfigurationRegistry>(Extensions.Configuration).onDidUpdateConfiguration(({ properties }) => this.onDidDefaultConfigurationChange(properties)));
|
||||
this._register(this.userConfiguration.onDidChange(() => this.reloadConfigurationScheduler.schedule()));
|
||||
}
|
||||
|
||||
|
@ -89,9 +89,9 @@ export class ConfigurationService extends Disposable implements IConfigurationSe
|
|||
this.trigger(change, previous, ConfigurationTarget.USER);
|
||||
}
|
||||
|
||||
private onDidDefaultConfigurationChange(): void {
|
||||
private onDidDefaultConfigurationChange(properties: string[]): void {
|
||||
const previous = this.configuration.toData();
|
||||
const change = this.configuration.compareAndUpdateDefaultConfiguration(new DefaultConfigurationModel());
|
||||
const change = this.configuration.compareAndUpdateDefaultConfiguration(new DefaultConfigurationModel(), properties);
|
||||
this.trigger(change, previous, ConfigurationTarget.DEFAULT);
|
||||
}
|
||||
|
||||
|
|
|
@ -525,9 +525,9 @@ suite('Configuration', () => {
|
|||
'[markdown]': {
|
||||
'editor.wordWrap': 'off'
|
||||
}
|
||||
}));
|
||||
}), ['editor.lineNumbers', '[markdown]']);
|
||||
|
||||
assert.deepStrictEqual(actual, { keys: ['[markdown]', 'editor.lineNumbers'], overrides: [['markdown', ['editor.wordWrap']]] });
|
||||
assert.deepStrictEqual(actual, { keys: ['editor.lineNumbers', '[markdown]'], overrides: [['markdown', ['editor.wordWrap']]] });
|
||||
|
||||
});
|
||||
|
||||
|
@ -890,7 +890,7 @@ suite('ConfigurationChangeEvent', () => {
|
|||
'[markdown]': {
|
||||
'editor.wordWrap': 'off'
|
||||
}
|
||||
})),
|
||||
}), ['editor.lineNumbers', '[markdown]']),
|
||||
configuration.compareAndUpdateLocalUserConfiguration(toConfigurationModel({
|
||||
'[json]': {
|
||||
'editor.lineNumbers': 'relative'
|
||||
|
|
|
@ -8,7 +8,7 @@ import * as objects from 'vs/base/common/objects';
|
|||
import { Registry } from 'vs/platform/registry/common/platform';
|
||||
import { IJSONSchema } from 'vs/base/common/jsonSchema';
|
||||
import { ExtensionsRegistry, IExtensionPointUser } from 'vs/workbench/services/extensions/common/extensionsRegistry';
|
||||
import { IConfigurationNode, IConfigurationRegistry, Extensions, resourceLanguageSettingsSchemaId, validateProperty, ConfigurationScope, OVERRIDE_PROPERTY_PATTERN, OVERRIDE_PROPERTY_REGEX, windowSettings, resourceSettings, machineOverridableSettings, IConfigurationDefaults } from 'vs/platform/configuration/common/configurationRegistry';
|
||||
import { IConfigurationNode, IConfigurationRegistry, Extensions, validateProperty, ConfigurationScope, OVERRIDE_PROPERTY_REGEX, IConfigurationDefaults, configurationDefaultsSchemaId } from 'vs/platform/configuration/common/configurationRegistry';
|
||||
import { IJSONContributionRegistry, Extensions as JSONExtensions } from 'vs/platform/jsonschemas/common/jsonContributionRegistry';
|
||||
import { workspaceSettingsSchemaId, launchSchemaId, tasksSchemaId } from 'vs/workbench/services/configuration/common/configuration';
|
||||
import { isObject } from 'vs/base/common/types';
|
||||
|
@ -112,29 +112,6 @@ const configurationEntrySchema: IJSONSchema = {
|
|||
}
|
||||
};
|
||||
|
||||
const configurationDefaultsSchemaId = 'vscode://schemas/settings/configurationDefaults';
|
||||
const configurationDefaultsSchema: IJSONSchema = {
|
||||
type: 'object',
|
||||
description: nls.localize('configurationDefaults.description', 'Contribute defaults for configurations'),
|
||||
properties: {},
|
||||
patternProperties: {
|
||||
[OVERRIDE_PROPERTY_PATTERN]: {
|
||||
type: 'object',
|
||||
default: {},
|
||||
$ref: resourceLanguageSettingsSchemaId,
|
||||
}
|
||||
},
|
||||
additionalProperties: false
|
||||
};
|
||||
jsonRegistry.registerSchema(configurationDefaultsSchemaId, configurationDefaultsSchema);
|
||||
configurationRegistry.onDidSchemaChange(() => {
|
||||
configurationDefaultsSchema.properties = {
|
||||
...machineOverridableSettings.properties,
|
||||
...windowSettings.properties,
|
||||
...resourceSettings.properties
|
||||
};
|
||||
});
|
||||
|
||||
// BEGIN VSCode extension point `configurationDefaults`
|
||||
const defaultConfigurationExtPoint = ExtensionsRegistry.registerExtensionPoint<IConfigurationNode>({
|
||||
extensionPoint: 'configurationDefaults',
|
||||
|
|
|
@ -36,8 +36,8 @@ export class DefaultConfiguration extends Disposable {
|
|||
private cachedConfigurationDefaultsOverrides: IStringDictionary<any> = {};
|
||||
private readonly cacheKey: ConfigurationKey = { type: 'defaults', key: 'configurationDefaultsOverrides' };
|
||||
|
||||
private readonly _onDidChangeConfiguration: Emitter<ConfigurationModel> = this._register(new Emitter<ConfigurationModel>());
|
||||
readonly onDidChangeConfiguration: Event<ConfigurationModel> = this._onDidChangeConfiguration.event;
|
||||
private readonly _onDidChangeConfiguration = this._register(new Emitter<{ defaults: ConfigurationModel, properties: string[] }>());
|
||||
readonly onDidChangeConfiguration = this._onDidChangeConfiguration.event;
|
||||
|
||||
private updateCache: boolean = false;
|
||||
|
||||
|
@ -62,7 +62,7 @@ export class DefaultConfiguration extends Disposable {
|
|||
async initialize(): Promise<ConfigurationModel> {
|
||||
await this.initializeCachedConfigurationDefaultsOverrides();
|
||||
this._configurationModel = undefined;
|
||||
this._register(this.configurationRegistry.onDidUpdateConfiguration(({ defaultsOverrides }) => this.onDidUpdateConfiguration(defaultsOverrides)));
|
||||
this._register(this.configurationRegistry.onDidUpdateConfiguration(({ properties, defaultsOverrides }) => this.onDidUpdateConfiguration(properties, defaultsOverrides)));
|
||||
return this.configurationModel;
|
||||
}
|
||||
|
||||
|
@ -93,9 +93,9 @@ export class DefaultConfiguration extends Disposable {
|
|||
return this.initiaizeCachedConfigurationDefaultsOverridesPromise;
|
||||
}
|
||||
|
||||
private onDidUpdateConfiguration(defaultsOverrides?: boolean): void {
|
||||
private onDidUpdateConfiguration(properties: string[], defaultsOverrides?: boolean): void {
|
||||
this._configurationModel = undefined;
|
||||
this._onDidChangeConfiguration.fire(this.configurationModel);
|
||||
this._onDidChangeConfiguration.fire({ defaults: this.configurationModel, properties });
|
||||
if (defaultsOverrides) {
|
||||
this.updateCachedConfigurationDefaultsOverrides();
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ import { IConfigurationChangeEvent, ConfigurationTarget, IConfigurationOverrides
|
|||
import { Configuration } from 'vs/workbench/services/configuration/common/configurationModels';
|
||||
import { FOLDER_CONFIG_FOLDER_NAME, defaultSettingsSchemaId, userSettingsSchemaId, workspaceSettingsSchemaId, folderSettingsSchemaId, IConfigurationCache, machineSettingsSchemaId, LOCAL_MACHINE_SCOPES, IWorkbenchConfigurationService, RestrictedSettings } from 'vs/workbench/services/configuration/common/configuration';
|
||||
import { Registry } from 'vs/platform/registry/common/platform';
|
||||
import { IConfigurationRegistry, Extensions, allSettings, windowSettings, resourceSettings, applicationSettings, machineSettings, machineOverridableSettings, ConfigurationScope, IConfigurationPropertySchema, keyFromOverrideIdentifiers } from 'vs/platform/configuration/common/configurationRegistry';
|
||||
import { IConfigurationRegistry, Extensions, allSettings, windowSettings, resourceSettings, applicationSettings, machineSettings, machineOverridableSettings, ConfigurationScope, IConfigurationPropertySchema, keyFromOverrideIdentifiers, OVERRIDE_PROPERTY_PATTERN, resourceLanguageSettingsSchemaId, configurationDefaultsSchemaId } from 'vs/platform/configuration/common/configurationRegistry';
|
||||
import { IWorkspaceIdentifier, isWorkspaceIdentifier, IStoredWorkspaceFolder, isStoredWorkspaceFolder, IWorkspaceFolderCreationData, IWorkspaceInitializationPayload, IEmptyWorkspaceIdentifier, useSlashForPath, getStoredWorkspaceFolder, isSingleFolderWorkspaceIdentifier, ISingleFolderWorkspaceIdentifier, toWorkspaceFolders } from 'vs/platform/workspaces/common/workspaces';
|
||||
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
|
||||
import { ConfigurationEditingService, EditableConfigurationTarget } from 'vs/workbench/services/configuration/common/configurationEditingService';
|
||||
|
@ -137,7 +137,7 @@ export class WorkspaceService extends Disposable implements IWorkbenchConfigurat
|
|||
});
|
||||
}));
|
||||
|
||||
this._register(this.defaultConfiguration.onDidChangeConfiguration(configurationModel => this.onDefaultConfigurationChanged(configurationModel)));
|
||||
this._register(this.defaultConfiguration.onDidChangeConfiguration(({ properties, defaults }) => this.onDefaultConfigurationChanged(defaults, properties)));
|
||||
|
||||
this.workspaceEditingQueue = new Queue<void>();
|
||||
}
|
||||
|
@ -663,10 +663,10 @@ export class WorkspaceService extends Disposable implements IWorkbenchConfigurat
|
|||
}
|
||||
}
|
||||
|
||||
private onDefaultConfigurationChanged(configurationModel: ConfigurationModel): void {
|
||||
private onDefaultConfigurationChanged(configurationModel: ConfigurationModel, properties?: string[]): void {
|
||||
if (this.workspace) {
|
||||
const previousData = this._configuration.toData();
|
||||
const change = this._configuration.compareAndUpdateDefaultConfiguration(configurationModel);
|
||||
const change = this._configuration.compareAndUpdateDefaultConfiguration(configurationModel, properties);
|
||||
if (this.remoteUserConfiguration) {
|
||||
this._configuration.updateLocalUserConfiguration(this.localUserConfiguration.reparse());
|
||||
this._configuration.updateRemoteUserConfiguration(this.remoteUserConfiguration.reparse());
|
||||
|
@ -1092,6 +1092,24 @@ class RegisterConfigurationSchemasContribution extends Disposable implements IWo
|
|||
jsonRegistry.registerSchema(workspaceSettingsSchemaId, workspaceSettingsSchema);
|
||||
jsonRegistry.registerSchema(folderSettingsSchemaId, workspaceSettingsSchema);
|
||||
}
|
||||
|
||||
jsonRegistry.registerSchema(configurationDefaultsSchemaId, {
|
||||
type: 'object',
|
||||
description: localize('configurationDefaults.description', 'Contribute defaults for configurations'),
|
||||
properties: {
|
||||
...machineOverridableSettings.properties,
|
||||
...windowSettings.properties,
|
||||
...resourceSettings.properties
|
||||
},
|
||||
patternProperties: {
|
||||
[OVERRIDE_PROPERTY_PATTERN]: {
|
||||
type: 'object',
|
||||
default: {},
|
||||
$ref: resourceLanguageSettingsSchemaId,
|
||||
}
|
||||
},
|
||||
additionalProperties: false
|
||||
});
|
||||
}
|
||||
|
||||
private checkAndFilterPropertiesRequiringTrust(properties: IStringDictionary<IConfigurationPropertySchema>): IStringDictionary<IConfigurationPropertySchema> {
|
||||
|
|
|
@ -116,7 +116,7 @@ suite('DefaultConfiguration', () => {
|
|||
}
|
||||
});
|
||||
|
||||
const actual = await promise;
|
||||
const { defaults: actual } = await promise;
|
||||
assert.deepStrictEqual(actual.getValue('test.configurationDefaultsOverride'), 'overrideValue');
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in a new issue