From 306d0497650b4267fd8ac1c507fdf7abbc2f6f12 Mon Sep 17 00:00:00 2001 From: colinmcneil Date: Fri, 27 Sep 2024 15:20:23 -0400 Subject: [PATCH] Fix activation bug with `ddSocket` --- src/extension.ts | 2 ++ src/utils/ddSocket.ts | 21 +++++++++++++++------ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/extension.ts b/src/extension.ts index bb61090..4834677 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -4,6 +4,7 @@ import { nativeClient } from './utils/lsp'; import { spawnSync } from 'child_process'; import semver from 'semver'; import commands from './commands'; +import { setDefaultProperties } from './utils/ddSocket'; export let ctx: vscode.ExtensionContext; @@ -72,6 +73,7 @@ const checkOutdatedVersionInstalled = async () => { export async function activate(context: vscode.ExtensionContext) { checkOutdatedVersionInstalled(); checkVersion(); + setDefaultProperties(context); ctx = context; let setOpenAIKeyCommand = vscode.commands.registerCommand('docker.labs-ai-tools-vscode.set-openai-api-key', () => { setOpenAIKey(context.secrets); diff --git a/src/utils/ddSocket.ts b/src/utils/ddSocket.ts index 228bb85..dea112b 100644 --- a/src/utils/ddSocket.ts +++ b/src/utils/ddSocket.ts @@ -2,6 +2,7 @@ import os from 'os'; import path from 'path'; import http from 'http'; import { ctx } from '../extension'; +import { ExtensionContext } from 'vscode'; const getDevhomePrefix = () => { return process.env['DEVHOME'] ? path.basename(process.env['DEVHOME']) : ''; } @@ -54,14 +55,22 @@ type TrackEvent = { properties?: Record } -const defaultProperties = { - version: ctx.extension.packageJSON.version, - platform: os.platform(), - arch: os.arch(), - nodeVersion: process.version, - vscodeVersion: ctx.extension.packageJSON.version, +let defaultProperties = { + +} + +export const setDefaultProperties = (ctx: ExtensionContext) => { + defaultProperties = { + version: ctx.extension.packageJSON.version, + platform: os.platform(), + arch: os.arch(), + nodeVersion: process.version, + vscodeVersion: ctx.extension.packageJSON.version, + } } + + export const postToBackendSocket = (event: TrackEvent) => { event.properties = { ...event.properties, ...defaultProperties } const postData = JSON.stringify(event);