111
112
constructor(
114
>
@IPolicyService private readonly policyService: IPolicyService,
115
>
@ILogService private readonly logService: ILogService
116
>
) {
117
>
super();
118
>
this._configurationModel = ConfigurationModel.createEmptyModel(this.logService);
119
>
this.configurationRegistry = Registry.as<IConfigurationRegistry>(Extensions.Configuration);
120
>
}
121
122
async initialize(): Promise<ConfigurationModel> {
124
>
125
>
this.update(await this.updatePolicyDefinitions(this.defaultConfiguration.configurationModel.keys), false);
126
>
this.update(await this.updatePolicyDefinitions(Object.keys(this.configurationRegistry.getExcludedConfigurationProperties())), false);
127
>
this._register(this.policyService.onDidChange(policyNames => this.onDidChangePolicies(policyNames)));
128
>
this._register(this.defaultConfiguration.onDidChangeConfiguration(async ({ properties }) => this.update(await this.updatePolicyDefinitions(properties), true)));
129
>
return this._configurationModel;
130
>
}
131
132
private toPolicyDefinitionType(configType: unknown, policyName: PolicyName): 'string' | 'number' | 'boolean' | undefined {
133
>
// `configType` may be a single type or a union (e.g. `['array', 'null']`).
configurations.ts
134
>
// Normalize to an array and keep only the types we can represent as policies.
135
>
const configTypes = Array.isArray(configType) ? configType : [configType];
136
>
const supportedTypes = configTypes.filter(type => type === 'string' || type === 'number' || type === 'array' || type === 'object' || type === 'boolean');
137
>
if (supportedTypes.length === 0) {
138
this.logService.warn(`PolicyConfiguration#updatePolicyDefinitions - policy '${policyName}' has unsupported type '${configType}'`);
139
return undefined;
140
}
141
>
return supportedTypes.includes('number') ? 'number' : supportedTypes.includes('boolean') ? 'boolean' : 'string';
configurations.ts
142
>
}
143
144
private async updatePolicyDefinitions(properties: string[]): Promise<string[]> {
145
>
this.logService.trace('PolicyConfiguration#updatePolicyDefinitions', properties);
configurations.ts
146
>
const keys: string[] = [];
147
>
const policyNames = new Set<PolicyName>();
148
>
const configurationProperties = this.configurationRegistry.getConfigurationProperties();
149
>
const excludedConfigurationProperties = this.configurationRegistry.getExcludedConfigurationProperties();
150
>
151
>
for (const key of properties) {
152
>
const config = configurationProperties[key] ?? excludedConfigurationProperties[key];
153
>
if (!config) {
154
keys.push(key); // deregistered — update() will clear this key's applied policy value
155
const removedPolicyName = this._policyNameByKey.get(key);