Skip to content

Commit 9acf670

Browse files
Clean up constants
1 parent dcfc94f commit 9acf670

6 files changed

Lines changed: 28 additions & 20 deletions

File tree

src/cloud/api.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
import * as vscode from "vscode"
2+
import { EXTENSION_ID } from "../extension"
3+
import { AUTH_PROVIDER_ID } from "./auth"
24
import type { App, Deployment, ListResponse, Team } from "./types"
35

4-
const AUTH_PROVIDER_ID = "fastapi-vscode"
5-
66
export interface UploadInfo {
77
url: string
88
fields: Record<string, string>
99
}
1010

1111
function getExtensionVersion(): string {
1212
return (
13-
vscode.extensions.getExtension("FastAPILabs.fastapi-vscode")?.packageJSON
14-
?.version ?? "unknown"
13+
vscode.extensions.getExtension(EXTENSION_ID)?.packageJSON?.version ??
14+
"unknown"
1515
)
1616
}
1717

src/cloud/auth.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { log } from "../utils/logger"
1818
import { trackCloudSignIn } from "../utils/telemetry"
1919
import { ApiService } from "./api"
2020

21-
const CLIENT_ID = "fastapi-vscode"
21+
export const AUTH_PROVIDER_ID = "fastapi-vscode"
2222
const NAME = "FastAPI Cloud"
2323
const AUTH_POLL_INTERVAL_MS = 3000
2424

@@ -63,9 +63,14 @@ export class CloudAuthenticationProvider
6363

6464
constructor(private readonly context: ExtensionContext) {
6565
this._disposable = Disposable.from(
66-
authentication.registerAuthenticationProvider(CLIENT_ID, NAME, this, {
67-
supportsMultipleAccounts: false,
68-
}),
66+
authentication.registerAuthenticationProvider(
67+
AUTH_PROVIDER_ID,
68+
NAME,
69+
this,
70+
{
71+
supportsMultipleAccounts: false,
72+
},
73+
),
6974
)
7075
}
7176

@@ -244,7 +249,7 @@ export class CloudAuthenticationProvider
244249
ReturnType<typeof ApiService.requestDeviceCode>
245250
>
246251
try {
247-
deviceCodeResponse = await ApiService.requestDeviceCode(CLIENT_ID)
252+
deviceCodeResponse = await ApiService.requestDeviceCode(AUTH_PROVIDER_ID)
248253
} catch (error) {
249254
if (
250255
error instanceof TypeError &&
@@ -275,7 +280,7 @@ export class CloudAuthenticationProvider
275280
cancellationToken.onCancellationRequested(() => abortController.abort())
276281

277282
return await ApiService.pollDeviceToken(
278-
CLIENT_ID,
283+
AUTH_PROVIDER_ID,
279284
deviceCodeResponse.device_code,
280285
intervalMs,
281286
abortController.signal,

src/cloud/cloudController.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,11 @@ import {
77
trackCloudSignOut,
88
} from "../utils/telemetry"
99
import { ApiService } from "./api"
10+
import { AUTH_PROVIDER_ID } from "./auth"
1011
import type { ConfigService } from "./config"
1112
import { createNewApp, pickExistingApp, pickTeam } from "./pickers"
1213
import type { App, Team } from "./types"
1314

14-
const AUTH_PROVIDER_ID = "fastapi-vscode"
15-
1615
interface AuthProvider {
1716
signOut(): Promise<void>
1817
}

src/extension.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import * as vscode from "vscode"
66
import { discoverFastAPIApps } from "./appDiscovery"
77
import { ApiService } from "./cloud/api"
8-
import { CloudAuthenticationProvider } from "./cloud/auth"
8+
import { AUTH_PROVIDER_ID, CloudAuthenticationProvider } from "./cloud/auth"
99
import { CloudController } from "./cloud/cloudController"
1010
import { ConfigService } from "./cloud/config"
1111
import { clearImportCache } from "./core/importResolver"
@@ -37,6 +37,8 @@ import {
3737
trackTreeViewVisible,
3838
} from "./utils/telemetry"
3939

40+
export const EXTENSION_ID = "FastAPILabs.fastapi-vscode"
41+
4042
let parserService: Parser | null = null
4143

4244
function navigateToLocation(location: SourceLocation): void {
@@ -50,8 +52,8 @@ function navigateToLocation(location: SourceLocation): void {
5052
export async function activate(context: vscode.ExtensionContext) {
5153
const elapsed = createTimer()
5254
const extensionVersion =
53-
vscode.extensions.getExtension("FastAPILabs.fastapi-vscode")?.packageJSON
54-
?.version ?? "unknown"
55+
vscode.extensions.getExtension(EXTENSION_ID)?.packageJSON?.version ??
56+
"unknown"
5557
log(
5658
`FastAPI extension ${extensionVersion} activated (VS Code ${vscode.version})`,
5759
)
@@ -202,7 +204,7 @@ export async function activate(context: vscode.ExtensionContext) {
202204
context.subscriptions.push(
203205
{ dispose: () => authProvider.dispose() },
204206
vscode.commands.registerCommand("fastapi-vscode.signIn", async () => {
205-
await vscode.authentication.getSession("fastapi-vscode", [], {
207+
await vscode.authentication.getSession(AUTH_PROVIDER_ID, [], {
206208
createIfNone: true,
207209
})
208210
}),

src/test/extension.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import * as assert from "node:assert"
22
import * as vscode from "vscode"
3+
import { EXTENSION_ID } from "../extension"
34

45
suite("Extension Test Suite", () => {
56
test("Extension should be present", () => {
6-
assert.ok(vscode.extensions.getExtension("FastAPILabs.fastapi-vscode"))
7+
assert.ok(vscode.extensions.getExtension(EXTENSION_ID))
78
})
89

910
test("Extension should activate", async () => {
10-
const ext = vscode.extensions.getExtension("FastAPILabs.fastapi-vscode")
11+
const ext = vscode.extensions.getExtension(EXTENSION_ID)
1112
assert.ok(ext)
1213
await ext.activate()
1314
assert.strictEqual(ext.isActive, true)

src/utils/telemetry/vscode.ts

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

66
import * as vscode from "vscode"
7+
import { EXTENSION_ID } from "../../extension"
78
import { client } from "./client"
89
import type { ClientInfo } from "./types"
910

@@ -88,8 +89,8 @@ export async function initVSCodeTelemetry(
8889

8990
const userId = await getOrCreateUserId(context)
9091
const extensionVersion =
91-
vscode.extensions.getExtension("FastAPILabs.fastapi-vscode")?.packageJSON
92-
?.version ?? "unknown"
92+
vscode.extensions.getExtension(EXTENSION_ID)?.packageJSON?.version ??
93+
"unknown"
9394

9495
await client.init({
9596
userId,

0 commit comments

Comments
 (0)