Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions cli/src/__tests__/utils/theme-system.test.ts
Original file line number Diff line number Diff line change
@@ -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()
})
})
})
36 changes: 10 additions & 26 deletions cli/src/utils/theme-system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down