-
Notifications
You must be signed in to change notification settings - Fork 31.7k
/
Copy pathexperimentationService.ts
62 lines (54 loc) · 2.34 KB
/
experimentationService.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as vscode from 'vscode';
import * as tas from 'vscode-tas-client';
import { IExperimentationTelemetryReporter } from './experimentTelemetryReporter';
interface ExperimentTypes {
// None for now.
}
export class ExperimentationService {
private readonly _experimentationServicePromise: Promise<tas.IExperimentationService>;
private readonly _telemetryReporter: IExperimentationTelemetryReporter;
constructor(telemetryReporter: IExperimentationTelemetryReporter, id: string, version: string, globalState: vscode.Memento) {
this._telemetryReporter = telemetryReporter;
this._experimentationServicePromise = createTasExperimentationService(this._telemetryReporter, id, version, globalState);
}
public async getTreatmentVariable<K extends keyof ExperimentTypes>(name: K, defaultValue: ExperimentTypes[K]): Promise<ExperimentTypes[K]> {
const experimentationService = await this._experimentationServicePromise;
try {
const treatmentVariable = experimentationService.getTreatmentVariableAsync('vscode', name, /*checkCache*/ true) as Promise<ExperimentTypes[K]>;
return treatmentVariable;
} catch {
return defaultValue;
}
}
}
export async function createTasExperimentationService(
reporter: IExperimentationTelemetryReporter,
id: string,
version: string,
globalState: vscode.Memento): Promise<tas.IExperimentationService> {
let targetPopulation: tas.TargetPopulation;
switch (vscode.env.uriScheme) {
case 'vscode':
targetPopulation = tas.TargetPopulation.Public;
break;
case 'vscode-insiders':
targetPopulation = tas.TargetPopulation.Insiders;
break;
case 'vscode-exploration':
targetPopulation = tas.TargetPopulation.Internal;
break;
case 'code-oss':
targetPopulation = tas.TargetPopulation.Team;
break;
default:
targetPopulation = tas.TargetPopulation.Public;
break;
}
const experimentationService = tas.getExperimentationService(id, version, targetPopulation, reporter, globalState);
await experimentationService.initialFetch;
return experimentationService;
}