77import * as util from './common' ;
88import * as Telemetry from './telemetry' ;
99import { PersistentState } from './LanguageServer/persistentState' ;
10+ import * as fs from 'fs' ;
1011
1112const userBucketMax :number = 100 ;
1213const userBucketString :string = "CPP.UserBucket" ;
@@ -15,61 +16,66 @@ const localConfigFile: string = "cpptools.json";
1516interface Settings {
1617defaultIntelliSenseEngine ?:number ;
1718recursiveIncludes ?:number ;
19+ gotoDefIntelliSense ?:number ;
1820}
1921
2022export class ABTestSettings {
2123private settings :Settings ;
2224private intelliSenseEngineDefault :PersistentState < number > ;
2325private recursiveIncludesDefault :PersistentState < number > ;
26+ private gotoDefIntelliSenseDefault :PersistentState < number > ;
2427private bucket :PersistentState < number > ;
2528
2629constructor ( ) {
2730this . intelliSenseEngineDefault = new PersistentState < number > ( "ABTest.1" , 100 ) ;
2831this . recursiveIncludesDefault = new PersistentState < number > ( "ABTest.2" , 100 ) ;
32+ this . gotoDefIntelliSenseDefault = new PersistentState < number > ( "ABTest.3" , 100 ) ;
2933this . settings = {
3034defaultIntelliSenseEngine :this . intelliSenseEngineDefault . Value ,
31- recursiveIncludes :this . recursiveIncludesDefault . Value
35+ recursiveIncludes :this . recursiveIncludesDefault . Value ,
36+ gotoDefIntelliSense :this . gotoDefIntelliSenseDefault . Value
3237} ;
3338this . bucket = new PersistentState < number > ( userBucketString , - 1 ) ;
3439if ( this . bucket . Value === - 1 ) {
3540this . bucket . Value = Math . floor ( Math . random ( ) * userBucketMax ) + 1 ; // Range is [1, userBucketMax].
3641}
3742
38- this . updateSettingsAsync ( ) . then ( ( ) => {
39- // Redownload cpptools.json after initialization so it's not blocked.
40- // It'll be used the next time the extension reloads.
41- this . downloadCpptoolsJsonPkgAsync ( ) ;
42- } ) ;
43+ this . updateSettings ( ) ;
44+ // Redownload cpptools.json after initialization so it's not blocked.
45+ // It'll be used the next time the extension reloads.
46+ this . downloadCpptoolsJsonPkgAsync ( ) ;
4347
4448// Redownload occasionally to prevent an extra reload during long sessions.
4549setInterval ( ( ) => { this . downloadCpptoolsJsonPkgAsync ( ) ; } , 30 * 60 * 1000 ) ; // 30 minutes.
4650}
4751
4852public get UseDefaultIntelliSenseEngine ( ) :boolean {
49- return this . settings . defaultIntelliSenseEngine ?this . settings . defaultIntelliSenseEngine >= this . bucket . Value :true ;
53+ return util . isNumber ( this . settings . defaultIntelliSenseEngine ) ?this . settings . defaultIntelliSenseEngine >= this . bucket . Value :true ;
5054}
5155
5256public get UseRecursiveIncludes ( ) :boolean {
53- return this . settings . recursiveIncludes ?this . settings . recursiveIncludes >= this . bucket . Value :true ;
57+ return util . isNumber ( this . settings . recursiveIncludes ) ?this . settings . recursiveIncludes >= this . bucket . Value :true ;
5458}
5559
56- private async updateSettingsAsync ( ) :Promise < void > {
60+ public get UseGoToDefIntelliSense ( ) :boolean {
61+ return util . isNumber ( this . settings . gotoDefIntelliSense ) ?this . settings . gotoDefIntelliSense >= this . bucket . Value :true ;
62+ }
63+
64+ private updateSettings ( ) :void {
5765const cpptoolsJsonFile :string = util . getExtensionFilePath ( localConfigFile ) ;
5866
5967try {
60- const exists :boolean = await util . checkFileExists ( cpptoolsJsonFile ) ;
68+ const exists :boolean = fs . existsSync ( cpptoolsJsonFile ) ;
6169if ( exists ) {
62- const fileContent :string = await util . readFileText ( cpptoolsJsonFile ) ;
70+ const fileContent :string = fs . readFileSync ( cpptoolsJsonFile ) . toString ( ) ;
6371let newSettings :Settings = < Settings > JSON . parse ( fileContent ) ;
64- if ( newSettings . defaultIntelliSenseEngine ) {
65- this . intelliSenseEngineDefault . Value = newSettings . defaultIntelliSenseEngine ;
66- }
67- if ( newSettings . recursiveIncludes ) {
68- this . recursiveIncludesDefault . Value = newSettings . recursiveIncludes ;
69- }
72+ this . intelliSenseEngineDefault . Value = util . isNumber ( newSettings . defaultIntelliSenseEngine ) ?newSettings . defaultIntelliSenseEngine :this . intelliSenseEngineDefault . DefaultValue ;
73+ this . recursiveIncludesDefault . Value = util . isNumber ( newSettings . recursiveIncludes ) ?newSettings . recursiveIncludes :this . recursiveIncludesDefault . DefaultValue ;
74+ this . gotoDefIntelliSenseDefault . Value = util . isNumber ( newSettings . gotoDefIntelliSense ) ?newSettings . gotoDefIntelliSense :this . gotoDefIntelliSenseDefault . DefaultValue ;
7075this . settings = {
7176defaultIntelliSenseEngine :this . intelliSenseEngineDefault . Value ,
72- recursiveIncludes :this . recursiveIncludesDefault . Value
77+ recursiveIncludes :this . recursiveIncludesDefault . Value ,
78+ gotoDefIntelliSense :this . gotoDefIntelliSenseDefault . Value
7379} ;
7480}
7581} catch ( error ) {
@@ -87,7 +93,7 @@ export class ABTestSettings {
8793hasError = true ;
8894} )
8995. then ( ( ) => {
90- this . updateSettingsAsync ( ) ;
96+ this . updateSettings ( ) ;
9197telemetryProperties [ 'success' ] = ( ! hasError ) . toString ( ) ;
9298Telemetry . logDebuggerEvent ( "cpptoolsJsonDownload" , telemetryProperties ) ;
9399} ) ;