@@ -38,42 +38,35 @@ export class ExperimentalSettings {
38
38
} ) ;
39
39
}
40
40
41
- async get < T > ( key : EXPERIMENTAL_SETTINGS ) : Promise < T | undefined > {
41
+ async get < T > ( key : EXPERIMENTAL_SETTINGS , defaultValue : T ) : Promise < T > {
42
42
const config = vscode . workspace . getConfiguration ( experimentsSection ) ;
43
43
const values = config . inspect < T > ( key . substring ( ( experimentsSection + '.' ) . length ) ) ;
44
44
if ( ! values ) {
45
45
this . logger . error ( `Cannot get invalid experimental setting '${ key } '` ) ;
46
- return undefined ;
46
+ return defaultValue ;
47
47
}
48
48
if ( values . globalValue !== undefined ) {
49
49
// User setting have priority over configcat so return early
50
50
return values . globalValue ;
51
51
}
52
- const experimentValue = await this . getExperimentValue < T > ( key ) ;
53
- return experimentValue ?? values . defaultValue ;
52
+ return this . getExperimentValue < T > ( key , defaultValue ) ;
54
53
}
55
54
56
- private async getExperimentValue < T > ( key : string ) : Promise < T | undefined > {
55
+ private async getExperimentValue < T > ( key : string , defaultValue : T ) : Promise < T > {
57
56
const configcatKey = key . replace ( / \. / g, '_' ) ; // '.' are not allowed in configcat
58
- const unresolved = '__unressssolved__'
59
-
60
57
const user = await this . pendingOwner ;
61
58
const email = User . getPrimaryEmail ( user ) ;
62
59
const teams = await this . pendingTeams ;
63
60
if ( teams . length ) {
64
61
for ( const team of teams ) {
65
- const value = ( await this . configcatClient . getValueAsync ( configcatKey , unresolved , this . getConfigcatUser ( user . id , email , team . id ) ) ) ;
66
- if ( value != unresolved ) {
62
+ const value = ( await this . configcatClient . getValueAsync ( configcatKey , defaultValue , this . getConfigcatUser ( user . id , email , team . id ) ) ) ;
63
+ if ( value != defaultValue ) {
67
64
return value as T ;
68
65
}
69
66
}
70
- } else {
71
- const value = ( await this . configcatClient . getValueAsync ( configcatKey , unresolved , this . getConfigcatUser ( user . id , email , undefined ) ) ) ;
72
- if ( value != unresolved ) {
73
- return value as T ;
74
- }
67
+ return defaultValue ;
75
68
}
76
- return undefined ;
69
+ return this . configcatClient . getValueAsync ( configcatKey , defaultValue , this . getConfigcatUser ( user . id , email , undefined ) ) ;
77
70
}
78
71
79
72
private getConfigcatUser ( userId : string , email : string | undefined , teamId : string | undefined ) : configcatcommon . User {
0 commit comments