Skip to content

Commit 3ea95f6

Browse files
Move getExtensionVersion to extension.ts
1 parent 9acf670 commit 3ea95f6

3 files changed

Lines changed: 11 additions & 15 deletions

File tree

src/cloud/api.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as vscode from "vscode"
2-
import { EXTENSION_ID } from "../extension"
2+
import { getExtensionVersion } from "../extension"
33
import { AUTH_PROVIDER_ID } from "./auth"
44
import type { App, Deployment, ListResponse, Team } from "./types"
55

@@ -8,13 +8,6 @@ export interface UploadInfo {
88
fields: Record<string, string>
99
}
1010

11-
function getExtensionVersion(): string {
12-
return (
13-
vscode.extensions.getExtension(EXTENSION_ID)?.packageJSON?.version ??
14-
"unknown"
15-
)
16-
}
17-
1811
function getUserAgentHeaders(): Record<string, string> {
1912
// User-Agent is a forbidden header in browsers and causes fetch to fail
2013
if (vscode.env.uiKind === vscode.UIKind.Web) return {}

src/extension.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,13 @@ import {
3939

4040
export const EXTENSION_ID = "FastAPILabs.fastapi-vscode"
4141

42+
export function getExtensionVersion(): string {
43+
return (
44+
vscode.extensions.getExtension(EXTENSION_ID)?.packageJSON?.version ??
45+
"unknown"
46+
)
47+
}
48+
4249
let parserService: Parser | null = null
4350

4451
function navigateToLocation(location: SourceLocation): void {
@@ -51,9 +58,7 @@ function navigateToLocation(location: SourceLocation): void {
5158

5259
export async function activate(context: vscode.ExtensionContext) {
5360
const elapsed = createTimer()
54-
const extensionVersion =
55-
vscode.extensions.getExtension(EXTENSION_ID)?.packageJSON?.version ??
56-
"unknown"
61+
const extensionVersion = getExtensionVersion()
5762
log(
5863
`FastAPI extension ${extensionVersion} activated (VS Code ${vscode.version})`,
5964
)

src/utils/telemetry/vscode.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*/
55

66
import * as vscode from "vscode"
7-
import { EXTENSION_ID } from "../../extension"
7+
import { getExtensionVersion } from "../../extension"
88
import { client } from "./client"
99
import type { ClientInfo } from "./types"
1010

@@ -88,9 +88,7 @@ export async function initVSCodeTelemetry(
8888
}
8989

9090
const userId = await getOrCreateUserId(context)
91-
const extensionVersion =
92-
vscode.extensions.getExtension(EXTENSION_ID)?.packageJSON?.version ??
93-
"unknown"
91+
const extensionVersion = getExtensionVersion()
9492

9593
await client.init({
9694
userId,

0 commit comments

Comments
 (0)