From 4d3d30f7ba772b34a7c1c0c71728ca065c39225e Mon Sep 17 00:00:00 2001 From: Vamshikrishna Ramasamy Date: Fri, 3 Jul 2026 16:30:16 -0700 Subject: [PATCH] fix: defer VS Code auto theme to platform --- cli/src/__tests__/utils/theme-system.test.ts | 30 ++++++++++++++++ cli/src/utils/theme-system.ts | 36 ++++++-------------- 2 files changed, 40 insertions(+), 26 deletions(-) create mode 100644 cli/src/__tests__/utils/theme-system.test.ts diff --git a/cli/src/__tests__/utils/theme-system.test.ts b/cli/src/__tests__/utils/theme-system.test.ts new file mode 100644 index 0000000000..1fa5735938 --- /dev/null +++ b/cli/src/__tests__/utils/theme-system.test.ts @@ -0,0 +1,30 @@ +import { describe, expect, test } from 'bun:test' + +import { extractVSCodeTheme } from '../../utils/theme-system' + +describe('cli/utils/theme-system', () => { + describe('extractVSCodeTheme', () => { + test('uses explicit VS Code color theme when auto-detect is disabled', () => { + const theme = extractVSCodeTheme(` + { + "window.autoDetectColorScheme": false, + "workbench.colorTheme": "Default Light Modern" + } + `) + + expect(theme).toBe('light') + }) + + test('defers to platform detection when VS Code syncs with OS theme', () => { + const theme = extractVSCodeTheme(` + { + "window.autoDetectColorScheme": true, + "workbench.preferredDarkColorTheme": "Default Dark Modern", + "workbench.preferredLightColorTheme": "Default Light Modern" + } + `) + + expect(theme).toBeNull() + }) + }) +}) diff --git a/cli/src/utils/theme-system.ts b/cli/src/utils/theme-system.ts index 79bd92d3dd..f555bc1e9a 100644 --- a/cli/src/utils/theme-system.ts +++ b/cli/src/utils/theme-system.ts @@ -321,39 +321,23 @@ const resolveZedSettingsPaths = ( return paths } -const extractVSCodeTheme = (content: string): ThemeName | null => { - // Try standard colorTheme setting - const colorThemeMatch = content.match( - /"workbench\.colorTheme"\s*:\s*"([^"]+)"/i, - ) - if (colorThemeMatch) { - const inferred = inferThemeFromName(colorThemeMatch[1]) - if (inferred) return inferred - } - - // Check if auto-detect is enabled and try preferred themes +export const extractVSCodeTheme = (content: string): ThemeName | null => { const autoDetectMatch = content.match( /"window\.autoDetectColorScheme"\s*:\s*(true|false)/i, ) const autoDetectEnabled = autoDetectMatch?.[1]?.toLowerCase() === 'true' if (autoDetectEnabled) { - // Try to extract both preferred themes and infer from their names - const preferredDarkMatch = content.match( - /"workbench\.preferredDarkColorTheme"\s*:\s*"([^"]+)"/i, - ) - if (preferredDarkMatch) { - const inferred = inferThemeFromName(preferredDarkMatch[1]) - if (inferred) return inferred - } + return null + } - const preferredLightMatch = content.match( - /"workbench\.preferredLightColorTheme"\s*:\s*"([^"]+)"/i, - ) - if (preferredLightMatch) { - const inferred = inferThemeFromName(preferredLightMatch[1]) - if (inferred) return inferred - } + // Try standard colorTheme setting + const colorThemeMatch = content.match( + /"workbench\.colorTheme"\s*:\s*"([^"]+)"/i, + ) + if (colorThemeMatch) { + const inferred = inferThemeFromName(colorThemeMatch[1]) + if (inferred) return inferred } return null