Path: blob/main/extensions/copilot/src/platform/configuration/common/defaultsOnlyConfigurationService.ts
13400 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import type { ConfigurationScope } from 'vscode';6import { IExperimentationService } from '../../telemetry/common/nullExperimentationService';7import { AbstractConfigurationService, BaseConfig, Config, ExperimentBasedConfig, ExperimentBasedConfigType, globalConfigRegistry, InspectConfigResult } from './configurationService';89/** Provides only the default values, ignoring the user's settings or exp. */1011export class DefaultsOnlyConfigurationService extends AbstractConfigurationService {1213override getConfig<T>(key: Config<T>): T {14return this.getDefaultValue(key);15}1617override inspectConfig<T>(key: BaseConfig<T>, scope?: ConfigurationScope): InspectConfigResult<T> | undefined {18return {19defaultValue: this.getDefaultValue(key),20};21}2223override setConfig<T>(key: BaseConfig<T>, value: T): Promise<void> {24return Promise.resolve();25}2627override getNonExtensionConfig<T>(configKey: string): T | undefined {28return undefined;29}3031override getExperimentBasedConfig<T extends ExperimentBasedConfigType>(key: ExperimentBasedConfig<T>, experimentationService: IExperimentationService, scope?: ConfigurationScope): T {32if (key.experimentName) {33const expValue = experimentationService.getTreatmentVariable<Exclude<T, undefined>>(key.experimentName);34if (expValue !== undefined) {35return expValue;36}37}3839// This is the pattern we've been using for a while now. We need to maintain it for older experiments.40const expValue = experimentationService.getTreatmentVariable<Exclude<T, undefined>>(`copilotchat.config.${key.id}`);41if (expValue !== undefined) {42return expValue;43}4445// This is the pattern vscode uses for settings using the `onExp` tag. But vscode only supports it for46// settings defined in package.json, so this is why we're also reading the value from exp here.47const expValue2 = experimentationService.getTreatmentVariable<Exclude<T, undefined>>(`config.${key.fullyQualifiedId}`);48if (expValue2 !== undefined) {49return expValue2;50}5152if (key.fullyQualifiedOldId) {53const oldExpValue = experimentationService.getTreatmentVariable<Exclude<T, undefined>>(`copilotchat.config.${key.oldId}`);54if (oldExpValue !== undefined) {55return oldExpValue;56}5758const oldExpValue2 = experimentationService.getTreatmentVariable<Exclude<T, undefined>>(`config.${key.fullyQualifiedOldId}`);59if (oldExpValue2 !== undefined) {60return oldExpValue2;61}62}6364return this.getDefaultValue(key);65}6667override updateExperimentBasedConfiguration(treatments: string[]): void {68if (treatments.length === 0) {69return;70}7172// Fire simulated event which checks if a configuration is affected in the treatments73this._onDidChangeConfiguration.fire({74affectsConfiguration: (section: string, _scope?: ConfigurationScope) => {75if (treatments.some(t => t.startsWith(`config.${section}`))) {76return true;77}78const oldId = globalConfigRegistry.configs.get(section)?.fullyQualifiedOldId;79if (oldId && treatments.some(t => t.startsWith(`config.${oldId}`))) {80return true;81}82return false;83}84});85}8687override dumpConfig(): { [key: string]: string } {88return {};89}90}919293