forked from DonJayamanne/pythonVSCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathenablementTracker.ts
More file actions
57 lines (53 loc) · 2.81 KB
/
Copy pathenablementTracker.ts
File metadata and controls
57 lines (53 loc) · 2.81 KB
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
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
'use strict';
import { inject, injectable } from 'inversify';
import { ConfigurationChangeEvent } from 'vscode';
import { IExtensionSingleActivationService } from '../../activation/types';
import { IWorkspaceService } from '../../common/application/types';
import { IDisposableRegistry, Resource } from '../../common/types';
import { sendTelemetryEvent } from '../../telemetry';
import { EventName } from '../../telemetry/constants';
import { ITestConfigSettingsService } from '../types';
import { ITestsHelper, TestProvider } from './types';
@injectable()
export class EnablementTracker implements IExtensionSingleActivationService {
constructor(
@inject(IWorkspaceService) private readonly workspaceService: IWorkspaceService,
@inject(IDisposableRegistry) private readonly disposables: IDisposableRegistry,
@inject(ITestConfigSettingsService) private readonly testConfig: ITestConfigSettingsService,
@inject(ITestsHelper) private readonly testsHelper: ITestsHelper
) {}
public async activate(): Promise<void> {
this.disposables.push(this.workspaceService.onDidChangeConfiguration(this.onDidChangeConfiguration, this));
}
public onDidChangeConfiguration(args: ConfigurationChangeEvent) {
const resourcesToCheck: Resource[] = [undefined];
if (Array.isArray(this.workspaceService.workspaceFolders)) {
this.workspaceService.workspaceFolders.forEach((item) => resourcesToCheck.push(item.uri));
}
const testProviders: TestProvider[] = ['nosetest', 'pytest', 'unittest'];
resourcesToCheck.forEach((resource) => {
const telemetry: Partial<Record<TestProvider, undefined | boolean>> = {};
testProviders.forEach((item) => {
const product = this.testsHelper.parseProduct(item);
const testingSetting = this.testConfig.getTestEnablingSetting(product);
const settingToCheck = `python.${testingSetting}`;
// If the setting was modified and if its value is true, then track this.
if (
args.affectsConfiguration(settingToCheck) &&
this.workspaceService.getConfiguration('python', resource).get<boolean>(testingSetting, false)
) {
telemetry[item] = true;
}
});
// If anyone of the items have been enabled, then send telemetry.
if (telemetry.nosetest || telemetry.pytest || telemetry.unittest) {
this.sendTelemetry(telemetry);
}
});
}
public sendTelemetry(telemetry: Partial<Record<TestProvider, undefined | boolean>>) {
sendTelemetryEvent(EventName.UNITTEST_ENABLED, undefined, telemetry);
}
}