From 338e868ecbcf68f02730b1a05b98361b165b9bcc Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Sat, 27 Apr 2024 11:10:54 -0700 Subject: [PATCH] refactor: use isAmazonQ() #4858 --- packages/core/src/shared/telemetry/activation.ts | 8 ++------ packages/core/src/shared/telemetry/util.ts | 15 ++++++--------- packages/core/src/shared/vscode/commands2.ts | 4 ++-- 3 files changed, 10 insertions(+), 17 deletions(-) diff --git a/packages/core/src/shared/telemetry/activation.ts b/packages/core/src/shared/telemetry/activation.ts index f30fa2ddc48..8ea220d035f 100644 --- a/packages/core/src/shared/telemetry/activation.ts +++ b/packages/core/src/shared/telemetry/activation.ts @@ -19,7 +19,6 @@ import { isAutomation, isReleaseVersion } from '../vscode/env' import { AWSProduct } from './clienttelemetry' import { DefaultTelemetryClient } from './telemetryClient' import { Commands } from '../vscode/commands2' -import { VSCODE_EXTENSION_ID } from '../utilities' export const noticeResponseViewSettings = localize('AWS.telemetry.notificationViewSettings', 'Settings') export const noticeResponseOk = localize('AWS.telemetry.notificationOk', 'OK') @@ -53,17 +52,14 @@ export async function activate( globals.telemetry.telemetryEnabled = config.isEnabled() extensionContext.subscriptions.push( - (globals.context.extension.id === VSCODE_EXTENSION_ID.amazonq - ? config.amazonQConfig - : config.toolkitConfig - ).onDidChange(event => { + (isAmazonQ() ? config.amazonQConfig : config.toolkitConfig).onDidChange(event => { if (event.key === 'telemetry') { globals.telemetry.telemetryEnabled = config.isEnabled() } }) ) - if (extensionContext.extension.id === VSCODE_EXTENSION_ID.amazonq) { + if (isAmazonQ()) { extensionContext.subscriptions.push( Commands.register('aws.amazonq.setupTelemetryId', async () => { await setupTelemetryId(extensionContext) diff --git a/packages/core/src/shared/telemetry/util.ts b/packages/core/src/shared/telemetry/util.ts index db23e74dc00..0910ad1bc66 100644 --- a/packages/core/src/shared/telemetry/util.ts +++ b/packages/core/src/shared/telemetry/util.ts @@ -15,7 +15,7 @@ import { mapMetadata } from './telemetryLogger' import { Result } from './telemetry.gen' import { MetricDatum } from './clienttelemetry' import { isValidationExemptMetric } from './exemptMetrics' -import { isCloud9, isSageMaker } from '../../shared/extensionUtilities' +import { isAmazonQ, isCloud9, isSageMaker } from '../../shared/extensionUtilities' import { isExtensionInstalled, VSCODE_EXTENSION_ID } from '../utilities' import { randomUUID } from '../../common/crypto' import { activateExtension } from '../utilities/vsCodeUtils' @@ -55,9 +55,7 @@ export class TelemetryConfig { } public isEnabled(): boolean { - return ( - globals.context.extension.id === VSCODE_EXTENSION_ID.amazonq ? this.amazonQConfig : this.toolkitConfig - ).get(`telemetry`, true) + return (isAmazonQ() ? this.amazonQConfig : this.toolkitConfig).get(`telemetry`, true) } public async initAmazonQSetting() { @@ -119,10 +117,9 @@ export async function getUserAgent( opt?: { includePlatform?: boolean; includeClientId?: boolean }, globalState = globals.context.globalState ): Promise { - const pairs = - globals.context.extension.id === VSCODE_EXTENSION_ID.amazonq - ? [`AmazonQ-For-VSCode/${extensionVersion}`] - : [`AWS-Toolkit-For-VSCode/${extensionVersion}`] + const pairs = isAmazonQ() + ? [`AmazonQ-For-VSCode/${extensionVersion}`] + : [`AWS-Toolkit-For-VSCode/${extensionVersion}`] if (opt?.includePlatform) { pairs.push(platformPair()) @@ -225,7 +222,7 @@ export async function setupTelemetryId(extensionContext: vscode.ExtensionContext await vscode.commands.executeCommand('aws.amazonq.setupTelemetryId') }) } - } else if (extensionContext.extension.id === VSCODE_EXTENSION_ID.amazonq) { + } else if (isAmazonQ()) { getLogger().debug(`telemetry: Set telemetry client id to ${storedClientId}`) await globals.context.globalState.update(telemetryClientIdGlobalStatekey, storedClientId) } else { diff --git a/packages/core/src/shared/vscode/commands2.ts b/packages/core/src/shared/vscode/commands2.ts index d5c11aaa412..1f9f7b6659b 100644 --- a/packages/core/src/shared/vscode/commands2.ts +++ b/packages/core/src/shared/vscode/commands2.ts @@ -15,7 +15,7 @@ import { ToolkitError } from '../errors' import crypto from 'crypto' import { keysAsInt } from '../utilities/tsUtils' import { partialClone } from '../utilities/collectionUtils' -import { VSCODE_EXTENSION_ID } from '../utilities' +import { isAmazonQ } from '../extensionUtilities' type Callback = (...args: any[]) => any type CommandFactory = (...parameters: U) => T @@ -636,7 +636,7 @@ async function runCommand(fn: T, info: CommandInfo): Prom try { if (info.autoconnect === true) { - const prefix = globals.context.extension.id === VSCODE_EXTENSION_ID.amazonq ? 'amazonq' : 'toolkit' + const prefix = isAmazonQ() ? 'amazonq' : 'toolkit' await vscode.commands.executeCommand(`_aws.${prefix}.auth.autoConnect`) }