| 25 | */ |
| 26 | @injectable() |
| 27 | export class ExperimentService implements IExperimentService { |
| 28 | /** |
| 29 | * Experiments the user requested to opt into manually. |
| 30 | */ |
| 31 | public _optInto: string[] = []; |
| 32 | /** |
| 33 | * Experiments the user requested to opt out from manually. |
| 34 | */ |
| 35 | public _optOutFrom: string[] = []; |
| 36 | |
| 37 | private readonly experimentationService?: IExperimentationService; |
| 38 | private readonly settings: IJupyterSettings; |
| 39 | |
| 40 | private get enabled() { |
| 41 | return this.settings.experiments.enabled && !this.settings.experiments.optOutFrom.includes('All'); |
| 42 | } |
| 43 | constructor( |
| 44 | @inject(IConfigurationService) readonly configurationService: IConfigurationService, |
| 45 | @inject(IApplicationEnvironment) private readonly appEnvironment: IApplicationEnvironment, |
| 46 | @inject(IMemento) @named(GLOBAL_MEMENTO) private readonly globalState: Memento |
| 47 | ) { |
| 48 | this.settings = configurationService.getSettings(undefined); |
| 49 | |
| 50 | // Users can only opt in or out of experiment groups, not control groups. |
| 51 | const optInto = this.settings.experiments.optInto; |
| 52 | const optOutFrom = this.settings.experiments.optOutFrom; |
| 53 | this._optInto = optInto.filter((exp) => !exp.endsWith('control')); |
| 54 | this._optOutFrom = optOutFrom.filter((exp) => !exp.endsWith('control')); |
| 55 | |
| 56 | // Don't initialize the experiment service if the extension's experiments setting is disabled. |
| 57 | if (!this.enabled) { |
| 58 | return; |
| 59 | } |
| 60 | |
| 61 | let targetPopulation: TargetPopulation; |
| 62 | |
| 63 | if (getVSCodeChannel() === 'insiders') { |
| 64 | targetPopulation = TargetPopulation.Insiders; |
| 65 | } else { |
| 66 | targetPopulation = TargetPopulation.Public; |
| 67 | } |
| 68 | |
| 69 | const telemetryReporter = new ExperimentationTelemetry(); |
| 70 | |
| 71 | this.experimentationService = tasClientWrapper.getExperimentationService( |
| 72 | JVSC_EXTENSION_ID, |
| 73 | this.appEnvironment.extensionVersion!, |
| 74 | targetPopulation, |
| 75 | telemetryReporter, |
| 76 | this.globalState |
| 77 | ); |
| 78 | } |
| 79 | |
| 80 | public async activate() { |
| 81 | if (this.experimentationService && this.enabled) { |
| 82 | await this.experimentationService.initializePromise; |
| 83 | if (this.getFeatures().length === 0) { |
| 84 | // Only await on this if we don't have anything in cache. |
nothing calls this directly
no outgoing calls
no test coverage detected