From cf52db8f4923c56c64dc841b3edb0db8d1aeb7d8 Mon Sep 17 00:00:00 2001 From: Sarah Fortune Date: Tue, 19 Aug 2025 13:52:41 -0700 Subject: [PATCH] Get the extension URI from the ExtensionContext instead of `vscode.extensions.getExtension("saoudrizwan.claude-dev")` (#5688) --- src/core/controller/ui/subscribeToTheme.ts | 4 ++-- src/hosts/vscode/VscodeWebviewProvider.ts | 2 +- src/integrations/theme/getTheme.ts | 12 ++++-------- 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/src/core/controller/ui/subscribeToTheme.ts b/src/core/controller/ui/subscribeToTheme.ts index 734a7935..f7eed0e3 100644 --- a/src/core/controller/ui/subscribeToTheme.ts +++ b/src/core/controller/ui/subscribeToTheme.ts @@ -14,7 +14,7 @@ const activeThemeSubscriptions = new Set>() * @param requestId The ID of the request (passed by the gRPC handler) */ export async function subscribeToTheme( - _controller: Controller, + controller: Controller, _request: EmptyRequest, responseStream: StreamingResponseHandler, requestId?: string, @@ -33,7 +33,7 @@ export async function subscribeToTheme( } // Send the current theme immediately upon subscription - const theme = await getTheme() + const theme = await getTheme(controller.context) if (theme) { try { const themeEvent = String.create({ diff --git a/src/hosts/vscode/VscodeWebviewProvider.ts b/src/hosts/vscode/VscodeWebviewProvider.ts index 4ef76c6d..ccbbb9b1 100644 --- a/src/hosts/vscode/VscodeWebviewProvider.ts +++ b/src/hosts/vscode/VscodeWebviewProvider.ts @@ -132,7 +132,7 @@ export class VscodeWebviewProvider extends WebviewProvider implements vscode.Web async (e) => { if (e && e.affectsConfiguration("workbench.colorTheme")) { // Send theme update via gRPC subscription - const theme = await getTheme() + const theme = await getTheme(this.context) if (theme) { await sendThemeEvent(JSON.stringify(theme)) } diff --git a/src/integrations/theme/getTheme.ts b/src/integrations/theme/getTheme.ts index 5b7fe87f..f38c335b 100644 --- a/src/integrations/theme/getTheme.ts +++ b/src/integrations/theme/getTheme.ts @@ -30,8 +30,8 @@ function parseThemeString(themeString: string | undefined): any { return JSON.parse(themeString ?? "{}") } -export async function getTheme() { - let currentTheme +export async function getTheme(context: vscode.ExtensionContext) { + let currentTheme: string | undefined const colorTheme = vscode.workspace.getConfiguration("workbench").get("colorTheme") || "Default Dark Modern" try { @@ -54,7 +54,7 @@ export async function getTheme() { if (currentTheme === undefined && defaultThemes[colorTheme]) { const filename = `${defaultThemes[colorTheme]}.json` currentTheme = await fs.readFile( - path.join(getExtensionUri().fsPath, "src", "integrations", "theme", "default-themes", filename), + path.join(context.extensionUri.fsPath, "src", "integrations", "theme", "default-themes", filename), "utf-8", ) } @@ -64,7 +64,7 @@ export async function getTheme() { if (parsed.include) { const includeThemeString = await fs.readFile( - path.join(getExtensionUri().fsPath, "src", "integrations", "theme", "default-themes", parsed.include), + path.join(context.extensionUri.fsPath, "src", "integrations", "theme", "default-themes", parsed.include), "utf-8", ) const includeTheme = parseThemeString(includeThemeString) @@ -135,7 +135,3 @@ export function mergeJson( } } } - -function getExtensionUri(): vscode.Uri { - return vscode.extensions.getExtension("saoudrizwan.claude-dev")!.extensionUri -}