Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Reapply "fix #229955 (#229959)" (#233567)

This reverts commit 86a992a.
  • Loading branch information
sandy081 authored Nov 14, 2024
1 parent 6dd6e70 commit fd5fa8e
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 6 deletions.
32 changes: 27 additions & 5 deletions src/vs/platform/configuration/common/configurationModels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ export class ConfigurationModel implements IConfigurationModel {
}

export interface ConfigurationParseOptions {
skipUnregistered?: boolean;
scopes?: ConfigurationScope[];
skipRestricted?: boolean;
include?: string[];
Expand Down Expand Up @@ -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;
Expand All @@ -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)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<void>({ 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<void>({ useFakeTimers: true }, async () => {
await testObject.updateValue(APPLY_ALL_PROFILES_SETTING, ['configurationService.profiles.testSetting2'], ConfigurationTarget.USER_LOCAL);

Expand Down

0 comments on commit fd5fa8e

Please sign in to comment.