From 114554bc5d35f7bad3c873b3be62790be6852c9a Mon Sep 17 00:00:00 2001 From: Sandeep Somavarapu Date: Fri, 27 Sep 2024 14:39:37 +0200 Subject: [PATCH] fix #229955 --- .../common/configurationModels.ts | 32 ++++++++++++++++--- .../configuration/browser/configuration.ts | 2 +- .../test/browser/configurationService.test.ts | 6 ++++ 3 files changed, 34 insertions(+), 6 deletions(-) diff --git a/src/vs/platform/configuration/common/configurationModels.ts b/src/vs/platform/configuration/common/configurationModels.ts index 5b7a51dced270..400ae1033cb92 100644 --- a/src/vs/platform/configuration/common/configurationModels.ts +++ b/src/vs/platform/configuration/common/configurationModels.ts @@ -296,6 +296,7 @@ export class ConfigurationModel implements IConfigurationModel { } export interface ConfigurationParseOptions { + skipUnregistered?: boolean; scopes?: ConfigurationScope[]; skipRestricted?: boolean; include?: string[]; @@ -428,14 +429,10 @@ export class ConfigurationModelParser { restricted.push(...result.restricted); } else { const propertySchema = configurationProperties[key]; - const scope = propertySchema ? typeof propertySchema.scope !== 'undefined' ? propertySchema.scope : ConfigurationScope.WINDOW : undefined; if (propertySchema?.restricted) { restricted.push(key); } - if (!options.exclude?.includes(key) /* Check exclude */ - && (options.include?.includes(key) /* Check include */ - || ((scope === undefined || options.scopes === undefined || options.scopes.includes(scope)) /* Check scopes */ - && !(options.skipRestricted && propertySchema?.restricted)))) /* Check restricted */ { + if (this.shouldInclude(key, propertySchema, options)) { raw[key] = properties[key]; } else { hasExcludedProperties = true; @@ -445,6 +442,31 @@ export class ConfigurationModelParser { return { raw, restricted, hasExcludedProperties }; } + private shouldInclude(key: string, propertySchema: IConfigurationPropertySchema | undefined, options: ConfigurationParseOptions): boolean { + if (options.exclude?.includes(key)) { + return false; + } + + if (options.include?.includes(key)) { + return true; + } + + if (options.skipRestricted && propertySchema?.restricted) { + return false; + } + + if (options.skipUnregistered && !propertySchema) { + return false; + } + + const scope = propertySchema ? typeof propertySchema.scope !== 'undefined' ? propertySchema.scope : ConfigurationScope.WINDOW : undefined; + if (scope === undefined || options.scopes === undefined) { + return true; + } + + return options.scopes.includes(scope); + } + private toOverrides(raw: any, conflictReporter: (message: string) => void): IOverrides[] { const overrides: IOverrides[] = []; for (const key of Object.keys(raw)) { diff --git a/src/vs/workbench/services/configuration/browser/configuration.ts b/src/vs/workbench/services/configuration/browser/configuration.ts index d18242bde5769..217084c9e9bbe 100644 --- a/src/vs/workbench/services/configuration/browser/configuration.ts +++ b/src/vs/workbench/services/configuration/browser/configuration.ts @@ -133,7 +133,7 @@ export class ApplicationConfiguration extends UserSettings { uriIdentityService: IUriIdentityService, logService: ILogService, ) { - super(userDataProfilesService.defaultProfile.settingsResource, { scopes: [ConfigurationScope.APPLICATION] }, uriIdentityService.extUri, fileService, logService); + super(userDataProfilesService.defaultProfile.settingsResource, { scopes: [ConfigurationScope.APPLICATION], skipUnregistered: true }, uriIdentityService.extUri, fileService, logService); this._register(this.onDidChange(() => this.reloadConfigurationScheduler.schedule())); this.reloadConfigurationScheduler = this._register(new RunOnceScheduler(() => this.loadConfiguration().then(configurationModel => this._onDidChangeConfiguration.fire(configurationModel)), 50)); } diff --git a/src/vs/workbench/services/configuration/test/browser/configurationService.test.ts b/src/vs/workbench/services/configuration/test/browser/configurationService.test.ts index ebcc88dd25d60..833dec287e066 100644 --- a/src/vs/workbench/services/configuration/test/browser/configurationService.test.ts +++ b/src/vs/workbench/services/configuration/test/browser/configurationService.test.ts @@ -1737,6 +1737,12 @@ suite('WorkspaceConfigurationService - Profiles', () => { assert.strictEqual(testObject.getValue('configurationService.profiles.applicationSetting3'), 'defaultProfile'); })); + test('non registering setting should not be read from default profile', () => runWithFakedTimers({ useFakeTimers: true }, async () => { + await fileService.writeFile(instantiationService.get(IUserDataProfilesService).defaultProfile.settingsResource, VSBuffer.fromString('{ "configurationService.profiles.nonregistered": "defaultProfile" }')); + await testObject.reloadConfiguration(); + assert.strictEqual(testObject.getValue('configurationService.profiles.nonregistered'), undefined); + })); + test('initialize with custom all profiles settings', () => runWithFakedTimers({ useFakeTimers: true }, async () => { await testObject.updateValue(APPLY_ALL_PROFILES_SETTING, ['configurationService.profiles.testSetting2'], ConfigurationTarget.USER_LOCAL);