diff --git a/news/3 Code Health/2904.md b/news/3 Code Health/2904.md new file mode 100644 index 000000000000..d4ed7013d98f --- /dev/null +++ b/news/3 Code Health/2904.md @@ -0,0 +1 @@ +Use enums for event names instead of constants. diff --git a/src/client/activation/activationService.ts b/src/client/activation/activationService.ts index d9a7bf023b8c..1bd665d0c543 100644 --- a/src/client/activation/activationService.ts +++ b/src/client/activation/activationService.ts @@ -22,7 +22,7 @@ import { } from '../common/types'; import { IServiceContainer } from '../ioc/types'; import { sendTelemetryEvent } from '../telemetry'; -import { PYTHON_LANGUAGE_SERVER_PLATFORM_NOT_SUPPORTED } from '../telemetry/constants'; +import { EventName } from '../telemetry/constants'; import { ExtensionActivators, IExtensionActivationService, IExtensionActivator @@ -58,8 +58,8 @@ export class ExtensionActivationService implements IExtensionActivationService, if (!jedi) { const diagnostic = await this.lsNotSupportedDiagnosticService.diagnose(); this.lsNotSupportedDiagnosticService.handle(diagnostic).ignoreErrors(); - if (diagnostic.length) { - sendTelemetryEvent(PYTHON_LANGUAGE_SERVER_PLATFORM_NOT_SUPPORTED); + if (diagnostic.length){ + sendTelemetryEvent(EventName.PYTHON_LANGUAGE_SERVER_PLATFORM_NOT_SUPPORTED); jedi = true; } } diff --git a/src/client/activation/downloader.ts b/src/client/activation/downloader.ts index 78624aa2ab92..a2388a171e6c 100644 --- a/src/client/activation/downloader.ts +++ b/src/client/activation/downloader.ts @@ -14,12 +14,11 @@ import { createDeferred } from '../common/utils/async'; import { Common, LanguageService } from '../common/utils/localize'; import { StopWatch } from '../common/utils/stopWatch'; import { sendTelemetryEvent } from '../telemetry'; +import { EventName } from '../telemetry/constants'; import { - PYTHON_LANGUAGE_SERVER_DOWNLOADED, - PYTHON_LANGUAGE_SERVER_ERROR, - PYTHON_LANGUAGE_SERVER_EXTRACTED -} from '../telemetry/constants'; -import { IHttpClient, ILanguageServerDownloader, ILanguageServerFolderService, IPlatformData } from './types'; + IHttpClient, ILanguageServerDownloader, ILanguageServerFolderService, + IPlatformData +} from './types'; const downloadFileExtension = '.nupkg'; @@ -53,11 +52,11 @@ export class LanguageServerDownloader implements ILanguageServerDownloader { this.output.appendLine(err); success = false; this.showMessageAndOptionallyShowOutput(LanguageService.lsFailedToDownload()).ignoreErrors(); - sendTelemetryEvent(PYTHON_LANGUAGE_SERVER_ERROR, undefined, { error: 'Failed to download (platform)' }, err); + sendTelemetryEvent(EventName.PYTHON_LANGUAGE_SERVER_ERROR, undefined, { error: 'Failed to download (platform)' }, err); throw new Error(err); } finally { sendTelemetryEvent( - PYTHON_LANGUAGE_SERVER_DOWNLOADED, + EventName.PYTHON_LANGUAGE_SERVER_DOWNLOADED, timer.elapsedTime, { success, lsVersion } ); @@ -71,11 +70,11 @@ export class LanguageServerDownloader implements ILanguageServerDownloader { this.output.appendLine(err); success = false; this.showMessageAndOptionallyShowOutput(LanguageService.lsFailedToExtract()).ignoreErrors(); - sendTelemetryEvent(PYTHON_LANGUAGE_SERVER_ERROR, undefined, { error: 'Failed to extract (platform)' }, err); + sendTelemetryEvent(EventName.PYTHON_LANGUAGE_SERVER_ERROR, undefined, { error: 'Failed to extract (platform)' }, err); throw new Error(err); } finally { sendTelemetryEvent( - PYTHON_LANGUAGE_SERVER_EXTRACTED, + EventName.PYTHON_LANGUAGE_SERVER_EXTRACTED, timer.elapsedTime, { success, lsVersion } ); diff --git a/src/client/activation/languageServer/languageServer.ts b/src/client/activation/languageServer/languageServer.ts index 7e772e54547f..6215b209ff58 100644 --- a/src/client/activation/languageServer/languageServer.ts +++ b/src/client/activation/languageServer/languageServer.ts @@ -11,11 +11,7 @@ import { Resource } from '../../common/types'; import { createDeferred, Deferred, sleep } from '../../common/utils/async'; import { noop } from '../../common/utils/misc'; import { captureTelemetry, sendTelemetryEvent } from '../../telemetry'; -import { - PYTHON_LANGUAGE_SERVER_ENABLED, - PYTHON_LANGUAGE_SERVER_READY, - PYTHON_LANGUAGE_SERVER_TELEMETRY -} from '../../telemetry/constants'; +import { EventName } from '../../telemetry/constants'; import { ProgressReporting } from '../progress'; import { ILanaguageServer as ILanguageServer, ILanguageClientFactory, LanguageClientFactory } from '../types'; @@ -51,7 +47,7 @@ export class LanguageServer implements ILanguageServer { } @traceDecorators.error('Failed to start language server') - @captureTelemetry(PYTHON_LANGUAGE_SERVER_ENABLED, undefined, true) + @captureTelemetry(EventName.PYTHON_LANGUAGE_SERVER_ENABLED, undefined, true) public async start(resource: Resource, options: LanguageClientOptions): Promise { this.languageClient = await this.factory.createLanguageClient(resource, options); this.disposables.push(this.languageClient!.start()); @@ -59,7 +55,7 @@ export class LanguageServer implements ILanguageServer { const progressReporting = new ProgressReporting(this.languageClient!); this.disposables.push(progressReporting); this.languageClient.onTelemetry(telemetryEvent => { - const eventName = telemetryEvent.EventName || PYTHON_LANGUAGE_SERVER_TELEMETRY; + const eventName = telemetryEvent.EventName || EventName.PYTHON_LANGUAGE_SERVER_TELEMETRY; sendTelemetryEvent(eventName, telemetryEvent.Measurements, telemetryEvent.Properties); }); } @@ -77,7 +73,7 @@ export class LanguageServer implements ILanguageServer { ) .ignoreErrors(); } - @captureTelemetry(PYTHON_LANGUAGE_SERVER_READY, undefined, true) + @captureTelemetry(EventName.PYTHON_LANGUAGE_SERVER_READY, undefined, true) private async serverReady(): Promise { while (this.languageClient && !this.languageClient!.initializeResult) { await sleep(100); diff --git a/src/client/activation/languageServer/languageServerCompatibilityService.ts b/src/client/activation/languageServer/languageServerCompatibilityService.ts index 97e50b664426..f5e81fca7e41 100644 --- a/src/client/activation/languageServer/languageServerCompatibilityService.ts +++ b/src/client/activation/languageServer/languageServerCompatibilityService.ts @@ -7,7 +7,7 @@ import { inject, injectable } from 'inversify'; import { IDotNetCompatibilityService } from '../../common/dotnet/types'; import { traceError } from '../../common/logger'; import { sendTelemetryEvent } from '../../telemetry'; -import { PYTHON_LANGUAGE_SERVER_PLATFORM_SUPPORTED } from '../../telemetry/constants'; +import { EventName } from '../../telemetry/constants'; import { ILanguageServerCompatibilityService } from '../types'; @injectable() @@ -16,11 +16,11 @@ export class LanguageServerCompatibilityService implements ILanguageServerCompat public async isSupported(): Promise { try { const supported = await this.dotnetCompatibility.isSupported(); - sendTelemetryEvent(PYTHON_LANGUAGE_SERVER_PLATFORM_SUPPORTED, undefined, { supported }); + sendTelemetryEvent(EventName.PYTHON_LANGUAGE_SERVER_PLATFORM_SUPPORTED, undefined, { supported }); return supported; } catch (ex) { traceError('Unable to determine whether LS is supported', ex); - sendTelemetryEvent(PYTHON_LANGUAGE_SERVER_PLATFORM_SUPPORTED, undefined, { supported: false, failureType: 'UnknownError' }); + sendTelemetryEvent(EventName.PYTHON_LANGUAGE_SERVER_PLATFORM_SUPPORTED, undefined, { supported: false, failureType: 'UnknownError' }); return false; } } diff --git a/src/client/activation/languageServer/manager.ts b/src/client/activation/languageServer/manager.ts index a8e53f9818d9..f3254468c246 100644 --- a/src/client/activation/languageServer/manager.ts +++ b/src/client/activation/languageServer/manager.ts @@ -10,7 +10,7 @@ import { IDisposable, Resource } from '../../common/types'; import { debounce } from '../../common/utils/decorators'; import { IServiceContainer } from '../../ioc/types'; import { captureTelemetry } from '../../telemetry'; -import { PYTHON_LANGUAGE_SERVER_STARTUP } from '../../telemetry/constants'; +import { EventName } from '../../telemetry/constants'; import { ILanaguageServer, ILanguageServerAnalysisOptions, ILanguageServerManager } from '../types'; const loadExtensionCommand = 'python._loadLanguageServerExtension'; @@ -64,7 +64,7 @@ export class LanguageServerManager implements ILanguageServerManager { } await this.startLanguageServer(); } - @captureTelemetry(PYTHON_LANGUAGE_SERVER_STARTUP, undefined, true) + @captureTelemetry(EventName.PYTHON_LANGUAGE_SERVER_STARTUP, undefined, true) @traceDecorators.verbose('Starting Language Server') protected async startLanguageServer(): Promise { this.languageServer = this.serviceContainer.get(ILanaguageServer); diff --git a/src/client/activation/progress.ts b/src/client/activation/progress.ts index e182d3be6404..2db7d9343b97 100644 --- a/src/client/activation/progress.ts +++ b/src/client/activation/progress.ts @@ -6,7 +6,7 @@ import { Disposable, LanguageClient } from 'vscode-languageclient'; import { createDeferred, Deferred } from '../common/utils/async'; import { StopWatch } from '../common/utils/stopWatch'; import { sendTelemetryEvent } from '../telemetry'; -import { PYTHON_LANGUAGE_SERVER_ANALYSISTIME } from '../telemetry/constants'; +import { EventName } from '../telemetry/constants'; // Draw the line at Language Server analysis 'timing out' // and becoming a failure-case at 1 minute: @@ -17,8 +17,6 @@ export class ProgressReporting implements Disposable { private progress: Progress<{ message?: string; increment?: number }> | undefined; private progressDeferred: Deferred | undefined; private progressTimer?: StopWatch; - // tslint:disable-next-line:no-unused-variable - private progressTimeout?: NodeJS.Timer; constructor(private readonly languageClient: LanguageClient) { this.languageClient.onNotification('python/setStatusBarMessage', (m: string) => { @@ -35,7 +33,7 @@ export class ProgressReporting implements Disposable { this.progressDeferred = createDeferred(); this.progressTimer = new StopWatch(); - this.progressTimeout = setTimeout( + setTimeout( this.handleTimeout.bind(this), ANALYSIS_TIMEOUT_MS ); @@ -73,13 +71,12 @@ export class ProgressReporting implements Disposable { private completeAnalysisTracking(success: boolean): void { if (this.progressTimer) { sendTelemetryEvent( - PYTHON_LANGUAGE_SERVER_ANALYSISTIME, + EventName.PYTHON_LANGUAGE_SERVER_ANALYSISTIME, this.progressTimer.elapsedTime, { success } ); } this.progressTimer = undefined; - this.progressTimeout = undefined; } // tslint:disable-next-line:no-any diff --git a/src/client/application/diagnostics/base.ts b/src/client/application/diagnostics/base.ts index 127620ed1f54..f67ce3e10b36 100644 --- a/src/client/application/diagnostics/base.ts +++ b/src/client/application/diagnostics/base.ts @@ -7,7 +7,7 @@ import { injectable, unmanaged } from 'inversify'; import { DiagnosticSeverity } from 'vscode'; import { IServiceContainer } from '../../ioc/types'; import { sendTelemetryEvent } from '../../telemetry'; -import { DIAGNOSTICS_MESSAGE } from '../../telemetry/constants'; +import { EventName } from '../../telemetry/constants'; import { DiagnosticScope, IDiagnostic, IDiagnosticFilterService, IDiagnosticsService } from './types'; @injectable() @@ -26,7 +26,7 @@ export abstract class BaseDiagnosticsService implements IDiagnosticsService { public abstract diagnose(): Promise; public abstract handle(diagnostics: IDiagnostic[]): Promise; public async canHandle(diagnostic: IDiagnostic): Promise { - sendTelemetryEvent(DIAGNOSTICS_MESSAGE, undefined, { code: diagnostic.code }); + sendTelemetryEvent(EventName.DIAGNOSTICS_MESSAGE, undefined, { code: diagnostic.code }); return this.supportedDiagnosticCodes.filter(item => item === diagnostic.code).length > 0; } } diff --git a/src/client/application/diagnostics/checks/powerShellActivation.ts b/src/client/application/diagnostics/checks/powerShellActivation.ts index 532ec869cde1..3dd4f0853fac 100644 --- a/src/client/application/diagnostics/checks/powerShellActivation.ts +++ b/src/client/application/diagnostics/checks/powerShellActivation.ts @@ -11,7 +11,7 @@ import { useCommandPromptAsDefaultShell } from '../../../common/terminal/command import { IConfigurationService, ICurrentProcess } from '../../../common/types'; import { IServiceContainer } from '../../../ioc/types'; import { sendTelemetryEvent } from '../../../telemetry'; -import { DIAGNOSTICS_ACTION } from '../../../telemetry/constants'; +import { EventName } from '../../../telemetry/constants'; import { BaseDiagnostic, BaseDiagnosticsService } from '../base'; import { IDiagnosticsCommandFactory } from '../commands/types'; import { DiagnosticCodes } from '../constants'; @@ -58,7 +58,7 @@ export class PowerShellActivationHackDiagnosticsService extends BaseDiagnosticsS // tslint:disable-next-line:no-object-literal-type-assertion command: { diagnostic, invoke: async (): Promise => { - sendTelemetryEvent(DIAGNOSTICS_ACTION, undefined, { action: 'switchToCommandPrompt' }); + sendTelemetryEvent(EventName.DIAGNOSTICS_ACTION, undefined, { action: 'switchToCommandPrompt' }); useCommandPromptAsDefaultShell(currentProcess, configurationService) .catch(ex => Logger.error('Use Command Prompt as default shell', ex)); } diff --git a/src/client/application/diagnostics/commands/execVSCCommand.ts b/src/client/application/diagnostics/commands/execVSCCommand.ts index b10fc001e5fc..0fe31b78d87b 100644 --- a/src/client/application/diagnostics/commands/execVSCCommand.ts +++ b/src/client/application/diagnostics/commands/execVSCCommand.ts @@ -6,7 +6,7 @@ import { ICommandManager } from '../../../common/application/types'; import { IServiceContainer } from '../../../ioc/types'; import { sendTelemetryEvent } from '../../../telemetry'; -import { DIAGNOSTICS_ACTION } from '../../../telemetry/constants'; +import { EventName } from '../../../telemetry/constants'; import { IDiagnostic } from '../types'; import { BaseDiagnosticCommand } from './base'; @@ -15,7 +15,7 @@ export class ExecuteVSCCommand extends BaseDiagnosticCommand { super(diagnostic); } public async invoke(): Promise { - sendTelemetryEvent(DIAGNOSTICS_ACTION, undefined, { commandName: this.commandName }); + sendTelemetryEvent(EventName.DIAGNOSTICS_ACTION, undefined, { commandName: this.commandName }); const cmdManager = this.serviceContainer.get(ICommandManager); return cmdManager.executeCommand(this.commandName).then(() => undefined); } diff --git a/src/client/application/diagnostics/commands/ignore.ts b/src/client/application/diagnostics/commands/ignore.ts index 89b32abfe220..f73d068c639d 100644 --- a/src/client/application/diagnostics/commands/ignore.ts +++ b/src/client/application/diagnostics/commands/ignore.ts @@ -5,7 +5,7 @@ import { IServiceContainer } from '../../../ioc/types'; import { sendTelemetryEvent } from '../../../telemetry'; -import { DIAGNOSTICS_ACTION } from '../../../telemetry/constants'; +import { EventName } from '../../../telemetry/constants'; import { DiagnosticScope, IDiagnostic, IDiagnosticFilterService } from '../types'; import { BaseDiagnosticCommand } from './base'; @@ -14,7 +14,7 @@ export class IgnoreDiagnosticCommand extends BaseDiagnosticCommand { super(diagnostic); } public invoke(): Promise { - sendTelemetryEvent(DIAGNOSTICS_ACTION, undefined, { ignoreCode: this.diagnostic.code }); + sendTelemetryEvent(EventName.DIAGNOSTICS_ACTION, undefined, { ignoreCode: this.diagnostic.code }); const filter = this.serviceContainer.get(IDiagnosticFilterService); return filter.ignoreDiagnostic(this.diagnostic.code, this.scope); } diff --git a/src/client/application/diagnostics/commands/launchBrowser.ts b/src/client/application/diagnostics/commands/launchBrowser.ts index 0fcd975bd48f..4509044f6770 100644 --- a/src/client/application/diagnostics/commands/launchBrowser.ts +++ b/src/client/application/diagnostics/commands/launchBrowser.ts @@ -6,7 +6,7 @@ import { IBrowserService } from '../../../common/types'; import { IServiceContainer } from '../../../ioc/types'; import { sendTelemetryEvent } from '../../../telemetry'; -import { DIAGNOSTICS_ACTION } from '../../../telemetry/constants'; +import { EventName } from '../../../telemetry/constants'; import { IDiagnostic } from '../types'; import { BaseDiagnosticCommand } from './base'; @@ -15,7 +15,7 @@ export class LaunchBrowserCommand extends BaseDiagnosticCommand { super(diagnostic); } public async invoke(): Promise { - sendTelemetryEvent(DIAGNOSTICS_ACTION, undefined, { url: this.url }); + sendTelemetryEvent(EventName.DIAGNOSTICS_ACTION, undefined, { url: this.url }); const browser = this.serviceContainer.get(IBrowserService); return browser.launch(this.url); } diff --git a/src/client/common/configSettings.ts b/src/client/common/configSettings.ts index e776599d3718..d890dc8c60b2 100644 --- a/src/client/common/configSettings.ts +++ b/src/client/common/configSettings.ts @@ -7,7 +7,7 @@ import { ConfigurationChangeEvent, ConfigurationTarget, DiagnosticSeverity, Disp import '../common/extensions'; import { IInterpreterAutoSeletionProxyService } from '../interpreter/autoSelection/types'; import { sendTelemetryEvent } from '../telemetry'; -import { COMPLETION_ADD_BRACKETS, FORMAT_ON_TYPE } from '../telemetry/constants'; +import { EventName } from '../telemetry/constants'; import { IWorkspaceService } from './application/types'; import { WorkspaceService } from './application/workspace'; import { isTestExecution } from './constants'; @@ -82,8 +82,8 @@ export class PythonSettings extends EventEmitter implements IPythonSettings { // tslint:disable-next-line:no-any const config = workspace.getConfiguration('editor', resource ? resource : null as any); const formatOnType = config ? config.get('formatOnType', false) : false; - sendTelemetryEvent(COMPLETION_ADD_BRACKETS, undefined, { enabled: settings.autoComplete ? settings.autoComplete.addBrackets : false }); - sendTelemetryEvent(FORMAT_ON_TYPE, undefined, { enabled: formatOnType }); + sendTelemetryEvent(EventName.COMPLETION_ADD_BRACKETS, undefined, { enabled: settings.autoComplete ? settings.autoComplete.addBrackets : false }); + sendTelemetryEvent(EventName.FORMAT_ON_TYPE, undefined, { enabled: formatOnType }); } // tslint:disable-next-line:no-non-null-assertion return PythonSettings.pythonSettings.get(workspaceFolderKey)!; diff --git a/src/client/common/installer/productInstaller.ts b/src/client/common/installer/productInstaller.ts index 8514e978c059..9824cfc15b41 100644 --- a/src/client/common/installer/productInstaller.ts +++ b/src/client/common/installer/productInstaller.ts @@ -7,7 +7,7 @@ import '../../common/extensions'; import { IServiceContainer } from '../../ioc/types'; import { LinterId } from '../../linters/types'; import { sendTelemetryEvent } from '../../telemetry'; -import { LINTER_NOT_INSTALLED_PROMPT } from '../../telemetry/constants'; +import { EventName } from '../../telemetry/constants'; import { IApplicationShell, ICommandManager, IWorkspaceService } from '../application/types'; import { Commands, STANDARD_OUTPUT_CHANNEL } from '../constants'; import { IPlatformService } from '../platform/types'; @@ -197,16 +197,16 @@ export class LinterInstaller extends BaseInstaller { } const response = await this.appShell.showErrorMessage(message, ...options); if (response === install) { - sendTelemetryEvent(LINTER_NOT_INSTALLED_PROMPT, undefined, { tool: productName as LinterId, action: 'install' }); + sendTelemetryEvent(EventName.LINTER_NOT_INSTALLED_PROMPT, undefined, { tool: productName as LinterId, action: 'install' }); return this.install(product, resource); } else if (response === disableInstallPrompt) { await this.setStoredResponse(disableLinterInstallPromptKey, true); - sendTelemetryEvent(LINTER_NOT_INSTALLED_PROMPT, undefined, { tool: productName as LinterId, action: 'disablePrompt' }); + sendTelemetryEvent(EventName.LINTER_NOT_INSTALLED_PROMPT, undefined, { tool: productName as LinterId, action: 'disablePrompt' }); return InstallerResponse.Ignore; } if (response === selectLinter) { - sendTelemetryEvent(LINTER_NOT_INSTALLED_PROMPT, undefined, { action: 'select' }); + sendTelemetryEvent(EventName.LINTER_NOT_INSTALLED_PROMPT, undefined, { action: 'select' }); const commandManager = this.serviceContainer.get(ICommandManager); await commandManager.executeCommand(Commands.Set_Linter); } diff --git a/src/client/common/nuget/azureBlobStoreNugetRepository.ts b/src/client/common/nuget/azureBlobStoreNugetRepository.ts index 3bf649da52c0..f006c15b635a 100644 --- a/src/client/common/nuget/azureBlobStoreNugetRepository.ts +++ b/src/client/common/nuget/azureBlobStoreNugetRepository.ts @@ -6,7 +6,7 @@ import { inject, injectable, unmanaged } from 'inversify'; import { IServiceContainer } from '../../ioc/types'; import { captureTelemetry } from '../../telemetry'; -import { PYTHON_LANGUAGE_SERVER_LIST_BLOB_STORE_PACKAGES } from '../../telemetry/constants'; +import { EventName } from '../../telemetry/constants'; import { traceDecorators } from '../logger'; import { INugetRepository, INugetService, NugetPackage } from './types'; @@ -20,7 +20,7 @@ export class AzureBlobStoreNugetRepository implements INugetRepository { return this.listPackages(this.azureBlobStorageAccount, this.azureBlobStorageContainer, packageName, this.azureCDNBlobStorageAccount); } - @captureTelemetry(PYTHON_LANGUAGE_SERVER_LIST_BLOB_STORE_PACKAGES) + @captureTelemetry(EventName.PYTHON_LANGUAGE_SERVER_LIST_BLOB_STORE_PACKAGES) @traceDecorators.verbose('Listing Nuget Packages') protected async listPackages(azureBlobStorageAccount: string, azureBlobStorageContainer: string, packageName: string, azureCDNBlobStorageAccount: string) { // tslint:disable-next-line:no-require-imports diff --git a/src/client/common/platform/platformService.ts b/src/client/common/platform/platformService.ts index 8f86b1f36fa4..53ef4d6b721e 100644 --- a/src/client/common/platform/platformService.ts +++ b/src/client/common/platform/platformService.ts @@ -6,7 +6,7 @@ import { injectable } from 'inversify'; import * as os from 'os'; import { coerce, SemVer } from 'semver'; import { sendTelemetryEvent } from '../../telemetry'; -import { PLATFORM_INFO, PlatformErrors } from '../../telemetry/constants'; +import { EventName, PlatformErrors } from '../../telemetry/constants'; import { OSType } from '../utils/platform'; import { parseVersion } from '../utils/version'; import { NON_WINDOWS_PATH_VARIABLE_NAME, WINDOWS_PATH_VARIABLE_NAME } from './constants'; @@ -35,12 +35,12 @@ export class PlatformService implements IPlatformService { try { const ver = coerce(os.release()); if (ver) { - sendTelemetryEvent(PLATFORM_INFO, undefined, { osVersion: `${ver.major}.${ver.minor}.${ver.patch}` }); + sendTelemetryEvent(EventName.PLATFORM_INFO, undefined, { osVersion: `${ver.major}.${ver.minor}.${ver.patch}` }); return this.version = ver; } throw new Error('Unable to parse version'); } catch (ex) { - sendTelemetryEvent(PLATFORM_INFO, undefined, { failureType: PlatformErrors.FailedToParseVersion }); + sendTelemetryEvent(EventName.PLATFORM_INFO, undefined, { failureType: PlatformErrors.FailedToParseVersion }); return parseVersion(os.release()); } default: @@ -72,7 +72,7 @@ function getOSType(platform: string = process.platform): OSType { } else if (/^linux/.test(platform)) { return OSType.Linux; } else { - sendTelemetryEvent(PLATFORM_INFO, undefined, { failureType: PlatformErrors.FailedToDetermineOS }); + sendTelemetryEvent(EventName.PLATFORM_INFO, undefined, { failureType: PlatformErrors.FailedToDetermineOS }); return OSType.Unknown; } } diff --git a/src/client/common/process/pythonExecutionFactory.ts b/src/client/common/process/pythonExecutionFactory.ts index 536847f39562..0a91946e8d43 100644 --- a/src/client/common/process/pythonExecutionFactory.ts +++ b/src/client/common/process/pythonExecutionFactory.ts @@ -5,7 +5,7 @@ import { inject, injectable } from 'inversify'; import { IEnvironmentActivationService } from '../../interpreter/activation/types'; import { IServiceContainer } from '../../ioc/types'; import { sendTelemetryEvent } from '../../telemetry'; -import { PYTHON_INTERPRETER_ACTIVATION_ENVIRONMENT_VARIABLES } from '../../telemetry/constants'; +import { EventName } from '../../telemetry/constants'; import { IConfigurationService } from '../types'; import { ProcessService } from './proc'; import { PythonExecutionService } from './pythonProcess'; @@ -34,7 +34,7 @@ export class PythonExecutionFactory implements IPythonExecutionFactory { public async createActivatedEnvironment(options: ExecutionFactoryCreateWithEnvironmentOptions): Promise { const envVars = await this.activationHelper.getActivatedEnvironmentVariables(options.resource, options.interpreter); const hasEnvVars = envVars && Object.keys(envVars).length > 0; - sendTelemetryEvent(PYTHON_INTERPRETER_ACTIVATION_ENVIRONMENT_VARIABLES, undefined, { hasEnvVars }); + sendTelemetryEvent(EventName.PYTHON_INTERPRETER_ACTIVATION_ENVIRONMENT_VARIABLES, undefined, { hasEnvVars }); if (!hasEnvVars) { return this.create({ resource: options.resource, pythonPath: options.interpreter ? options.interpreter.path : undefined }); } diff --git a/src/client/common/terminal/helper.ts b/src/client/common/terminal/helper.ts index 19e4794a737f..4dfd987d2fd9 100644 --- a/src/client/common/terminal/helper.ts +++ b/src/client/common/terminal/helper.ts @@ -5,7 +5,7 @@ import { inject, injectable, named } from 'inversify'; import { Terminal, Uri } from 'vscode'; import { ICondaService, IInterpreterService, InterpreterType, PythonInterpreter } from '../../interpreter/contracts'; import { sendTelemetryEvent } from '../../telemetry'; -import { PYTHON_INTERPRETER_ACTIVATION_FOR_RUNNING_CODE, PYTHON_INTERPRETER_ACTIVATION_FOR_TERMINAL } from '../../telemetry/constants'; +import { EventName } from '../../telemetry/constants'; import { ITerminalManager, IWorkspaceService } from '../application/types'; import '../extensions'; import { traceDecorators, traceError } from '../logger'; @@ -106,7 +106,7 @@ export class TerminalHelper implements ITerminalHelper { public async getEnvironmentActivationCommands(terminalShellType: TerminalShellType, resource?: Uri): Promise { const providers = [this.pipenv, this.pyenv, this.bashCShellFish, this.commandPromptAndPowerShell]; const promise = this.getActivationCommands(resource || undefined, undefined, terminalShellType, providers); - this.sendTelemetry(resource, terminalShellType, PYTHON_INTERPRETER_ACTIVATION_FOR_TERMINAL, promise).ignoreErrors(); + this.sendTelemetry(resource, terminalShellType, EventName.PYTHON_INTERPRETER_ACTIVATION_FOR_TERMINAL, promise).ignoreErrors(); return promise; } public async getEnvironmentActivationShellCommands(resource: Resource, interpreter?: PythonInterpreter): Promise { @@ -116,7 +116,7 @@ export class TerminalHelper implements ITerminalHelper { } const providers = [this.bashCShellFish, this.commandPromptAndPowerShell]; const promise = this.getActivationCommands(resource, interpreter, shell, providers); - this.sendTelemetry(resource, shell, PYTHON_INTERPRETER_ACTIVATION_FOR_RUNNING_CODE, promise).ignoreErrors(); + this.sendTelemetry(resource, shell, EventName.PYTHON_INTERPRETER_ACTIVATION_FOR_RUNNING_CODE, promise).ignoreErrors(); return promise; } @traceDecorators.error('Failed to capture telemetry') diff --git a/src/client/common/terminal/service.ts b/src/client/common/terminal/service.ts index 7e6e60d4a91d..2db3b9f5c3c3 100644 --- a/src/client/common/terminal/service.ts +++ b/src/client/common/terminal/service.ts @@ -7,7 +7,7 @@ import '../../common/extensions'; import { IInterpreterService } from '../../interpreter/contracts'; import { IServiceContainer } from '../../ioc/types'; import { captureTelemetry } from '../../telemetry'; -import { TERMINAL_CREATE } from '../../telemetry/constants'; +import { EventName } from '../../telemetry/constants'; import { ITerminalManager } from '../application/types'; import { IConfigurationService, IDisposableRegistry } from '../types'; import { ITerminalActivator, ITerminalHelper, ITerminalService, TerminalShellType } from './types'; @@ -83,6 +83,6 @@ export class TerminalService implements ITerminalService, Disposable { const interpreterInfo = await this.serviceContainer.get(IInterpreterService).getInterpreterDetails(pythonPath); const pythonVersion = (interpreterInfo && interpreterInfo.version) ? interpreterInfo.version.raw : undefined; const interpreterType = interpreterInfo ? interpreterInfo.type : undefined; - captureTelemetry(TERMINAL_CREATE, { terminal: this.terminalShellType, pythonVersion, interpreterType }); + captureTelemetry(EventName.TERMINAL_CREATE, { terminal: this.terminalShellType, pythonVersion, interpreterType }); } } diff --git a/src/client/debugger/extension/configuration/debugConfigurationService.ts b/src/client/debugger/extension/configuration/debugConfigurationService.ts index a94463a2ab65..5269d61826aa 100644 --- a/src/client/debugger/extension/configuration/debugConfigurationService.ts +++ b/src/client/debugger/extension/configuration/debugConfigurationService.ts @@ -11,7 +11,7 @@ import { DebugConfigurationPrompts } from '../../../common/utils/localize'; import { IMultiStepInput, IMultiStepInputFactory, InputStep, IQuickPickParameters } from '../../../common/utils/multiStepInput'; import { EXTENSION_ROOT_DIR } from '../../../constants'; import { sendTelemetryEvent } from '../../../telemetry'; -import { DEBUGGER_CONFIGURATION_PROMPTS } from '../../../telemetry/constants'; +import { EventName } from '../../../telemetry/constants'; import { AttachRequestArguments, DebugConfigurationArguments, LaunchRequestArguments } from '../../types'; import { DebugConfigurationState, DebugConfigurationType, IDebugConfigurationService } from '../types'; import { IDebugConfigurationProviderFactory, IDebugConfigurationResolver } from './types'; @@ -47,7 +47,7 @@ export class PythonDebugConfigurationService implements IDebugConfigurationServi } } protected async getDefaultDebugConfig(): Promise { - sendTelemetryEvent(DEBUGGER_CONFIGURATION_PROMPTS, undefined, { configurationType: DebugConfigurationType.default }); + sendTelemetryEvent(EventName.DEBUGGER_CONFIGURATION_PROMPTS, undefined, { configurationType: DebugConfigurationType.default }); const jsFilePath = path.join(EXTENSION_ROOT_DIR, 'resources', 'default.launch.json'); const jsonStr = await this.fs.readFile(jsFilePath); return JSON.parse(jsonStr) as DebugConfiguration[]; diff --git a/src/client/debugger/extension/configuration/providers/djangoLaunch.ts b/src/client/debugger/extension/configuration/providers/djangoLaunch.ts index 2cfc9aa927d7..f6ca674476df 100644 --- a/src/client/debugger/extension/configuration/providers/djangoLaunch.ts +++ b/src/client/debugger/extension/configuration/providers/djangoLaunch.ts @@ -13,7 +13,7 @@ import { DebugConfigurationPrompts, localize } from '../../../../common/utils/lo import { MultiStepInput } from '../../../../common/utils/multiStepInput'; import { SystemVariables } from '../../../../common/variables/systemVariables'; import { sendTelemetryEvent } from '../../../../telemetry'; -import { DEBUGGER_CONFIGURATION_PROMPTS } from '../../../../telemetry/constants'; +import { EventName } from '../../../../telemetry/constants'; import { DebuggerTypeName } from '../../../constants'; import { LaunchRequestArguments } from '../../../types'; import { DebugConfigurationState, DebugConfigurationType, IDebugConfigurationProvider } from '../../types'; @@ -55,7 +55,7 @@ export class DjangoLaunchDebugConfigurationProvider implements IDebugConfigurati } } - sendTelemetryEvent(DEBUGGER_CONFIGURATION_PROMPTS, undefined, { configurationType: DebugConfigurationType.launchDjango, autoDetectedDjangoManagePyPath: !!program, manuallyEnteredAValue }); + sendTelemetryEvent(EventName.DEBUGGER_CONFIGURATION_PROMPTS, undefined, { configurationType: DebugConfigurationType.launchDjango, autoDetectedDjangoManagePyPath: !!program, manuallyEnteredAValue }); Object.assign(state.config, config); } public async validateManagePy(folder: WorkspaceFolder | undefined, defaultValue: string, selected?: string): Promise { diff --git a/src/client/debugger/extension/configuration/providers/fileLaunch.ts b/src/client/debugger/extension/configuration/providers/fileLaunch.ts index 7718778ff24e..462d4368f347 100644 --- a/src/client/debugger/extension/configuration/providers/fileLaunch.ts +++ b/src/client/debugger/extension/configuration/providers/fileLaunch.ts @@ -7,14 +7,14 @@ import { injectable } from 'inversify'; import { localize } from '../../../../common/utils/localize'; import { MultiStepInput } from '../../../../common/utils/multiStepInput'; import { captureTelemetry } from '../../../../telemetry'; -import { DEBUGGER_CONFIGURATION_PROMPTS } from '../../../../telemetry/constants'; +import { EventName } from '../../../../telemetry/constants'; import { DebuggerTypeName } from '../../../constants'; import { LaunchRequestArguments } from '../../../types'; import { DebugConfigurationState, DebugConfigurationType, IDebugConfigurationProvider } from '../../types'; @injectable() export class FileLaunchDebugConfigurationProvider implements IDebugConfigurationProvider { - @captureTelemetry(DEBUGGER_CONFIGURATION_PROMPTS, { configurationType: DebugConfigurationType.launchFile }, false) + @captureTelemetry(EventName.DEBUGGER_CONFIGURATION_PROMPTS, { configurationType: DebugConfigurationType.launchFile }, false) public async buildConfiguration(_input: MultiStepInput, state: DebugConfigurationState) { const config: Partial = { name: localize('python.snippet.launch.standard.label', 'Python: Current File')(), diff --git a/src/client/debugger/extension/configuration/providers/flaskLaunch.ts b/src/client/debugger/extension/configuration/providers/flaskLaunch.ts index 1f21c10feff4..7009460c90de 100644 --- a/src/client/debugger/extension/configuration/providers/flaskLaunch.ts +++ b/src/client/debugger/extension/configuration/providers/flaskLaunch.ts @@ -10,7 +10,7 @@ import { IFileSystem } from '../../../../common/platform/types'; import { DebugConfigurationPrompts, localize } from '../../../../common/utils/localize'; import { MultiStepInput } from '../../../../common/utils/multiStepInput'; import { sendTelemetryEvent } from '../../../../telemetry'; -import { DEBUGGER_CONFIGURATION_PROMPTS } from '../../../../telemetry/constants'; +import { EventName } from '../../../../telemetry/constants'; import { DebuggerTypeName } from '../../../constants'; import { LaunchRequestArguments } from '../../../types'; import { DebugConfigurationState, DebugConfigurationType, IDebugConfigurationProvider } from '../../types'; @@ -55,7 +55,7 @@ export class FlaskLaunchDebugConfigurationProvider implements IDebugConfiguratio } } - sendTelemetryEvent(DEBUGGER_CONFIGURATION_PROMPTS, undefined, { configurationType: DebugConfigurationType.launchFlask, autoDetectedFlaskAppPyPath: !!application, manuallyEnteredAValue }); + sendTelemetryEvent(EventName.DEBUGGER_CONFIGURATION_PROMPTS, undefined, { configurationType: DebugConfigurationType.launchFlask, autoDetectedFlaskAppPyPath: !!application, manuallyEnteredAValue }); Object.assign(state.config, config); } protected async getApplicationPath(folder: WorkspaceFolder | undefined): Promise { diff --git a/src/client/debugger/extension/configuration/providers/moduleLaunch.ts b/src/client/debugger/extension/configuration/providers/moduleLaunch.ts index baf11fa32f04..061cdd967c7d 100644 --- a/src/client/debugger/extension/configuration/providers/moduleLaunch.ts +++ b/src/client/debugger/extension/configuration/providers/moduleLaunch.ts @@ -7,7 +7,7 @@ import { injectable } from 'inversify'; import { DebugConfigurationPrompts, localize } from '../../../../common/utils/localize'; import { MultiStepInput } from '../../../../common/utils/multiStepInput'; import { sendTelemetryEvent } from '../../../../telemetry'; -import { DEBUGGER_CONFIGURATION_PROMPTS } from '../../../../telemetry/constants'; +import { EventName } from '../../../../telemetry/constants'; import { DebuggerTypeName } from '../../../constants'; import { LaunchRequestArguments } from '../../../types'; import { DebugConfigurationState, DebugConfigurationType, IDebugConfigurationProvider } from '../../types'; @@ -33,7 +33,7 @@ export class ModuleLaunchDebugConfigurationProvider implements IDebugConfigurati config.module = selectedModule; } - sendTelemetryEvent(DEBUGGER_CONFIGURATION_PROMPTS, undefined, { configurationType: DebugConfigurationType.launchModule, manuallyEnteredAValue }); + sendTelemetryEvent(EventName.DEBUGGER_CONFIGURATION_PROMPTS, undefined, { configurationType: DebugConfigurationType.launchModule, manuallyEnteredAValue }); Object.assign(state.config, config); } } diff --git a/src/client/debugger/extension/configuration/providers/pyramidLaunch.ts b/src/client/debugger/extension/configuration/providers/pyramidLaunch.ts index da50c6703ed2..61f21470acd4 100644 --- a/src/client/debugger/extension/configuration/providers/pyramidLaunch.ts +++ b/src/client/debugger/extension/configuration/providers/pyramidLaunch.ts @@ -13,7 +13,7 @@ import { DebugConfigurationPrompts, localize } from '../../../../common/utils/lo import { MultiStepInput } from '../../../../common/utils/multiStepInput'; import { SystemVariables } from '../../../../common/variables/systemVariables'; import { sendTelemetryEvent } from '../../../../telemetry'; -import { DEBUGGER_CONFIGURATION_PROMPTS } from '../../../../telemetry/constants'; +import { EventName } from '../../../../telemetry/constants'; import { DebuggerTypeName } from '../../../constants'; import { LaunchRequestArguments } from '../../../types'; import { DebugConfigurationState, DebugConfigurationType, IDebugConfigurationProvider } from '../../types'; @@ -55,7 +55,7 @@ export class PyramidLaunchDebugConfigurationProvider implements IDebugConfigurat } } - sendTelemetryEvent(DEBUGGER_CONFIGURATION_PROMPTS, undefined, { configurationType: DebugConfigurationType.launchPyramid, autoDetectedPyramidIniPath: !!iniPath, manuallyEnteredAValue }); + sendTelemetryEvent(EventName.DEBUGGER_CONFIGURATION_PROMPTS, undefined, { configurationType: DebugConfigurationType.launchPyramid, autoDetectedPyramidIniPath: !!iniPath, manuallyEnteredAValue }); Object.assign(state.config, config); } public async validateIniPath(folder: WorkspaceFolder | undefined, defaultValue: string, selected?: string): Promise { diff --git a/src/client/debugger/extension/configuration/providers/remoteAttach.ts b/src/client/debugger/extension/configuration/providers/remoteAttach.ts index 9d6fee8c307e..49235afbdad5 100644 --- a/src/client/debugger/extension/configuration/providers/remoteAttach.ts +++ b/src/client/debugger/extension/configuration/providers/remoteAttach.ts @@ -7,7 +7,7 @@ import { injectable } from 'inversify'; import { DebugConfigurationPrompts, localize } from '../../../../common/utils/localize'; import { InputStep, MultiStepInput } from '../../../../common/utils/multiStepInput'; import { sendTelemetryEvent } from '../../../../telemetry'; -import { DEBUGGER_CONFIGURATION_PROMPTS } from '../../../../telemetry/constants'; +import { EventName } from '../../../../telemetry/constants'; import { DebuggerTypeName } from '../../../constants'; import { AttachRequestArguments } from '../../../types'; import { DebugConfigurationState, DebugConfigurationType, IDebugConfigurationProvider } from '../../types'; @@ -38,7 +38,7 @@ export class RemoteAttachDebugConfigurationProvider implements IDebugConfigurati config.host = defaultHost; } - sendTelemetryEvent(DEBUGGER_CONFIGURATION_PROMPTS, undefined, { configurationType: DebugConfigurationType.remoteAttach, manuallyEnteredAValue: config.host !== defaultHost }); + sendTelemetryEvent(EventName.DEBUGGER_CONFIGURATION_PROMPTS, undefined, { configurationType: DebugConfigurationType.remoteAttach, manuallyEnteredAValue: config.host !== defaultHost }); Object.assign(state.config, config); return _ => this.configurePort(input, state.config); } @@ -57,6 +57,6 @@ export class RemoteAttachDebugConfigurationProvider implements IDebugConfigurati if (!config.port) { config.port = defaultPort; } - sendTelemetryEvent(DEBUGGER_CONFIGURATION_PROMPTS, undefined, { configurationType: DebugConfigurationType.remoteAttach, manuallyEnteredAValue: config.port !== defaultPort }); + sendTelemetryEvent(EventName.DEBUGGER_CONFIGURATION_PROMPTS, undefined, { configurationType: DebugConfigurationType.remoteAttach, manuallyEnteredAValue: config.port !== defaultPort }); } } diff --git a/src/client/debugger/extension/configuration/resolvers/base.ts b/src/client/debugger/extension/configuration/resolvers/base.ts index dffff2e0c6f5..3e93c53bd1c7 100644 --- a/src/client/debugger/extension/configuration/resolvers/base.ts +++ b/src/client/debugger/extension/configuration/resolvers/base.ts @@ -12,7 +12,7 @@ import { IDocumentManager, IWorkspaceService } from '../../../../common/applicat import { PYTHON_LANGUAGE } from '../../../../common/constants'; import { IConfigurationService } from '../../../../common/types'; import { sendTelemetryEvent } from '../../../../telemetry'; -import { DEBUGGER } from '../../../../telemetry/constants'; +import { EventName } from '../../../../telemetry/constants'; import { DebuggerTelemetry } from '../../../../telemetry/types'; import { AttachRequestArguments, DebugOptions, LaunchRequestArguments } from '../../../types'; import { IDebugConfigurationResolver } from '../types'; @@ -92,7 +92,7 @@ export abstract class BaseConfigurationResolver im gevent: name.toLowerCase().indexOf('gevent') >= 0, scrapy: moduleName.toLowerCase() === 'scrapy' }; - sendTelemetryEvent(DEBUGGER, undefined, telemetryProps); + sendTelemetryEvent(EventName.DEBUGGER, undefined, telemetryProps); } } diff --git a/src/client/debugger/extension/hooks/childProcessAttachService.ts b/src/client/debugger/extension/hooks/childProcessAttachService.ts index 23f0db700b0a..e5558e2105c4 100644 --- a/src/client/debugger/extension/hooks/childProcessAttachService.ts +++ b/src/client/debugger/extension/hooks/childProcessAttachService.ts @@ -8,7 +8,7 @@ import { DebugConfiguration, WorkspaceFolder } from 'vscode'; import { IApplicationShell, IDebugService, IWorkspaceService } from '../../../common/application/types'; import { noop } from '../../../common/utils/misc'; import { captureTelemetry } from '../../../telemetry'; -import { DEBUGGER_ATTACH_TO_CHILD_PROCESS } from '../../../telemetry/constants'; +import { EventName } from '../../../telemetry/constants'; import { AttachRequestArguments } from '../../types'; import { ChildProcessLaunchData, IChildProcessAttachService } from './types'; @@ -25,7 +25,7 @@ export class ChildProcessAttachService implements IChildProcessAttachService { @inject(IDebugService) private readonly debugService: IDebugService, @inject(IWorkspaceService) private readonly workspaceService: IWorkspaceService) { } - @captureTelemetry(DEBUGGER_ATTACH_TO_CHILD_PROCESS) + @captureTelemetry(EventName.DEBUGGER_ATTACH_TO_CHILD_PROCESS) public async attach(data: ChildProcessLaunchData): Promise { const folder = this.getRelatedWorkspaceFolder(data); const debugConfig = this.getAttachConfiguration(data); diff --git a/src/client/extension.ts b/src/client/extension.ts index da2ffbc691ab..55fde0aa59cd 100644 --- a/src/client/extension.ts +++ b/src/client/extension.ts @@ -90,7 +90,7 @@ import { TerminalProvider } from './providers/terminalProvider'; import { ISortImportsEditingProvider } from './providers/types'; import { activateUpdateSparkLibraryProvider } from './providers/updateSparkLibraryProvider'; import { sendTelemetryEvent } from './telemetry'; -import { EDITOR_LOAD } from './telemetry/constants'; +import { EventName } from './telemetry/constants'; import { registerTypes as commonRegisterTerminalTypes } from './terminals/serviceRegistry'; import { ICodeExecutionManager, ITerminalAutoActivation } from './terminals/types'; import { TEST_OUTPUT_CHANNEL } from './unittests/common/constants'; @@ -306,7 +306,7 @@ async function sendStartupTelemetry(activatedPromise: Promise, serviceConta try { await activatedPromise; const props = await getActivationTelemetryProps(serviceContainer); - sendTelemetryEvent(EDITOR_LOAD, durations, props); + sendTelemetryEvent(EventName.EDITOR_LOAD, durations, props); } catch (ex) { traceError('sendStartupTelemetry() failed.', ex); } @@ -410,7 +410,7 @@ async function sendErrorTelemetry(ex: Error) { // ignore } } - sendTelemetryEvent(EDITOR_LOAD, durations, props, ex); + sendTelemetryEvent(EventName.EDITOR_LOAD, durations, props, ex); } catch (exc2) { traceError('sendErrorTelemetry() failed.', exc2); } diff --git a/src/client/formatters/autoPep8Formatter.ts b/src/client/formatters/autoPep8Formatter.ts index 15ef14a17859..c178f68c17e6 100644 --- a/src/client/formatters/autoPep8Formatter.ts +++ b/src/client/formatters/autoPep8Formatter.ts @@ -4,7 +4,7 @@ import { IConfigurationService } from '../common/types'; import { StopWatch } from '../common/utils/stopWatch'; import { IServiceContainer } from '../ioc/types'; import { sendTelemetryWhenDone } from '../telemetry'; -import { FORMAT } from '../telemetry/constants'; +import { EventName } from '../telemetry/constants'; import { BaseFormatter } from './baseFormatter'; export class AutoPep8Formatter extends BaseFormatter { @@ -24,7 +24,7 @@ export class AutoPep8Formatter extends BaseFormatter { autoPep8Args.push(...['--line-range', (range!.start.line + 1).toString(), (range!.end.line + 1).toString()]); } const promise = super.provideDocumentFormattingEdits(document, options, token, autoPep8Args); - sendTelemetryWhenDone(FORMAT, promise, stopWatch, { tool: 'autopep8', hasCustomArgs, formatSelection }); + sendTelemetryWhenDone(EventName.FORMAT, promise, stopWatch, { tool: 'autopep8', hasCustomArgs, formatSelection }); return promise; } } diff --git a/src/client/formatters/blackFormatter.ts b/src/client/formatters/blackFormatter.ts index e33a00a35e20..37853ec26131 100644 --- a/src/client/formatters/blackFormatter.ts +++ b/src/client/formatters/blackFormatter.ts @@ -9,7 +9,7 @@ import { IConfigurationService } from '../common/types'; import { StopWatch } from '../common/utils/stopWatch'; import { IServiceContainer } from '../ioc/types'; import { sendTelemetryWhenDone } from '../telemetry'; -import { FORMAT } from '../telemetry/constants'; +import { EventName } from '../telemetry/constants'; import { BaseFormatter } from './baseFormatter'; export class BlackFormatter extends BaseFormatter { @@ -35,7 +35,7 @@ export class BlackFormatter extends BaseFormatter { const blackArgs = ['--diff', '--quiet']; const promise = super.provideDocumentFormattingEdits(document, options, token, blackArgs); - sendTelemetryWhenDone(FORMAT, promise, stopWatch, { tool: 'black', hasCustomArgs, formatSelection }); + sendTelemetryWhenDone(EventName.FORMAT, promise, stopWatch, { tool: 'black', hasCustomArgs, formatSelection }); return promise; } } diff --git a/src/client/formatters/yapfFormatter.ts b/src/client/formatters/yapfFormatter.ts index 301bf4a9da87..f85b94ed090d 100644 --- a/src/client/formatters/yapfFormatter.ts +++ b/src/client/formatters/yapfFormatter.ts @@ -3,7 +3,7 @@ import { IConfigurationService, Product } from '../common/types'; import { StopWatch } from '../common/utils/stopWatch'; import { IServiceContainer } from '../ioc/types'; import { sendTelemetryWhenDone } from '../telemetry'; -import { FORMAT } from '../telemetry/constants'; +import { EventName } from '../telemetry/constants'; import { BaseFormatter } from './baseFormatter'; export class YapfFormatter extends BaseFormatter { @@ -26,7 +26,7 @@ export class YapfFormatter extends BaseFormatter { const fallbarFolder = this.getWorkspaceUri(document).fsPath; const cwd = this.getDocumentPath(document, fallbarFolder); const promise = super.provideDocumentFormattingEdits(document, options, token, yapfArgs, cwd); - sendTelemetryWhenDone(FORMAT, promise, stopWatch, { tool: 'yapf', hasCustomArgs, formatSelection }); + sendTelemetryWhenDone(EventName.FORMAT, promise, stopWatch, { tool: 'yapf', hasCustomArgs, formatSelection }); return promise; } } diff --git a/src/client/interpreter/activation/service.ts b/src/client/interpreter/activation/service.ts index ad4d2fe4d4f7..12cd63629b8d 100644 --- a/src/client/interpreter/activation/service.ts +++ b/src/client/interpreter/activation/service.ts @@ -20,7 +20,7 @@ import { OSType } from '../../common/utils/platform'; import { IEnvironmentVariablesProvider } from '../../common/variables/types'; import { EXTENSION_ROOT_DIR } from '../../constants'; import { captureTelemetry } from '../../telemetry'; -import { PYTHON_INTERPRETER_ACTIVATION_ENVIRONMENT_VARIABLES } from '../../telemetry/constants'; +import { EventName } from '../../telemetry/constants'; import { PythonInterpreter } from '../contracts'; import { IEnvironmentActivationService } from './types'; @@ -47,12 +47,12 @@ export class EnvironmentActivationService implements IEnvironmentActivationServi this.envVarsService.onDidEnvironmentVariablesChange(this.onDidEnvironmentVariablesChange, this, this.disposables); } - public dispose(): void | undefined { + public dispose(): void { this.disposables.forEach(d => d.dispose()); } @traceDecorators.verbose('getActivatedEnvironmentVariables', LogOptions.Arguments) @swallowExceptions('getActivatedEnvironmentVariables') - @captureTelemetry(PYTHON_INTERPRETER_ACTIVATION_ENVIRONMENT_VARIABLES, { failed: false }, true) + @captureTelemetry(EventName.PYTHON_INTERPRETER_ACTIVATION_ENVIRONMENT_VARIABLES, { failed: false }, true) @cacheResourceSpecificInterpreterData('ActivatedEnvironmentVariables', cacheDuration) public async getActivatedEnvironmentVariables(resource: Resource, interpreter?: PythonInterpreter): Promise { const shell = defaultShells[this.platform.osType]; diff --git a/src/client/interpreter/autoSelection/index.ts b/src/client/interpreter/autoSelection/index.ts index 5eb01586f83c..a380c9530f30 100644 --- a/src/client/interpreter/autoSelection/index.ts +++ b/src/client/interpreter/autoSelection/index.ts @@ -11,7 +11,7 @@ import '../../common/extensions'; import { IFileSystem } from '../../common/platform/types'; import { IPersistentState, IPersistentStateFactory, Resource } from '../../common/types'; import { captureTelemetry } from '../../telemetry'; -import { PYTHON_INTERPRETER_AUTO_SELECTION } from '../../telemetry/constants'; +import { EventName } from '../../telemetry/constants'; import { IInterpreterHelper, PythonInterpreter } from '../contracts'; import { AutoSelectionRule, IInterpreterAutoSelectionRule, IInterpreterAutoSelectionService, IInterpreterAutoSeletionProxyService } from './types'; @@ -63,7 +63,7 @@ export class InterpreterAutoSelectionService implements IInterpreterAutoSelectio currentPathInterpreter.setNextRule(winRegInterpreter); winRegInterpreter.setNextRule(systemInterpreter); } - @captureTelemetry(PYTHON_INTERPRETER_AUTO_SELECTION, { rule: AutoSelectionRule.all }, true) + @captureTelemetry(EventName.PYTHON_INTERPRETER_AUTO_SELECTION, { rule: AutoSelectionRule.all }, true) public async autoSelectInterpreter(resource: Resource): Promise { await this.initializeStore(); await this.userDefinedInterpreter.autoSelectInterpreter(resource, this); diff --git a/src/client/interpreter/autoSelection/rules/baseRule.ts b/src/client/interpreter/autoSelection/rules/baseRule.ts index 16ad9d49c12a..957f6d60acf1 100644 --- a/src/client/interpreter/autoSelection/rules/baseRule.ts +++ b/src/client/interpreter/autoSelection/rules/baseRule.ts @@ -11,7 +11,7 @@ import { IFileSystem } from '../../../common/platform/types'; import { IPersistentState, IPersistentStateFactory, Resource } from '../../../common/types'; import { StopWatch } from '../../../common/utils/stopWatch'; import { sendTelemetryEvent } from '../../../telemetry'; -import { PYTHON_INTERPRETER_AUTO_SELECTION } from '../../../telemetry/constants'; +import { EventName } from '../../../telemetry/constants'; import { PythonInterpreter } from '../../contracts'; import { AutoSelectionRule, IInterpreterAutoSelectionRule, IInterpreterAutoSelectionService } from '../types'; @@ -39,7 +39,7 @@ export abstract class BaseRuleService implements IInterpreterAutoSelectionRule { const action = await this.onAutoSelectInterpreter(resource, manager); traceVerbose(`Rule = ${this.ruleName}, result = ${action}`); const identified = action === NextAction.runNextRule; - sendTelemetryEvent(PYTHON_INTERPRETER_AUTO_SELECTION, { elapsedTime: stopWatch.elapsedTime }, { rule: this.ruleName, identified }); + sendTelemetryEvent(EventName.PYTHON_INTERPRETER_AUTO_SELECTION, { elapsedTime: stopWatch.elapsedTime }, { rule: this.ruleName, identified }); if (action === NextAction.runNextRule) { await this.next(resource, manager); } @@ -72,14 +72,14 @@ export abstract class BaseRuleService implements IInterpreterAutoSelectionRule { if (!this.stateStore.value || await this.fs.fileExists(this.stateStore.value.path)) { return; } - sendTelemetryEvent(PYTHON_INTERPRETER_AUTO_SELECTION, {}, { rule: this.ruleName, interpreterMissing: true }); + sendTelemetryEvent(EventName.PYTHON_INTERPRETER_AUTO_SELECTION, {}, { rule: this.ruleName, interpreterMissing: true }); await this.cacheSelectedInterpreter(resource, undefined); } protected async cacheSelectedInterpreter(_resource: Resource, interpreter: PythonInterpreter | undefined) { const interpreterPath = interpreter ? interpreter.path : ''; const interpreterPathInCache = this.stateStore.value ? this.stateStore.value.path : ''; const updated = interpreterPath === interpreterPathInCache; - sendTelemetryEvent(PYTHON_INTERPRETER_AUTO_SELECTION, {}, { rule: this.ruleName, updated }); + sendTelemetryEvent(EventName.PYTHON_INTERPRETER_AUTO_SELECTION, {}, { rule: this.ruleName, updated }); await this.stateStore.updateValue(interpreter); } protected async next(resource: Resource, manager?: IInterpreterAutoSelectionService): Promise { diff --git a/src/client/interpreter/configuration/pythonPathUpdaterService.ts b/src/client/interpreter/configuration/pythonPathUpdaterService.ts index 13f5210d9c93..bedc8702083b 100644 --- a/src/client/interpreter/configuration/pythonPathUpdaterService.ts +++ b/src/client/interpreter/configuration/pythonPathUpdaterService.ts @@ -5,7 +5,7 @@ import { InterpreterInfomation, IPythonExecutionFactory } from '../../common/pro import { StopWatch } from '../../common/utils/stopWatch'; import { IServiceContainer } from '../../ioc/types'; import { sendTelemetryEvent } from '../../telemetry'; -import { PYTHON_INTERPRETER } from '../../telemetry/constants'; +import { EventName } from '../../telemetry/constants'; import { PythonInterpreterTelemetry } from '../../telemetry/types'; import { IInterpreterVersionService } from '../contracts'; import { IPythonPathUpdaterServiceFactory, IPythonPathUpdaterServiceManager } from './types'; @@ -56,7 +56,7 @@ export class PythonPathUpdaterService implements IPythonPathUpdaterServiceManage telemtryProperties.pipVersion = pipVersion; } } - sendTelemetryEvent(PYTHON_INTERPRETER, duration, telemtryProperties); + sendTelemetryEvent(EventName.PYTHON_INTERPRETER, duration, telemtryProperties); } private getPythonUpdaterService(configTarget: ConfigurationTarget, wkspace?: Uri) { switch (configTarget) { diff --git a/src/client/interpreter/interpreterService.ts b/src/client/interpreter/interpreterService.ts index 644616d90143..b1eb7e758024 100644 --- a/src/client/interpreter/interpreterService.ts +++ b/src/client/interpreter/interpreterService.ts @@ -10,7 +10,7 @@ import { IConfigurationService, IDisposableRegistry, IPersistentStateFactory } f import { sleep } from '../common/utils/async'; import { IServiceContainer } from '../ioc/types'; import { captureTelemetry } from '../telemetry'; -import { PYTHON_INTERPRETER_DISCOVERY } from '../telemetry/constants'; +import { EventName } from '../telemetry/constants'; import { IInterpreterDisplay, IInterpreterHelper, IInterpreterLocatorService, IInterpreterService, INTERPRETER_LOCATOR_SERVICE, @@ -58,7 +58,7 @@ export class InterpreterService implements Disposable, IInterpreterService { disposables.push(disposable); } - @captureTelemetry(PYTHON_INTERPRETER_DISCOVERY, { locator: 'all' }, true) + @captureTelemetry(EventName.PYTHON_INTERPRETER_DISCOVERY, { locator: 'all' }, true) public async getInterpreters(resource?: Uri): Promise { const interpreters = await this.locator.getInterpreters(resource); await Promise.all(interpreters diff --git a/src/client/interpreter/locators/services/cacheableLocatorService.ts b/src/client/interpreter/locators/services/cacheableLocatorService.ts index 1d69dfa32817..f592837e9a6e 100644 --- a/src/client/interpreter/locators/services/cacheableLocatorService.ts +++ b/src/client/interpreter/locators/services/cacheableLocatorService.ts @@ -13,7 +13,7 @@ import { IDisposableRegistry, IPersistentStateFactory } from '../../../common/ty import { createDeferred, Deferred } from '../../../common/utils/async'; import { IServiceContainer } from '../../../ioc/types'; import { sendTelemetryWhenDone } from '../../../telemetry'; -import { PYTHON_INTERPRETER_DISCOVERY } from '../../../telemetry/constants'; +import { EventName } from '../../../telemetry/constants'; import { IInterpreterLocatorService, IInterpreterWatcher, PythonInterpreter } from '../../contracts'; @injectable() @@ -55,7 +55,7 @@ export abstract class CacheableLocatorService implements IInterpreterLocatorServ }) .catch(ex => deferred!.reject(ex)); - sendTelemetryWhenDone(PYTHON_INTERPRETER_DISCOVERY, promise, undefined, { locator: this.name }); + sendTelemetryWhenDone(EventName.PYTHON_INTERPRETER_DISCOVERY, promise, undefined, { locator: this.name }); this.locating.fire(deferred.promise); } deferred.promise diff --git a/src/client/linters/linterCommands.ts b/src/client/linters/linterCommands.ts index 3c2a6dcfd664..62756c818f06 100644 --- a/src/client/linters/linterCommands.ts +++ b/src/client/linters/linterCommands.ts @@ -9,7 +9,7 @@ import { IDisposable } from '../common/types'; import { Linters } from '../common/utils/localize'; import { IServiceContainer } from '../ioc/types'; import { sendTelemetryEvent } from '../telemetry'; -import { SELECT_LINTER } from '../telemetry/constants'; +import { EventName } from '../telemetry/constants'; import { ILinterManager, ILintingEngine, LinterId } from './types'; export class LinterCommands implements IDisposable { @@ -61,7 +61,7 @@ export class LinterCommands implements IDisposable { if (selection !== undefined) { if (selection === 'Disable Linting'){ await this.linterManager.enableLintingAsync(false); - sendTelemetryEvent(SELECT_LINTER, undefined, {enabled: false}); + sendTelemetryEvent(EventName.SELECT_LINTER, undefined, {enabled: false}); } else{ const index = linters.findIndex(x => x.id === selection); if (activeLinters.length > 1) { @@ -71,7 +71,7 @@ export class LinterCommands implements IDisposable { } } await this.linterManager.setActiveLintersAsync([linters[index].product], this.settingsUri); - sendTelemetryEvent(SELECT_LINTER, undefined, {tool: selection as LinterId, enabled: true}); + sendTelemetryEvent(EventName.SELECT_LINTER, undefined, {tool: selection as LinterId, enabled: true}); } } } diff --git a/src/client/linters/lintingEngine.ts b/src/client/linters/lintingEngine.ts index 066080250e7d..2f67560dd267 100644 --- a/src/client/linters/lintingEngine.ts +++ b/src/client/linters/lintingEngine.ts @@ -15,7 +15,7 @@ import { StopWatch } from '../common/utils/stopWatch'; import { IServiceContainer } from '../ioc/types'; import { JupyterProvider } from '../jupyter/provider'; import { sendTelemetryWhenDone } from '../telemetry'; -import { LINTING } from '../telemetry/constants'; +import { EventName } from '../telemetry/constants'; import { LinterTrigger, LintingTelemetry } from '../telemetry/types'; import { ILinterInfo, ILinterManager, ILintingEngine, ILintMessage, LintMessageSeverity } from './types'; @@ -164,7 +164,7 @@ export class LintingEngine implements ILintingEngine { trigger, executableSpecified: linterExecutablePathName.length > 0 }; - sendTelemetryWhenDone(LINTING, promise, stopWatch, properties); + sendTelemetryWhenDone(EventName.LINTING, promise, stopWatch, properties); } private isDocumentOpen(uri: vscode.Uri): boolean { diff --git a/src/client/providers/completionProvider.ts b/src/client/providers/completionProvider.ts index 89c89f732091..aa9099b6a401 100644 --- a/src/client/providers/completionProvider.ts +++ b/src/client/providers/completionProvider.ts @@ -5,7 +5,7 @@ import { IConfigurationService } from '../common/types'; import { IServiceContainer } from '../ioc/types'; import { JediFactory } from '../languageServices/jediProxyFactory'; import { captureTelemetry } from '../telemetry'; -import { COMPLETION } from '../telemetry/constants'; +import { EventName } from '../telemetry/constants'; import { CompletionSource } from './completionSource'; import { ItemInfoSource } from './itemInfoSource'; @@ -18,7 +18,7 @@ export class PythonCompletionItemProvider implements vscode.CompletionItemProvid this.configService = serviceContainer.get(IConfigurationService); } - @captureTelemetry(COMPLETION) + @captureTelemetry(EventName.COMPLETION) public async provideCompletionItems(document: vscode.TextDocument, position: vscode.Position, token: vscode.CancellationToken): Promise { const items = await this.completionSource.getVsCodeCompletionItems(document, position, token); diff --git a/src/client/providers/definitionProvider.ts b/src/client/providers/definitionProvider.ts index f1555e58b9fc..cd87d8ec1087 100644 --- a/src/client/providers/definitionProvider.ts +++ b/src/client/providers/definitionProvider.ts @@ -3,7 +3,7 @@ import * as vscode from 'vscode'; import { JediFactory } from '../languageServices/jediProxyFactory'; import { captureTelemetry } from '../telemetry'; -import { DEFINITION } from '../telemetry/constants'; +import { EventName } from '../telemetry/constants'; import * as proxy from './jediProxy'; export class PythonDefinitionProvider implements vscode.DefinitionProvider { @@ -19,7 +19,7 @@ export class PythonDefinitionProvider implements vscode.DefinitionProvider { return new vscode.Location(definitionResource, range); } } - @captureTelemetry(DEFINITION) + @captureTelemetry(EventName.DEFINITION) public async provideDefinition(document: vscode.TextDocument, position: vscode.Position, token: vscode.CancellationToken): Promise { const filename = document.fileName; if (document.lineAt(position.line).text.match(/^\s*\/\//)) { diff --git a/src/client/providers/hoverProvider.ts b/src/client/providers/hoverProvider.ts index 745300986189..a7e07ea6337e 100644 --- a/src/client/providers/hoverProvider.ts +++ b/src/client/providers/hoverProvider.ts @@ -3,7 +3,7 @@ import * as vscode from 'vscode'; import { JediFactory } from '../languageServices/jediProxyFactory'; import { captureTelemetry } from '../telemetry'; -import { HOVER_DEFINITION } from '../telemetry/constants'; +import { EventName } from '../telemetry/constants'; import { ItemInfoSource } from './itemInfoSource'; export class PythonHoverProvider implements vscode.HoverProvider { @@ -13,7 +13,7 @@ export class PythonHoverProvider implements vscode.HoverProvider { this.itemInfoSource = new ItemInfoSource(jediFactory); } - @captureTelemetry(HOVER_DEFINITION) + @captureTelemetry(EventName.HOVER_DEFINITION) public async provideHover(document: vscode.TextDocument, position: vscode.Position, token: vscode.CancellationToken) : Promise { const itemInfos = await this.itemInfoSource.getItemInfoFromDocument(document, position, token); diff --git a/src/client/providers/importSortProvider.ts b/src/client/providers/importSortProvider.ts index 394ec631f853..10ce7dddec65 100644 --- a/src/client/providers/importSortProvider.ts +++ b/src/client/providers/importSortProvider.ts @@ -10,7 +10,7 @@ import { IConfigurationService, IDisposableRegistry, IEditorUtils, ILogger, IOut import { noop } from '../common/utils/misc'; import { IServiceContainer } from '../ioc/types'; import { captureTelemetry } from '../telemetry'; -import { FORMAT_SORT_IMPORTS } from '../telemetry/constants'; +import { EventName } from '../telemetry/constants'; import { ISortImportsEditingProvider } from './types'; @injectable() @@ -29,7 +29,7 @@ export class SortImportsEditingProvider implements ISortImportsEditingProvider { this.processServiceFactory = serviceContainer.get(IProcessServiceFactory); this.editorUtils = serviceContainer.get(IEditorUtils); } - @captureTelemetry(FORMAT_SORT_IMPORTS) + @captureTelemetry(EventName.FORMAT_SORT_IMPORTS) public async provideDocumentSortImportsEdits(uri: Uri, token?: CancellationToken): Promise { const document = await this.documentManager.openTextDocument(uri); if (!document) { diff --git a/src/client/providers/objectDefinitionProvider.ts b/src/client/providers/objectDefinitionProvider.ts index 6742d2de9787..3eafdef6bfeb 100644 --- a/src/client/providers/objectDefinitionProvider.ts +++ b/src/client/providers/objectDefinitionProvider.ts @@ -3,42 +3,36 @@ import * as vscode from 'vscode'; import { JediFactory } from '../languageServices/jediProxyFactory'; import { captureTelemetry } from '../telemetry'; -import { GO_TO_OBJECT_DEFINITION } from '../telemetry/constants'; +import { EventName } from '../telemetry/constants'; import * as defProvider from './definitionProvider'; -export function activateGoToObjectDefinitionProvider(jediFactory: JediFactory): vscode.Disposable[] { - const def = new PythonObjectDefinitionProvider(jediFactory); - const commandRegistration = vscode.commands.registerCommand("python.goToPythonObject", () => def.goToObjectDefinition()); - return [def, commandRegistration] as vscode.Disposable[]; -} - export class PythonObjectDefinitionProvider { private readonly _defProvider: defProvider.PythonDefinitionProvider; public constructor(jediFactory: JediFactory) { this._defProvider = new defProvider.PythonDefinitionProvider(jediFactory); } - @captureTelemetry(GO_TO_OBJECT_DEFINITION) + @captureTelemetry(EventName.GO_TO_OBJECT_DEFINITION) public async goToObjectDefinition() { - let pathDef = await this.getObjectDefinition(); + const pathDef = await this.getObjectDefinition(); if (typeof pathDef !== 'string' || pathDef.length === 0) { return; } - let parts = pathDef.split('.'); + const parts = pathDef.split('.'); let source = ''; let startColumn = 0; if (parts.length === 1) { source = `import ${parts[0]}`; startColumn = 'import '.length; - } - else { - let mod = parts.shift(); + } else { + const mod = parts.shift(); source = `from ${mod} import ${parts.join('.')}`; startColumn = `from ${mod} import `.length; } const range = new vscode.Range(0, startColumn, 0, source.length - 1); - let doc = { + // tslint:disable-next-line:no-any + const doc = { fileName: 'test.py', lineAt: (line: number) => { return { text: source }; @@ -48,31 +42,30 @@ export class PythonObjectDefinitionProvider { getText: () => source }; - let tokenSource = new vscode.CancellationTokenSource(); - let defs = await this._defProvider.provideDefinition(doc, range.start, tokenSource.token); + const tokenSource = new vscode.CancellationTokenSource(); + const defs = await this._defProvider.provideDefinition(doc, range.start, tokenSource.token); if (defs === null) { await vscode.window.showInformationMessage(`Definition not found for '${pathDef}'`); return; } - let uri: vscode.Uri; + let uri: vscode.Uri | undefined; let lineNumber: number; if (Array.isArray(defs) && defs.length > 0) { uri = defs[0].uri; lineNumber = defs[0].range.start.line; } - if (!Array.isArray(defs) && defs.uri) { + if (defs && !Array.isArray(defs) && defs.uri) { uri = defs.uri; lineNumber = defs.range.start.line; } if (uri) { - let doc = await vscode.workspace.openTextDocument(uri); - await vscode.window.showTextDocument(doc); - await vscode.commands.executeCommand('revealLine', { lineNumber: lineNumber, 'at': 'top' }); - } - else { + const openedDoc = await vscode.workspace.openTextDocument(uri); + await vscode.window.showTextDocument(openedDoc); + await vscode.commands.executeCommand('revealLine', { lineNumber: lineNumber!, at: 'top' }); + } else { await vscode.window.showInformationMessage(`Definition not found for '${pathDef}'`); } } @@ -88,8 +81,13 @@ export class PythonObjectDefinitionProvider { return null; } - private async getObjectDefinition(): Promise { - let value = await vscode.window.showInputBox({ prompt: "Enter Object Path", validateInput: this.intputValidation }); - return value; + private async getObjectDefinition(): Promise { + return vscode.window.showInputBox({ prompt: 'Enter Object Path', validateInput: this.intputValidation }); } } + +export function activateGoToObjectDefinitionProvider(jediFactory: JediFactory): vscode.Disposable[] { + const def = new PythonObjectDefinitionProvider(jediFactory); + const commandRegistration = vscode.commands.registerCommand('python.goToPythonObject', () => def.goToObjectDefinition()); + return [def, commandRegistration] as vscode.Disposable[]; +} diff --git a/src/client/providers/referenceProvider.ts b/src/client/providers/referenceProvider.ts index c57e35e0299b..c42125808608 100644 --- a/src/client/providers/referenceProvider.ts +++ b/src/client/providers/referenceProvider.ts @@ -3,7 +3,7 @@ import * as vscode from 'vscode'; import { JediFactory } from '../languageServices/jediProxyFactory'; import { captureTelemetry } from '../telemetry'; -import { REFERENCE } from '../telemetry/constants'; +import { EventName } from '../telemetry/constants'; import * as proxy from './jediProxy'; export class PythonReferenceProvider implements vscode.ReferenceProvider { @@ -29,7 +29,7 @@ export class PythonReferenceProvider implements vscode.ReferenceProvider { return []; } - @captureTelemetry(REFERENCE) + @captureTelemetry(EventName.REFERENCE) public async provideReferences(document: vscode.TextDocument, position: vscode.Position, _context: vscode.ReferenceContext, token: vscode.CancellationToken): Promise { const filename = document.fileName; if (document.lineAt(position.line).text.match(/^\s*\/\//)) { diff --git a/src/client/providers/renameProvider.ts b/src/client/providers/renameProvider.ts index adf9a62f9093..0cc79b5547a1 100644 --- a/src/client/providers/renameProvider.ts +++ b/src/client/providers/renameProvider.ts @@ -9,7 +9,7 @@ import { IConfigurationService, IInstaller, IOutputChannel, Product } from '../c import { IServiceContainer } from '../ioc/types'; import { RefactorProxy } from '../refactor/proxy'; import { captureTelemetry } from '../telemetry'; -import { REFACTOR_RENAME } from '../telemetry/constants'; +import { EventName } from '../telemetry/constants'; type RenameResponse = { results: [{ diff: string }]; @@ -22,7 +22,7 @@ export class PythonRenameProvider implements RenameProvider { this.outputChannel = serviceContainer.get(IOutputChannel, STANDARD_OUTPUT_CHANNEL); this.configurationService = serviceContainer.get(IConfigurationService); } - @captureTelemetry(REFACTOR_RENAME) + @captureTelemetry(EventName.REFACTOR_RENAME) public provideRenameEdits(document: TextDocument, position: Position, newName: string, token: CancellationToken): ProviderResult { return workspace.saveAll(false).then(() => { return this.doRename(document, position, newName, token); diff --git a/src/client/providers/replProvider.ts b/src/client/providers/replProvider.ts index ddde0fea33ce..b31d274b9015 100644 --- a/src/client/providers/replProvider.ts +++ b/src/client/providers/replProvider.ts @@ -3,7 +3,7 @@ import { ICommandManager, IDocumentManager, IWorkspaceService } from '../common/ import { Commands } from '../common/constants'; import { IServiceContainer } from '../ioc/types'; import { captureTelemetry } from '../telemetry'; -import { REPL } from '../telemetry/constants'; +import { EventName } from '../telemetry/constants'; import { ICodeExecutionService } from '../terminals/types'; export class ReplProvider implements Disposable { @@ -19,7 +19,7 @@ export class ReplProvider implements Disposable { const disposable = commandManager.registerCommand(Commands.Start_REPL, this.commandHandler, this); this.disposables.push(disposable); } - @captureTelemetry(REPL) + @captureTelemetry(EventName.REPL) private async commandHandler() { const resource = this.getActiveResourceUri(); const replProvider = this.serviceContainer.get(ICodeExecutionService, 'repl'); diff --git a/src/client/providers/signatureProvider.ts b/src/client/providers/signatureProvider.ts index f6ea0d65fd6e..3d6cd6e94b16 100644 --- a/src/client/providers/signatureProvider.ts +++ b/src/client/providers/signatureProvider.ts @@ -12,7 +12,7 @@ import { } from 'vscode'; import { JediFactory } from '../languageServices/jediProxyFactory'; import { captureTelemetry } from '../telemetry'; -import { SIGNATURE } from '../telemetry/constants'; +import { EventName } from '../telemetry/constants'; import * as proxy from './jediProxy'; import { isPositionInsideStringOrComment } from './providerUtilities'; @@ -110,7 +110,7 @@ export class PythonSignatureProvider implements SignatureHelpProvider { return new SignatureHelp(); } - @captureTelemetry(SIGNATURE) + @captureTelemetry(EventName.SIGNATURE) public provideSignatureHelp(document: TextDocument, position: Position, token: CancellationToken): Thenable { // early exit if we're in a string or comment (or in an undefined position) if (position.character <= 0 || diff --git a/src/client/providers/simpleRefactorProvider.ts b/src/client/providers/simpleRefactorProvider.ts index 28260841a49e..5952f7e9d6eb 100644 --- a/src/client/providers/simpleRefactorProvider.ts +++ b/src/client/providers/simpleRefactorProvider.ts @@ -5,7 +5,7 @@ import { StopWatch } from '../common/utils/stopWatch'; import { IServiceContainer } from '../ioc/types'; import { RefactorProxy } from '../refactor/proxy'; import { sendTelemetryWhenDone } from '../telemetry'; -import { REFACTOR_EXTRACT_FUNCTION, REFACTOR_EXTRACT_VAR } from '../telemetry/constants'; +import { EventName } from '../telemetry/constants'; type RenameResponse = { results: [{ diff: string }]; @@ -22,7 +22,7 @@ export function activateSimplePythonRefactorProvider(context: vscode.ExtensionCo vscode.window.activeTextEditor!.selection, // tslint:disable-next-line:no-empty outputChannel, serviceContainer).catch(() => { }); - sendTelemetryWhenDone(REFACTOR_EXTRACT_VAR, promise, stopWatch); + sendTelemetryWhenDone(EventName.REFACTOR_EXTRACT_VAR, promise, stopWatch); }); context.subscriptions.push(disposable); @@ -33,7 +33,7 @@ export function activateSimplePythonRefactorProvider(context: vscode.ExtensionCo vscode.window.activeTextEditor!.selection, // tslint:disable-next-line:no-empty outputChannel, serviceContainer).catch(() => { }); - sendTelemetryWhenDone(REFACTOR_EXTRACT_FUNCTION, promise, stopWatch); + sendTelemetryWhenDone(EventName.REFACTOR_EXTRACT_FUNCTION, promise, stopWatch); }); context.subscriptions.push(disposable); } diff --git a/src/client/providers/symbolProvider.ts b/src/client/providers/symbolProvider.ts index 89c724644fd8..9de9d0108016 100644 --- a/src/client/providers/symbolProvider.ts +++ b/src/client/providers/symbolProvider.ts @@ -10,7 +10,7 @@ import { createDeferred, Deferred } from '../common/utils/async'; import { IServiceContainer } from '../ioc/types'; import { JediFactory } from '../languageServices/jediProxyFactory'; import { captureTelemetry } from '../telemetry'; -import { SYMBOL } from '../telemetry/constants'; +import { EventName } from '../telemetry/constants'; import * as proxy from './jediProxy'; function flattenSymbolTree(tree: DocumentSymbol, uri: Uri, containerName: string = ''): SymbolInformation[] { @@ -92,7 +92,7 @@ export class JediSymbolProvider implements DocumentSymbolProvider { this.fs = serviceContainer.get(IFileSystem); } - @captureTelemetry(SYMBOL) + @captureTelemetry(EventName.SYMBOL) public provideDocumentSymbols(document: TextDocument, token: CancellationToken): Thenable { return this.provideDocumentSymbolsThrottled(document, token); } diff --git a/src/client/providers/terminalProvider.ts b/src/client/providers/terminalProvider.ts index 87d60070e328..b4bc02e9c3b2 100644 --- a/src/client/providers/terminalProvider.ts +++ b/src/client/providers/terminalProvider.ts @@ -7,7 +7,7 @@ import { Commands } from '../common/constants'; import { ITerminalServiceFactory } from '../common/terminal/types'; import { IServiceContainer } from '../ioc/types'; import { captureTelemetry } from '../telemetry'; -import { TERMINAL_CREATE } from '../telemetry/constants'; +import { EventName } from '../telemetry/constants'; export class TerminalProvider implements Disposable { private disposables: Disposable[] = []; @@ -23,7 +23,7 @@ export class TerminalProvider implements Disposable { this.disposables.push(disposable); } - @captureTelemetry(TERMINAL_CREATE, { triggeredBy: 'commandpalette' }) + @captureTelemetry(EventName.TERMINAL_CREATE, { triggeredBy: 'commandpalette' }) private async onCreateTerminal() { const terminalService = this.serviceContainer.get(ITerminalServiceFactory); const activeResource = this.getActiveResource(); diff --git a/src/client/providers/updateSparkLibraryProvider.ts b/src/client/providers/updateSparkLibraryProvider.ts index 935e5082a2e1..f8d4b1a8c278 100644 --- a/src/client/providers/updateSparkLibraryProvider.ts +++ b/src/client/providers/updateSparkLibraryProvider.ts @@ -3,7 +3,7 @@ import * as path from 'path'; import * as vscode from 'vscode'; import { Commands } from '../common/constants'; import { sendTelemetryEvent } from '../telemetry'; -import { UPDATE_PYSPARK_LIBRARY } from '../telemetry/constants'; +import { EventName } from '../telemetry/constants'; export function activateUpdateSparkLibraryProvider(): vscode.Disposable { return vscode.commands.registerCommand(Commands.Update_SparkLibrary, updateSparkLibrary); @@ -22,5 +22,5 @@ function updateSparkLibrary() { console.error(reason); }); vscode.window.showInformationMessage('Make sure you have SPARK_HOME environment variable set to the root path of the local spark installation!'); - sendTelemetryEvent(UPDATE_PYSPARK_LIBRARY); + sendTelemetryEvent(EventName.UPDATE_PYSPARK_LIBRARY); } diff --git a/src/client/telemetry/constants.ts b/src/client/telemetry/constants.ts index 61b61107a785..b970c155d1b5 100644 --- a/src/client/telemetry/constants.ts +++ b/src/client/telemetry/constants.ts @@ -3,62 +3,64 @@ 'use strict'; -export const COMPLETION = 'COMPLETION'; -export const COMPLETION_ADD_BRACKETS = 'COMPLETION.ADD_BRACKETS'; -export const DEFINITION = 'DEFINITION'; -export const HOVER_DEFINITION = 'HOVER_DEFINITION'; -export const REFERENCE = 'REFERENCE'; -export const SIGNATURE = 'SIGNATURE'; -export const SYMBOL = 'SYMBOL'; -export const FORMAT_SORT_IMPORTS = 'FORMAT.SORT_IMPORTS'; -export const FORMAT = 'FORMAT.FORMAT'; -export const FORMAT_ON_TYPE = 'FORMAT.FORMAT_ON_TYPE'; -export const EDITOR_LOAD = 'EDITOR.LOAD'; -export const LINTING = 'LINTING'; -export const GO_TO_OBJECT_DEFINITION = 'GO_TO_OBJECT_DEFINITION'; -export const UPDATE_PYSPARK_LIBRARY = 'UPDATE_PYSPARK_LIBRARY'; -export const REFACTOR_RENAME = 'REFACTOR_RENAME'; -export const REFACTOR_EXTRACT_VAR = 'REFACTOR_EXTRACT_VAR'; -export const REFACTOR_EXTRACT_FUNCTION = 'REFACTOR_EXTRACT_FUNCTION'; -export const REPL = 'REPL'; -export const PYTHON_INTERPRETER = 'PYTHON_INTERPRETER'; -export const PYTHON_INTERPRETER_DISCOVERY = 'PYTHON_INTERPRETER_DISCOVERY'; -export const PYTHON_INTERPRETER_AUTO_SELECTION = 'PYTHON_INTERPRETER_AUTO_SELECTION'; -export const PYTHON_INTERPRETER_ACTIVATION_ENVIRONMENT_VARIABLES = 'PYTHON_INTERPRETER_ACTIVATION_ENVIRONMENT_VARIABLES'; -export const PYTHON_INTERPRETER_ACTIVATION_FOR_RUNNING_CODE = 'PYTHON_INTERPRETER_ACTIVATION_FOR_RUNNING_CODE'; -export const PYTHON_INTERPRETER_ACTIVATION_FOR_TERMINAL = 'PYTHON_INTERPRETER_ACTIVATION_FOR_TERMINAL'; -export const WORKSPACE_SYMBOLS_BUILD = 'WORKSPACE_SYMBOLS.BUILD'; -export const WORKSPACE_SYMBOLS_GO_TO = 'WORKSPACE_SYMBOLS.GO_TO'; -export const EXECUTION_CODE = 'EXECUTION_CODE'; -export const EXECUTION_DJANGO = 'EXECUTION_DJANGO'; -export const DEBUGGER = 'DEBUGGER'; -export const DEBUGGER_ATTACH_TO_CHILD_PROCESS = 'DEBUGGER.ATTACH_TO_CHILD_PROCESS'; -export const DEBUGGER_PERFORMANCE = 'DEBUGGER.PERFORMANCE'; -export const DEBUGGER_CONFIGURATION_PROMPTS = 'DEBUGGER.CONFIGURATION.PROMPTS'; -export const UNITTEST_STOP = 'UNITTEST.STOP'; -export const UNITTEST_RUN = 'UNITTEST.RUN'; -export const UNITTEST_DISCOVER = 'UNITTEST.DISCOVER'; -export const UNITTEST_VIEW_OUTPUT = 'UNITTEST.VIEW_OUTPUT'; -export const PYTHON_LANGUAGE_SERVER_ANALYSISTIME = 'PYTHON_LANGUAGE_SERVER.ANALYSIS_TIME'; -export const PYTHON_LANGUAGE_SERVER_ENABLED = 'PYTHON_LANGUAGE_SERVER.ENABLED'; -export const PYTHON_LANGUAGE_SERVER_EXTRACTED = 'PYTHON_LANGUAGE_SERVER.EXTRACTED'; -export const PYTHON_LANGUAGE_SERVER_DOWNLOADED = 'PYTHON_LANGUAGE_SERVER.DOWNLOADED'; -export const PYTHON_LANGUAGE_SERVER_ERROR = 'PYTHON_LANGUAGE_SERVER.ERROR'; -export const PYTHON_LANGUAGE_SERVER_STARTUP = 'PYTHON_LANGUAGE_SERVER.STARTUP'; -export const PYTHON_LANGUAGE_SERVER_READY = 'PYTHON_LANGUAGE_SERVER.READY'; -export const PYTHON_LANGUAGE_SERVER_PLATFORM_NOT_SUPPORTED = 'PYTHON_LANGUAGE_SERVER.PLATFORM_NOT_SUPPORTED'; -export const PYTHON_LANGUAGE_SERVER_PLATFORM_SUPPORTED = 'PYTHON_LANGUAGE_SERVER.PLATFORM_SUPPORTED'; -export const PYTHON_LANGUAGE_SERVER_TELEMETRY = 'PYTHON_LANGUAGE_SERVER.EVENT'; +export enum EventName { + COMPLETION = 'COMPLETION', + COMPLETION_ADD_BRACKETS = 'COMPLETION.ADD_BRACKETS', + DEFINITION = 'DEFINITION', + HOVER_DEFINITION = 'HOVER_DEFINITION', + REFERENCE = 'REFERENCE', + SIGNATURE = 'SIGNATURE', + SYMBOL = 'SYMBOL', + FORMAT_SORT_IMPORTS = 'FORMAT.SORT_IMPORTS', + FORMAT = 'FORMAT.FORMAT', + FORMAT_ON_TYPE = 'FORMAT.FORMAT_ON_TYPE', + EDITOR_LOAD = 'EDITOR.LOAD', + LINTING = 'LINTING', + GO_TO_OBJECT_DEFINITION = 'GO_TO_OBJECT_DEFINITION', + UPDATE_PYSPARK_LIBRARY = 'UPDATE_PYSPARK_LIBRARY', + REFACTOR_RENAME = 'REFACTOR_RENAME', + REFACTOR_EXTRACT_VAR = 'REFACTOR_EXTRACT_VAR', + REFACTOR_EXTRACT_FUNCTION = 'REFACTOR_EXTRACT_FUNCTION', + REPL = 'REPL', + PYTHON_INTERPRETER = 'PYTHON_INTERPRETER', + PYTHON_INTERPRETER_DISCOVERY = 'PYTHON_INTERPRETER_DISCOVERY', + PYTHON_INTERPRETER_AUTO_SELECTION = 'PYTHON_INTERPRETER_AUTO_SELECTION', + PYTHON_INTERPRETER_ACTIVATION_ENVIRONMENT_VARIABLES = 'PYTHON_INTERPRETER_ACTIVATION_ENVIRONMENT_VARIABLES', + PYTHON_INTERPRETER_ACTIVATION_FOR_RUNNING_CODE = 'PYTHON_INTERPRETER_ACTIVATION_FOR_RUNNING_CODE', + PYTHON_INTERPRETER_ACTIVATION_FOR_TERMINAL = 'PYTHON_INTERPRETER_ACTIVATION_FOR_TERMINAL', + WORKSPACE_SYMBOLS_BUILD = 'WORKSPACE_SYMBOLS.BUILD', + WORKSPACE_SYMBOLS_GO_TO = 'WORKSPACE_SYMBOLS.GO_TO', + EXECUTION_CODE = 'EXECUTION_CODE', + EXECUTION_DJANGO = 'EXECUTION_DJANGO', + DEBUGGER = 'DEBUGGER', + DEBUGGER_ATTACH_TO_CHILD_PROCESS = 'DEBUGGER.ATTACH_TO_CHILD_PROCESS', + DEBUGGER_PERFORMANCE = 'DEBUGGER.PERFORMANCE', + DEBUGGER_CONFIGURATION_PROMPTS = 'DEBUGGER.CONFIGURATION.PROMPTS', + UNITTEST_STOP = 'UNITTEST.STOP', + UNITTEST_RUN = 'UNITTEST.RUN', + UNITTEST_DISCOVER = 'UNITTEST.DISCOVER', + UNITTEST_VIEW_OUTPUT = 'UNITTEST.VIEW_OUTPUT', + PYTHON_LANGUAGE_SERVER_ANALYSISTIME = 'PYTHON_LANGUAGE_SERVER.ANALYSIS_TIME', + PYTHON_LANGUAGE_SERVER_ENABLED = 'PYTHON_LANGUAGE_SERVER.ENABLED', + PYTHON_LANGUAGE_SERVER_EXTRACTED = 'PYTHON_LANGUAGE_SERVER.EXTRACTED', + PYTHON_LANGUAGE_SERVER_DOWNLOADED = 'PYTHON_LANGUAGE_SERVER.DOWNLOADED', + PYTHON_LANGUAGE_SERVER_ERROR = 'PYTHON_LANGUAGE_SERVER.ERROR', + PYTHON_LANGUAGE_SERVER_STARTUP = 'PYTHON_LANGUAGE_SERVER.STARTUP', + PYTHON_LANGUAGE_SERVER_READY = 'PYTHON_LANGUAGE_SERVER.READY', + PYTHON_LANGUAGE_SERVER_PLATFORM_NOT_SUPPORTED = 'PYTHON_LANGUAGE_SERVER.PLATFORM_NOT_SUPPORTED', + PYTHON_LANGUAGE_SERVER_PLATFORM_SUPPORTED = 'PYTHON_LANGUAGE_SERVER.PLATFORM_SUPPORTED', + PYTHON_LANGUAGE_SERVER_TELEMETRY = 'PYTHON_LANGUAGE_SERVER.EVENT', -export const TERMINAL_CREATE = 'TERMINAL.CREATE'; -export const PYTHON_LANGUAGE_SERVER_LIST_BLOB_STORE_PACKAGES = 'PYTHON_LANGUAGE_SERVER.LIST_BLOB_PACKAGES'; -export const DIAGNOSTICS_ACTION = 'DIAGNOSTICS.ACTION'; -export const DIAGNOSTICS_MESSAGE = 'DIAGNOSTICS.MESSAGE'; -export const PLATFORM_INFO = 'PLATFORM.INFO'; + TERMINAL_CREATE = 'TERMINAL.CREATE', + PYTHON_LANGUAGE_SERVER_LIST_BLOB_STORE_PACKAGES = 'PYTHON_LANGUAGE_SERVER.LIST_BLOB_PACKAGES', + DIAGNOSTICS_ACTION = 'DIAGNOSTICS.ACTION', + DIAGNOSTICS_MESSAGE = 'DIAGNOSTICS.MESSAGE', + PLATFORM_INFO = 'PLATFORM.INFO', -export const SELECT_LINTER = 'LINTING.SELECT'; + SELECT_LINTER = 'LINTING.SELECT', -export const LINTER_NOT_INSTALLED_PROMPT = 'LINTER_NOT_INSTALLED_PROMPT'; + LINTER_NOT_INSTALLED_PROMPT = 'LINTER_NOT_INSTALLED_PROMPT' +} export enum PlatformErrors { FailedToParseVersion = 'FailedToParseVersion', diff --git a/src/client/terminals/codeExecution/codeExecutionManager.ts b/src/client/terminals/codeExecution/codeExecutionManager.ts index 04ccf5e61c19..2bc3b6cca1e0 100644 --- a/src/client/terminals/codeExecution/codeExecutionManager.ts +++ b/src/client/terminals/codeExecution/codeExecutionManager.ts @@ -10,7 +10,7 @@ import { Commands } from '../../common/constants'; import { IDisposableRegistry } from '../../common/types'; import { IServiceContainer } from '../../ioc/types'; import { captureTelemetry } from '../../telemetry'; -import { EXECUTION_CODE, EXECUTION_DJANGO } from '../../telemetry/constants'; +import { EventName } from '../../telemetry/constants'; import { ICodeExecutionHelper, ICodeExecutionManager, ICodeExecutionService } from '../../terminals/types'; @injectable() @@ -27,7 +27,7 @@ export class CodeExecutionManager implements ICodeExecutionManager { this.disposableRegistry.push(this.commandManager.registerCommand(Commands.Exec_Selection_In_Terminal, this.executeSelectionInTerminal.bind(this))); this.disposableRegistry.push(this.commandManager.registerCommand(Commands.Exec_Selection_In_Django_Shell, this.executeSelectionInDjangoShell.bind(this))); } - @captureTelemetry(EXECUTION_CODE, { scope: 'file' }, false) + @captureTelemetry(EventName.EXECUTION_CODE, { scope: 'file' }, false) private async executeFileInterTerminal(file?: Uri) { const codeExecutionHelper = this.serviceContainer.get(ICodeExecutionHelper); file = file instanceof Uri ? file : undefined; @@ -40,14 +40,14 @@ export class CodeExecutionManager implements ICodeExecutionManager { await executionService.executeFile(fileToExecute); } - @captureTelemetry(EXECUTION_CODE, { scope: 'selection' }, false) + @captureTelemetry(EventName.EXECUTION_CODE, { scope: 'selection' }, false) private async executeSelectionInTerminal(): Promise { const executionService = this.serviceContainer.get(ICodeExecutionService, 'standard'); await this.executeSelection(executionService); } - @captureTelemetry(EXECUTION_DJANGO, { scope: 'selection' }, false) + @captureTelemetry(EventName.EXECUTION_DJANGO, { scope: 'selection' }, false) private async executeSelectionInDjangoShell(): Promise { const executionService = this.serviceContainer.get(ICodeExecutionService, 'djangoShell'); await this.executeSelection(executionService); diff --git a/src/client/unittests/common/managers/baseTestManager.ts b/src/client/unittests/common/managers/baseTestManager.ts index 215881c8554e..6f484c96b194 100644 --- a/src/client/unittests/common/managers/baseTestManager.ts +++ b/src/client/unittests/common/managers/baseTestManager.ts @@ -5,7 +5,7 @@ import { IFileSystem } from '../../../common/platform/types'; import { IConfigurationService, IDisposableRegistry, IInstaller, IOutputChannel, IPythonSettings, Product } from '../../../common/types'; import { getNamesAndValues } from '../../../common/utils/enum'; import { IServiceContainer } from '../../../ioc/types'; -import { UNITTEST_DISCOVER, UNITTEST_RUN } from '../../../telemetry/constants'; +import { EventName } from '../../../telemetry/constants'; import { sendTelemetryEvent } from '../../../telemetry/index'; import { TestDiscoverytTelemetry, TestRunTelemetry } from '../../../telemetry/types'; import { IPythonUnitTestMessage, IUnitTestDiagnosticService } from '../../types'; @@ -143,7 +143,7 @@ export abstract class BaseTestManager implements ITestManager { const wkspace = this.workspaceService.getWorkspaceFolder(Uri.file(this.rootDirectory))!.uri; this.testCollectionStorage.storeTests(wkspace, tests); this.disposeCancellationToken(CancellationTokenType.testDiscovery); - sendTelemetryEvent(UNITTEST_DISCOVER, undefined, telementryProperties); + sendTelemetryEvent(EventName.UNITTEST_DISCOVER, undefined, telementryProperties); return tests; }).catch((reason: {}) => { if (isNotInstalledError(reason as Error) && !quietMode) { @@ -158,7 +158,7 @@ export abstract class BaseTestManager implements ITestManager { this._status = TestStatus.Idle; } else { telementryProperties.failed = true; - sendTelemetryEvent(UNITTEST_DISCOVER, undefined, telementryProperties); + sendTelemetryEvent(EventName.UNITTEST_DISCOVER, undefined, telementryProperties); this._status = TestStatus.Error; this.outputChannel.appendLine('Test Discovery failed: '); // tslint:disable-next-line:prefer-template @@ -237,7 +237,7 @@ export abstract class BaseTestManager implements ITestManager { }).then(() => { this._status = TestStatus.Idle; this.disposeCancellationToken(CancellationTokenType.testRunner); - sendTelemetryEvent(UNITTEST_RUN, undefined, telementryProperties); + sendTelemetryEvent(EventName.UNITTEST_RUN, undefined, telementryProperties); return this.tests!; }).catch(reason => { if (this.testRunnerCancellationToken && this.testRunnerCancellationToken.isCancellationRequested) { @@ -246,7 +246,7 @@ export abstract class BaseTestManager implements ITestManager { } else { this._status = TestStatus.Error; telementryProperties.failed = true; - sendTelemetryEvent(UNITTEST_RUN, undefined, telementryProperties); + sendTelemetryEvent(EventName.UNITTEST_RUN, undefined, telementryProperties); } this.disposeCancellationToken(CancellationTokenType.testRunner); return Promise.reject(reason); @@ -256,7 +256,7 @@ export abstract class BaseTestManager implements ITestManager { await this.stripStaleDiagnostics(tests, messages); // Update relevant file diagnostics for tests that have problems. - const uniqueMsgFiles = messages.reduce((filtered, msg) => { + const uniqueMsgFiles = messages.reduce((filtered, msg) => { if (filtered.indexOf(msg.testFilePath) === -1 && msg.testFilePath !== undefined) { filtered.push(msg.testFilePath); } @@ -272,7 +272,7 @@ export abstract class BaseTestManager implements ITestManager { this.diagnosticCollection.set(fileUri, diagnostics); } // Get the diagnostics for this file's URI before updating it so old tests that weren't run can still show problems. - const oldDiagnostics = this.diagnosticCollection.get(fileUri); + const oldDiagnostics = this.diagnosticCollection.get(fileUri)!; const newDiagnostics: Diagnostic[] = []; for (const diagnostic of oldDiagnostics) { newDiagnostics.push(diagnostic); @@ -344,15 +344,15 @@ export abstract class BaseTestManager implements ITestManager { } private createDiagnostics(message: IPythonUnitTestMessage): Diagnostic { - const stackStart = message.locationStack[0]; + const stackStart = message.locationStack![0]; const diagPrefix = this.unitTestDiagnosticService.getMessagePrefix(message.status); const severity = this.unitTestDiagnosticService.getSeverity(message.severity)!; - const diagMsg = message.message.split('\n')[0]; + const diagMsg = message.message!.split('\n')[0]; const diagnostic = new Diagnostic(stackStart.location.range, `${diagPrefix ? `${diagPrefix}: ` : ''}${diagMsg}`, severity); diagnostic.code = message.code; diagnostic.source = message.provider; const relatedInfoArr: DiagnosticRelatedInformation[] = []; - for (const frameDetails of message.locationStack) { + for (const frameDetails of message.locationStack!) { const relatedInfo = new DiagnosticRelatedInformation(frameDetails.location, frameDetails.lineText); relatedInfoArr.push(relatedInfo); } diff --git a/src/client/unittests/main.ts b/src/client/unittests/main.ts index c349f21738d6..f10cbc1bd041 100644 --- a/src/client/unittests/main.ts +++ b/src/client/unittests/main.ts @@ -9,7 +9,7 @@ import { ICommandManager, IDocumentManager, IWorkspaceService } from '../common/ import * as constants from '../common/constants'; import { IConfigurationService, IDisposableRegistry, ILogger, IOutputChannel } from '../common/types'; import { IServiceContainer } from '../ioc/types'; -import { UNITTEST_STOP, UNITTEST_VIEW_OUTPUT } from '../telemetry/constants'; +import { EventName } from '../telemetry/constants'; import { sendTelemetryEvent } from '../telemetry/index'; import { activateCodeLenses } from './codeLenses/main'; import { CANCELLATION_REASON, CommandSource, TEST_OUTPUT_CHANNEL } from './common/constants'; @@ -156,7 +156,7 @@ export class UnitTestManagementService implements IUnitTestManagementService, Di await discoveryPromise; } public async stopTests(resource: Uri) { - sendTelemetryEvent(UNITTEST_STOP); + sendTelemetryEvent(EventName.UNITTEST_STOP); const testManager = await this.getTestManager(true, resource); if (testManager) { testManager.stop(); @@ -190,7 +190,7 @@ export class UnitTestManagementService implements IUnitTestManagementService, Di testDisplay.displayFunctionTestPickerUI(cmdSource, testManager.workspaceFolder, testManager.workingDirectory, file, testFunctions, debug); } public viewOutput(cmdSource: CommandSource) { - sendTelemetryEvent(UNITTEST_VIEW_OUTPUT); + sendTelemetryEvent(EventName.UNITTEST_VIEW_OUTPUT); this.outputChannel.show(); } public async selectAndRunTestMethod(cmdSource: CommandSource, resource: Uri, debug?: boolean) { diff --git a/src/client/workspaceSymbols/generator.ts b/src/client/workspaceSymbols/generator.ts index cb1453bbd181..4b682cfcd4c7 100644 --- a/src/client/workspaceSymbols/generator.ts +++ b/src/client/workspaceSymbols/generator.ts @@ -6,7 +6,7 @@ import { IProcessServiceFactory } from '../common/process/types'; import { IConfigurationService, IPythonSettings } from '../common/types'; import { EXTENSION_ROOT_DIR } from '../constants'; import { captureTelemetry } from '../telemetry'; -import { WORKSPACE_SYMBOLS_BUILD } from '../telemetry/constants'; +import { EventName } from '../telemetry/constants'; export class Generator implements Disposable { private optionsFile: string; @@ -44,7 +44,7 @@ export class Generator implements Disposable { return [`--options=${this.optionsFile}`, '--languages=Python'].concat(excludes); } - @captureTelemetry(WORKSPACE_SYMBOLS_BUILD) + @captureTelemetry(EventName.WORKSPACE_SYMBOLS_BUILD) private async generateTags(source: { directory?: string; file?: string }): Promise { const tagFile = path.normalize(this.pythonSettings.workspaceSymbols.tagFilePath); const cmd = this.pythonSettings.workspaceSymbols.ctagsPath; diff --git a/src/client/workspaceSymbols/provider.ts b/src/client/workspaceSymbols/provider.ts index 5c20d386feb1..019bcd25592d 100644 --- a/src/client/workspaceSymbols/provider.ts +++ b/src/client/workspaceSymbols/provider.ts @@ -10,7 +10,7 @@ import { ICommandManager } from '../common/application/types'; import { Commands } from '../common/constants'; import { IFileSystem } from '../common/platform/types'; import { captureTelemetry } from '../telemetry'; -import { WORKSPACE_SYMBOLS_GO_TO } from '../telemetry/constants'; +import { EventName } from '../telemetry/constants'; import { Generator } from './generator'; import { parseTags } from './parser'; @@ -22,7 +22,7 @@ export class WorkspaceSymbolProvider implements IWorspaceSymbolProvider { ) { } - @captureTelemetry(WORKSPACE_SYMBOLS_GO_TO) + @captureTelemetry(EventName.WORKSPACE_SYMBOLS_GO_TO) public async provideWorkspaceSymbols(query: string, token: CancellationToken): Promise { if (this.tagGenerators.length === 0) { return [];