3
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
4
*--------------------------------------------------------------------------------------------*/
5
5
6
- import { createDecorator } from 'vs/platform/instantiation/common/instantiation' ;
6
+ import { distinct } from 'vs/base/common/arrays' ;
7
+ import { RunOnceWorker } from 'vs/base/common/async' ;
8
+ import { CancellationToken } from 'vs/base/common/cancellation' ;
7
9
import { Emitter , Event } from 'vs/base/common/event' ;
8
- import { IStorageService , StorageScope , StorageTarget } from 'vs/platform/storage/common/storage' ;
9
- import { ITelemetryService , lastSessionDateStorageKey } from 'vs/platform/telemetry/common/telemetry' ;
10
- import { ILifecycleService , LifecyclePhase } from 'vs/workbench/services/lifecycle/common/lifecycle' ;
10
+ import { match } from 'vs/base/common/glob' ;
11
+ import { Disposable } from 'vs/base/common/lifecycle' ;
12
+ import { equals } from 'vs/base/common/objects' ;
13
+ import { language , OperatingSystem , OS } from 'vs/base/common/platform' ;
14
+ import { isDefined } from 'vs/base/common/types' ;
11
15
import { IConfigurationService } from 'vs/platform/configuration/common/configuration' ;
12
16
import { IExtensionManagementService } from 'vs/platform/extensionManagement/common/extensionManagement' ;
13
- import { language , OperatingSystem , OS } from 'vs/base/common/platform' ;
14
- import { Disposable } from 'vs/base/common/lifecycle' ;
15
- import { match } from 'vs/base/common/glob' ;
16
- import { IRequestService , asJson } from 'vs/platform/request/common/request' ;
17
- import { ITextFileService , ITextFileEditorModel } from 'vs/workbench/services/textfile/common/textfiles' ;
18
- import { CancellationToken } from 'vs/base/common/cancellation' ;
19
- import { distinct } from 'vs/base/common/arrays' ;
20
17
import { ExtensionType } from 'vs/platform/extensions/common/extensions' ;
18
+ import { createDecorator } from 'vs/platform/instantiation/common/instantiation' ;
21
19
import { IProductService } from 'vs/platform/product/common/productService' ;
20
+ import { asJson , IRequestService } from 'vs/platform/request/common/request' ;
21
+ import { IStorageService , StorageScope , StorageTarget } from 'vs/platform/storage/common/storage' ;
22
+ import { ITelemetryService , lastSessionDateStorageKey } from 'vs/platform/telemetry/common/telemetry' ;
22
23
import { IWorkspaceTagsService } from 'vs/workbench/contrib/tags/common/workspaceTags' ;
23
- import { RunOnceWorker } from 'vs/base/common/async' ;
24
24
import { IExtensionService } from 'vs/workbench/services/extensions/common/extensions' ;
25
- import { equals } from 'vs/base/common/objects' ;
25
+ import { ILifecycleService , LifecyclePhase } from 'vs/workbench/services/lifecycle/common/lifecycle' ;
26
+ import { ITextFileEditorModel , ITextFileService } from 'vs/workbench/services/textfile/common/textfiles' ;
26
27
27
28
export const enum ExperimentState {
28
29
Evaluating ,
@@ -93,7 +94,7 @@ interface IExperimentStorageState {
93
94
* be incremented when adding a condition, otherwise experiments might activate
94
95
* on older versions of VS Code where not intended.
95
96
*/
96
- export const currentSchemaVersion = 4 ;
97
+ export const currentSchemaVersion = 5 ;
97
98
98
99
interface IRawExperiment {
99
100
id : string ;
@@ -107,7 +108,7 @@ interface IRawExperiment {
107
108
userSetting ?: { [ key : string ] : unknown ; } ;
108
109
// Start the experiment if the number of activation events have happened over the last week:
109
110
activationEvent ?: {
110
- event : string ;
111
+ event : string | string [ ] ;
111
112
uniqueDays ?: number ;
112
113
minEvents : number ;
113
114
} ;
@@ -285,7 +286,8 @@ export class ExperimentService extends Disposable implements IExperimentService
285
286
this . storageService . remove ( 'allExperiments' , StorageScope . GLOBAL ) ;
286
287
}
287
288
288
- const activationEvents = new Set ( rawExperiments . map ( exp => exp . condition ?. activationEvent ?. event ) . filter ( evt => ! ! evt ) ) ;
289
+ const activationEvents = new Set ( rawExperiments . map ( exp => exp . condition ?. activationEvent ?. event )
290
+ . filter ( isDefined ) . flatMap ( evt => typeof evt === 'string' ? [ evt ] : [ ] ) ) ;
289
291
if ( activationEvents . size ) {
290
292
this . _register ( this . extensionService . onWillActivateByEvent ( evt => {
291
293
if ( activationEvents . has ( evt . event ) ) {
@@ -402,7 +404,14 @@ export class ExperimentService extends Disposable implements IExperimentService
402
404
this . storageService . store ( key , JSON . stringify ( record ) , StorageScope . GLOBAL , StorageTarget . MACHINE ) ;
403
405
404
406
this . _experiments
405
- . filter ( e => e . state === ExperimentState . Evaluating && e . raw ?. condition ?. activationEvent ?. event === event )
407
+ . filter ( e => {
408
+ const lookingFor = e . raw ?. condition ?. activationEvent ?. event ;
409
+ if ( e . state !== ExperimentState . Evaluating || ! lookingFor ) {
410
+ return false ;
411
+ }
412
+
413
+ return typeof lookingFor === 'string' ? lookingFor === event : lookingFor ?. includes ( event ) ;
414
+ } )
406
415
. forEach ( e => this . evaluateExperiment ( e . raw ! ) ) ;
407
416
}
408
417
@@ -412,14 +421,18 @@ export class ExperimentService extends Disposable implements IExperimentService
412
421
return true ;
413
422
}
414
423
415
- const { count } = getCurrentActivationRecord ( safeParse ( this . storageService . get ( experimentEventStorageKey ( setting . event ) , StorageScope . GLOBAL ) , undefined ) ) ;
416
-
417
424
let total = 0 ;
418
425
let uniqueDays = 0 ;
419
- for ( const entry of count ) {
420
- if ( entry > 0 ) {
421
- uniqueDays ++ ;
422
- total += entry ;
426
+
427
+ const events = typeof setting . event === 'string' ? [ setting . event ] : setting . event ;
428
+ for ( const event of events ) {
429
+ const { count } = getCurrentActivationRecord ( safeParse ( this . storageService . get ( experimentEventStorageKey ( event ) , StorageScope . GLOBAL ) , undefined ) ) ;
430
+
431
+ for ( const entry of count ) {
432
+ if ( entry > 0 ) {
433
+ uniqueDays ++ ;
434
+ total += entry ;
435
+ }
423
436
}
424
437
}
425
438
0 commit comments