Skip to content

Commit 98e4d8f

Browse files
committed
Use resolveThemeValue API
The one we have actually works for what we want
1 parent 1878ae6 commit 98e4d8f

File tree

4 files changed

+6
-23
lines changed

4 files changed

+6
-23
lines changed

packages/tailwindcss-language-server/src/util/v4/design-system.ts

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -172,25 +172,6 @@ export async function loadDesignSystem(
172172
? postcss.root({ nodes }).toString().trim()
173173
: nodes.toString().trim()
174174
},
175-
176-
lookupThemeValue(themeKey: string): string | null {
177-
if (!themeKey.startsWith('--')) {
178-
return null
179-
}
180-
181-
let details = design.theme.values.get(themeKey)
182-
183-
// That theme key doesn't exist
184-
if (!details) return null
185-
186-
// Early versions of v4 had string values
187-
if (typeof details === 'string') {
188-
return details
189-
}
190-
191-
// Later versions have an object with more data
192-
return details.value
193-
}
194175
})
195176

196177
return design

packages/tailwindcss-language-service/src/util/css-vars.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ test('replacing CSS variables with their fallbacks (when they have them)', () =>
1111
let state: State = {
1212
enabled: true,
1313
designSystem: {
14-
lookupThemeValue: (name) => map.get(name) ?? null,
14+
resolveThemeValue: (name) => map.get(name) ?? null,
1515
} as DesignSystem,
1616
}
1717

packages/tailwindcss-language-service/src/util/css-vars.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ export function replaceCssVarsWithFallbacks(state: State, str: string): string {
88
// In a v4 project we should attempt to look up the value from the theme
99
// this is because not all v4 projects will generate utilities where
1010
// variables have fallbacks
11-
if (state.designSystem) {
12-
return state.designSystem.lookupThemeValue(name)
11+
if (state.designSystem && name.startsWith('--')) {
12+
return state.designSystem.resolveThemeValue?.(name) ?? null
1313
}
1414

1515
// Don't replace the variable otherwise

packages/tailwindcss-language-service/src/util/v4/design-system.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,7 @@ export interface DesignSystem {
4343
export interface DesignSystem {
4444
compile(classes: string[]): postcss.Root[]
4545
toCss(nodes: postcss.Root | postcss.Node[]): string
46-
lookupThemeValue(themeKey: string): string | null
46+
47+
// Optional because it did not exist in earlier v4 alpha versions
48+
resolveThemeValue?(path: string): string | null
4749
}

0 commit comments

Comments
 (0)