Skip to content

Commit d2e0b7b

Browse files
authored
Remove the unnecessary EnvFileTelemetry namespace (#11007)
1 parent dd82412 commit d2e0b7b

File tree

9 files changed

+77
-80
lines changed

9 files changed

+77
-80
lines changed

src/client/activation/activationManager.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { IFileSystem } from '../common/platform/types';
1313
import { IDisposable, Resource } from '../common/types';
1414
import { IInterpreterAutoSelectionService } from '../interpreter/autoSelection/types';
1515
import { IInterpreterService } from '../interpreter/contracts';
16-
import { EnvFileTelemetry } from '../telemetry/envFileTelemetry';
16+
import { sendActivationTelemetry } from '../telemetry/envFileTelemetry';
1717
import { IExtensionActivationManager, IExtensionActivationService, IExtensionSingleActivationService } from './types';
1818

1919
@injectable()
@@ -63,7 +63,7 @@ export class ExtensionActivationManager implements IExtensionActivationManager {
6363
// Get latest interpreter list in the background.
6464
this.interpreterService.getInterpreters(resource).ignoreErrors();
6565

66-
await EnvFileTelemetry.sendActivationTelemetry(this.fileSystem, this.workspaceService, resource);
66+
await sendActivationTelemetry(this.fileSystem, this.workspaceService, resource);
6767

6868
await this.autoSelection.autoSelectInterpreter(resource);
6969
await Promise.all(this.activationServices.map((item) => item.activate(resource)));

src/client/common/configSettings.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import '../common/extensions';
1717
import { IInterpreterAutoSeletionProxyService } from '../interpreter/autoSelection/types';
1818
import { sendTelemetryEvent } from '../telemetry';
1919
import { EventName } from '../telemetry/constants';
20-
import { EnvFileTelemetry } from '../telemetry/envFileTelemetry';
20+
import { sendSettingTelemetry } from '../telemetry/envFileTelemetry';
2121
import { IWorkspaceService } from './application/types';
2222
import { WorkspaceService } from './application/workspace';
2323
import { isTestExecution } from './constants';
@@ -205,7 +205,7 @@ export class PythonSettings implements IPythonSettings {
205205

206206
const envFileSetting = pythonSettings.get<string>('envFile');
207207
this.envFile = systemVariables.resolveAny(envFileSetting)!;
208-
EnvFileTelemetry.sendSettingTelemetry(this.workspace, envFileSetting);
208+
sendSettingTelemetry(this.workspace, envFileSetting);
209209

210210
// tslint:disable-next-line:no-any
211211
// tslint:disable-next-line:no-backbone-get-set-outside-model no-non-null-assertion no-any

src/client/common/variables/environmentVariablesProvider.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
import { inject, injectable } from 'inversify';
55
import { ConfigurationChangeEvent, Disposable, Event, EventEmitter, FileSystemWatcher, Uri } from 'vscode';
6-
import { EnvFileTelemetry } from '../../telemetry/envFileTelemetry';
6+
import { sendFileCreationTelemetry } from '../../telemetry/envFileTelemetry';
77
import { IWorkspaceService } from '../application/types';
88
import { IPlatformService } from '../platform/types';
99
import { IConfigurationService, ICurrentProcess, IDisposableRegistry } from '../types';
@@ -97,7 +97,7 @@ export class EnvironmentVariablesProvider implements IEnvironmentVariablesProvid
9797

9898
private onEnvironmentFileCreated(workspaceFolderUri?: Uri) {
9999
this.onEnvironmentFileChanged(workspaceFolderUri);
100-
EnvFileTelemetry.sendFileCreationTelemetry();
100+
sendFileCreationTelemetry();
101101
}
102102

103103
private onEnvironmentFileChanged(workspaceFolderUri?: Uri) {

src/client/telemetry/envFileTelemetry.ts

Lines changed: 48 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -11,77 +11,69 @@ import { SystemVariables } from '../common/variables/systemVariables';
1111
import { sendTelemetryEvent } from '.';
1212
import { EventName } from './constants';
1313

14-
export namespace EnvFileTelemetry {
15-
let _defaultEnvFileSetting: string | undefined;
16-
let envFileTelemetrySent = false;
14+
let _defaultEnvFileSetting: string | undefined;
15+
let envFileTelemetrySent = false;
1716

18-
export function sendSettingTelemetry(workspaceService: IWorkspaceService, envFileSetting?: string) {
19-
if (shouldSendTelemetry() && envFileSetting !== defaultEnvFileSetting(workspaceService)) {
20-
sendTelemetry(true);
21-
}
17+
export function sendSettingTelemetry(workspaceService: IWorkspaceService, envFileSetting?: string) {
18+
if (shouldSendTelemetry() && envFileSetting !== defaultEnvFileSetting(workspaceService)) {
19+
sendTelemetry(true);
2220
}
21+
}
2322

24-
export function sendFileCreationTelemetry() {
25-
if (shouldSendTelemetry()) {
26-
sendTelemetry();
27-
}
23+
export function sendFileCreationTelemetry() {
24+
if (shouldSendTelemetry()) {
25+
sendTelemetry();
2826
}
27+
}
2928

30-
export async function sendActivationTelemetry(
31-
fileSystem: IFileSystem,
32-
workspaceService: IWorkspaceService,
33-
resource: Resource
34-
) {
35-
if (shouldSendTelemetry()) {
36-
const systemVariables = new SystemVariables(resource, undefined, workspaceService);
37-
const envFilePath = systemVariables.resolveAny(defaultEnvFileSetting(workspaceService))!;
38-
const envFileExists = await fileSystem.fileExists(envFilePath);
29+
export async function sendActivationTelemetry(
30+
fileSystem: IFileSystem,
31+
workspaceService: IWorkspaceService,
32+
resource: Resource
33+
) {
34+
if (shouldSendTelemetry()) {
35+
const systemVariables = new SystemVariables(resource, undefined, workspaceService);
36+
const envFilePath = systemVariables.resolveAny(defaultEnvFileSetting(workspaceService))!;
37+
const envFileExists = await fileSystem.fileExists(envFilePath);
3938

40-
if (envFileExists) {
41-
sendTelemetry();
42-
}
39+
if (envFileExists) {
40+
sendTelemetry();
4341
}
4442
}
43+
}
4544

46-
function sendTelemetry(hasCustomEnvPath: boolean = false) {
47-
sendTelemetryEvent(EventName.ENVFILE_WORKSPACE, undefined, { hasCustomEnvPath });
48-
49-
envFileTelemetrySent = true;
50-
}
45+
function sendTelemetry(hasCustomEnvPath: boolean = false) {
46+
sendTelemetryEvent(EventName.ENVFILE_WORKSPACE, undefined, { hasCustomEnvPath });
5147

52-
function shouldSendTelemetry(): boolean {
53-
return !envFileTelemetrySent;
54-
}
48+
envFileTelemetrySent = true;
49+
}
5550

56-
function defaultEnvFileSetting(workspaceService: IWorkspaceService) {
57-
if (!_defaultEnvFileSetting) {
58-
const section = workspaceService.getConfiguration('python');
59-
_defaultEnvFileSetting = section.inspect<string>('envFile')?.defaultValue || '';
60-
}
51+
function shouldSendTelemetry(): boolean {
52+
return !envFileTelemetrySent;
53+
}
6154

62-
return _defaultEnvFileSetting;
55+
function defaultEnvFileSetting(workspaceService: IWorkspaceService) {
56+
if (!_defaultEnvFileSetting) {
57+
const section = workspaceService.getConfiguration('python');
58+
_defaultEnvFileSetting = section.inspect<string>('envFile')?.defaultValue || '';
6359
}
6460

65-
// Set state for tests.
66-
export namespace EnvFileTelemetryTests {
67-
export function setState({
68-
telemetrySent,
69-
defaultSetting
70-
}: {
71-
telemetrySent?: boolean;
72-
defaultSetting?: string;
73-
}) {
74-
if (telemetrySent !== undefined) {
75-
envFileTelemetrySent = telemetrySent;
76-
}
77-
if (defaultEnvFileSetting !== undefined) {
78-
_defaultEnvFileSetting = defaultSetting;
79-
}
80-
}
61+
return _defaultEnvFileSetting;
62+
}
8163

82-
export function resetState() {
83-
_defaultEnvFileSetting = undefined;
84-
envFileTelemetrySent = false;
64+
// Set state for tests.
65+
export namespace EnvFileTelemetryTests {
66+
export function setState({ telemetrySent, defaultSetting }: { telemetrySent?: boolean; defaultSetting?: string }) {
67+
if (telemetrySent !== undefined) {
68+
envFileTelemetrySent = telemetrySent;
69+
}
70+
if (defaultEnvFileSetting !== undefined) {
71+
_defaultEnvFileSetting = defaultSetting;
8572
}
8673
}
74+
75+
export function resetState() {
76+
_defaultEnvFileSetting = undefined;
77+
envFileTelemetrySent = false;
78+
}
8779
}

src/test/activation/activationManager.unit.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import { IDisposable } from '../../client/common/types';
2222
import { IInterpreterAutoSelectionService } from '../../client/interpreter/autoSelection/types';
2323
import { IInterpreterService } from '../../client/interpreter/contracts';
2424
import { InterpreterService } from '../../client/interpreter/interpreterService';
25-
import { EnvFileTelemetry } from '../../client/telemetry/envFileTelemetry';
25+
import * as EnvFileTelemetry from '../../client/telemetry/envFileTelemetry';
2626
import { sleep } from '../core';
2727

2828
// tslint:disable:max-func-body-length no-any

src/test/common/configSettings/configSettings.pythonPath.unit.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import * as typemoq from 'typemoq';
1313
import { Uri, WorkspaceConfiguration } from 'vscode';
1414
import { PythonSettings } from '../../../client/common/configSettings';
1515
import { noop } from '../../../client/common/utils/misc';
16-
import { EnvFileTelemetry } from '../../../client/telemetry/envFileTelemetry';
16+
import * as EnvFileTelemetry from '../../../client/telemetry/envFileTelemetry';
1717
import { MockAutoSelectionService } from '../../mocks/autoSelector';
1818
const untildify = require('untildify');
1919

src/test/common/configSettings/configSettings.unit.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import {
2727
IWorkspaceSymbolSettings
2828
} from '../../../client/common/types';
2929
import { noop } from '../../../client/common/utils/misc';
30-
import { EnvFileTelemetry } from '../../../client/telemetry/envFileTelemetry';
30+
import * as EnvFileTelemetry from '../../../client/telemetry/envFileTelemetry';
3131
import { MockAutoSelectionService } from '../../mocks/autoSelector';
3232

3333
// tslint:disable-next-line:max-func-body-length

src/test/common/variables/environmentVariablesProvider.unit.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import { clearCache } from '../../../client/common/utils/cacheUtils';
2121
import { EnvironmentVariablesService } from '../../../client/common/variables/environment';
2222
import { EnvironmentVariablesProvider } from '../../../client/common/variables/environmentVariablesProvider';
2323
import { IEnvironmentVariablesService } from '../../../client/common/variables/types';
24-
import { EnvFileTelemetry } from '../../../client/telemetry/envFileTelemetry';
24+
import * as EnvFileTelemetry from '../../../client/telemetry/envFileTelemetry';
2525
import { noop } from '../../core';
2626

2727
// tslint:disable:no-any max-func-body-length

src/test/telemetry/envFileTelemetry.unit.test.ts

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,12 @@ import { FileSystem } from '../../client/common/platform/fileSystem';
1212
import { IFileSystem } from '../../client/common/platform/types';
1313
import * as Telemetry from '../../client/telemetry';
1414
import { EventName } from '../../client/telemetry/constants';
15-
import { EnvFileTelemetry } from '../../client/telemetry/envFileTelemetry';
15+
import {
16+
EnvFileTelemetryTests,
17+
sendActivationTelemetry,
18+
sendFileCreationTelemetry,
19+
sendSettingTelemetry
20+
} from '../../client/telemetry/envFileTelemetry';
1621

1722
suite('Env file telemetry', () => {
1823
const defaultEnvFileValue = 'someDefaultValue';
@@ -53,45 +58,45 @@ suite('Env file telemetry', () => {
5358
teardown(() => {
5459
telemetryEvent = undefined;
5560
sinon.restore();
56-
EnvFileTelemetry.EnvFileTelemetryTests.resetState();
61+
EnvFileTelemetryTests.resetState();
5762
});
5863

5964
test('Setting telemetry should be sent with hasCustomEnvPath at true if the python.envFile setting is different from the default value', () => {
60-
EnvFileTelemetry.sendSettingTelemetry(instance(workspaceService), 'bar');
65+
sendSettingTelemetry(instance(workspaceService), 'bar');
6166

6267
sinon.assert.calledOnce(sendTelemetryStub);
6368
assert.deepEqual(telemetryEvent, { eventName: EventName.ENVFILE_WORKSPACE, hasCustomEnvPath: true });
6469
});
6570

6671
test('Setting telemetry should not be sent if a telemetry event has already been sent', () => {
67-
EnvFileTelemetry.EnvFileTelemetryTests.setState({ telemetrySent: true });
72+
EnvFileTelemetryTests.setState({ telemetrySent: true });
6873

69-
EnvFileTelemetry.sendSettingTelemetry(instance(workspaceService), 'bar');
74+
sendSettingTelemetry(instance(workspaceService), 'bar');
7075

7176
sinon.assert.notCalled(sendTelemetryStub);
7277
assert.deepEqual(telemetryEvent, undefined);
7378
});
7479

7580
test('Setting telemetry should not be sent if the python.envFile setting is the same as the default value', () => {
76-
EnvFileTelemetry.EnvFileTelemetryTests.setState({ defaultSetting: defaultEnvFileValue });
81+
EnvFileTelemetryTests.setState({ defaultSetting: defaultEnvFileValue });
7782

78-
EnvFileTelemetry.sendSettingTelemetry(instance(workspaceService), defaultEnvFileValue);
83+
sendSettingTelemetry(instance(workspaceService), defaultEnvFileValue);
7984

8085
sinon.assert.notCalled(sendTelemetryStub);
8186
assert.deepEqual(telemetryEvent, undefined);
8287
});
8388

8489
test('File creation telemetry should be sent if no telemetry event has been sent before', () => {
85-
EnvFileTelemetry.sendFileCreationTelemetry();
90+
sendFileCreationTelemetry();
8691

8792
sinon.assert.calledOnce(sendTelemetryStub);
8893
assert.deepEqual(telemetryEvent, { eventName: EventName.ENVFILE_WORKSPACE, hasCustomEnvPath: false });
8994
});
9095

9196
test('File creation telemetry should not be sent if a telemetry event has already been sent', () => {
92-
EnvFileTelemetry.EnvFileTelemetryTests.setState({ telemetrySent: true });
97+
EnvFileTelemetryTests.setState({ telemetrySent: true });
9398

94-
EnvFileTelemetry.sendFileCreationTelemetry();
99+
sendFileCreationTelemetry();
95100

96101
sinon.assert.notCalled(sendTelemetryStub);
97102
assert.deepEqual(telemetryEvent, undefined);
@@ -100,16 +105,16 @@ suite('Env file telemetry', () => {
100105
test('Activation telemetry should be sent if no telemetry event has been sent before, and a .env file exists', async () => {
101106
when(fileSystem.fileExists(anyString())).thenResolve(true);
102107

103-
await EnvFileTelemetry.sendActivationTelemetry(instance(fileSystem), instance(workspaceService), resource);
108+
await sendActivationTelemetry(instance(fileSystem), instance(workspaceService), resource);
104109

105110
sinon.assert.calledOnce(sendTelemetryStub);
106111
assert.deepEqual(telemetryEvent, { eventName: EventName.ENVFILE_WORKSPACE, hasCustomEnvPath: false });
107112
});
108113

109114
test('Activation telemetry should not be sent if a telemetry event has already been sent', async () => {
110-
EnvFileTelemetry.EnvFileTelemetryTests.setState({ telemetrySent: true });
115+
EnvFileTelemetryTests.setState({ telemetrySent: true });
111116

112-
await EnvFileTelemetry.sendActivationTelemetry(instance(fileSystem), instance(workspaceService), resource);
117+
await sendActivationTelemetry(instance(fileSystem), instance(workspaceService), resource);
113118

114119
sinon.assert.notCalled(sendTelemetryStub);
115120
assert.deepEqual(telemetryEvent, undefined);
@@ -118,7 +123,7 @@ suite('Env file telemetry', () => {
118123
test('Activation telemetry should not be sent if no .env file exists', async () => {
119124
when(fileSystem.fileExists(anyString())).thenResolve(false);
120125

121-
await EnvFileTelemetry.sendActivationTelemetry(instance(fileSystem), instance(workspaceService), resource);
126+
await sendActivationTelemetry(instance(fileSystem), instance(workspaceService), resource);
122127

123128
sinon.assert.notCalled(sendTelemetryStub);
124129
assert.deepEqual(telemetryEvent, undefined);

0 commit comments

Comments
 (0)