Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/extensions/copilot/src/platform/configuration/common/defaultsOnlyConfigurationService.ts
13400 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import type { ConfigurationScope } from 'vscode';
7
import { IExperimentationService } from '../../telemetry/common/nullExperimentationService';
8
import { AbstractConfigurationService, BaseConfig, Config, ExperimentBasedConfig, ExperimentBasedConfigType, globalConfigRegistry, InspectConfigResult } from './configurationService';
9
10
/** Provides only the default values, ignoring the user's settings or exp. */
11
12
export class DefaultsOnlyConfigurationService extends AbstractConfigurationService {
13
14
override getConfig<T>(key: Config<T>): T {
15
return this.getDefaultValue(key);
16
}
17
18
override inspectConfig<T>(key: BaseConfig<T>, scope?: ConfigurationScope): InspectConfigResult<T> | undefined {
19
return {
20
defaultValue: this.getDefaultValue(key),
21
};
22
}
23
24
override setConfig<T>(key: BaseConfig<T>, value: T): Promise<void> {
25
return Promise.resolve();
26
}
27
28
override getNonExtensionConfig<T>(configKey: string): T | undefined {
29
return undefined;
30
}
31
32
override getExperimentBasedConfig<T extends ExperimentBasedConfigType>(key: ExperimentBasedConfig<T>, experimentationService: IExperimentationService, scope?: ConfigurationScope): T {
33
if (key.experimentName) {
34
const expValue = experimentationService.getTreatmentVariable<Exclude<T, undefined>>(key.experimentName);
35
if (expValue !== undefined) {
36
return expValue;
37
}
38
}
39
40
// This is the pattern we've been using for a while now. We need to maintain it for older experiments.
41
const expValue = experimentationService.getTreatmentVariable<Exclude<T, undefined>>(`copilotchat.config.${key.id}`);
42
if (expValue !== undefined) {
43
return expValue;
44
}
45
46
// This is the pattern vscode uses for settings using the `onExp` tag. But vscode only supports it for
47
// settings defined in package.json, so this is why we're also reading the value from exp here.
48
const expValue2 = experimentationService.getTreatmentVariable<Exclude<T, undefined>>(`config.${key.fullyQualifiedId}`);
49
if (expValue2 !== undefined) {
50
return expValue2;
51
}
52
53
if (key.fullyQualifiedOldId) {
54
const oldExpValue = experimentationService.getTreatmentVariable<Exclude<T, undefined>>(`copilotchat.config.${key.oldId}`);
55
if (oldExpValue !== undefined) {
56
return oldExpValue;
57
}
58
59
const oldExpValue2 = experimentationService.getTreatmentVariable<Exclude<T, undefined>>(`config.${key.fullyQualifiedOldId}`);
60
if (oldExpValue2 !== undefined) {
61
return oldExpValue2;
62
}
63
}
64
65
return this.getDefaultValue(key);
66
}
67
68
override updateExperimentBasedConfiguration(treatments: string[]): void {
69
if (treatments.length === 0) {
70
return;
71
}
72
73
// Fire simulated event which checks if a configuration is affected in the treatments
74
this._onDidChangeConfiguration.fire({
75
affectsConfiguration: (section: string, _scope?: ConfigurationScope) => {
76
if (treatments.some(t => t.startsWith(`config.${section}`))) {
77
return true;
78
}
79
const oldId = globalConfigRegistry.configs.get(section)?.fullyQualifiedOldId;
80
if (oldId && treatments.some(t => t.startsWith(`config.${oldId}`))) {
81
return true;
82
}
83
return false;
84
}
85
});
86
}
87
88
override dumpConfig(): { [key: string]: string } {
89
return {};
90
}
91
}
92
93