Skip to content

Commit 8a39555

Browse files
Fix display of color swatches using new v4 oklch color palette (#1073)
The new oklch color palette doesn't show swatches in some cases due to how we were detecting fallback values for CSS variables. I've made the code much more general and it should be able to handle any number of CSS var fallbacks regardless of how its nested. --------- Co-authored-by: Robin Malfait <malfait.robin@gmail.com>
1 parent 9be9123 commit 8a39555

File tree

23 files changed

+204
-172
lines changed

23 files changed

+204
-172
lines changed

packages/tailwindcss-language-server/tests/colors/colors.test.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { test } from 'vitest'
1+
import { test, expect } from 'vitest'
22
import { withFixture } from '../common'
33

44
withFixture('basic', (c) => {
@@ -169,9 +169,9 @@ withFixture('v4/basic', (c) => {
169169
{
170170
range: { start: { line: 0, character: 12 }, end: { line: 0, character: 22 } },
171171
color: {
172-
red: 0.9372549019607843,
173-
green: 0.26666666666666666,
174-
blue: 0.26666666666666666,
172+
red: expect.closeTo(0.98, 0.01),
173+
green: expect.closeTo(0.172, 0.01),
174+
blue: expect.closeTo(0.21, 0.01),
175175
alpha: 1,
176176
},
177177
},
@@ -184,9 +184,9 @@ withFixture('v4/basic', (c) => {
184184
{
185185
range: { start: { line: 0, character: 12 }, end: { line: 0, character: 25 } },
186186
color: {
187-
red: 0.9372549019607843,
188-
green: 0.26666666666666666,
189-
blue: 0.26666666666666666,
187+
red: expect.closeTo(0.98, 0.01),
188+
green: expect.closeTo(0.172, 0.01),
189+
blue: expect.closeTo(0.21, 0.01),
190190
alpha: 0.2,
191191
},
192192
},

packages/tailwindcss-language-server/tests/completions/completions.test.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -310,8 +310,8 @@ withFixture('v4/basic', (c) => {
310310
let result = await completion({ lang, text, position, settings })
311311
let textEdit = expect.objectContaining({ range: { start: position, end: position } })
312312

313-
expect(result.items.length).toBe(12398)
314-
expect(result.items.filter((item) => item.label.endsWith(':')).length).toBe(224)
313+
expect(result.items.length).toBe(12492)
314+
expect(result.items.filter((item) => item.label.endsWith(':')).length).toBe(270)
315315
expect(result).toEqual({
316316
isIncomplete: false,
317317
items: expect.arrayContaining([
@@ -553,11 +553,11 @@ withFixture('v4/basic', (c) => {
553553
expect(resolved).toEqual({
554554
...item,
555555
detail:
556-
'font-size: var(--font-size-sm, 0.875rem /* 8.75px */); line-height: var(--font-size-sm--line-height, 1.25rem /* 12.5px */);',
556+
'font-size: var(--font-size-sm, 0.875rem /* 8.75px */); line-height: var(--tw-leading, var(--font-size-sm--line-height, 1.25rem /* 12.5px */));',
557557
documentation: {
558558
kind: 'markdown',
559559
value:
560-
'```css\n.text-sm {\n font-size: var(--font-size-sm, 0.875rem /* 8.75px */);\n line-height: var(--font-size-sm--line-height, 1.25rem /* 12.5px */);\n}\n```',
560+
'```css\n.text-sm {\n font-size: var(--font-size-sm, 0.875rem /* 8.75px */);\n line-height: var(--tw-leading, var(--font-size-sm--line-height, 1.25rem /* 12.5px */));\n}\n```',
561561
},
562562
})
563563
})
@@ -579,8 +579,8 @@ withFixture('v4/basic', (c) => {
579579

580580
expect(resolved).toEqual({
581581
...item,
582-
detail: 'background-color: var(--color-red-500, #ef4444);',
583-
documentation: '#ef4444',
582+
detail: 'background-color: var(--color-red-500, oklch(0.637 0.237 25.331));',
583+
documentation: '#fb2c36',
584584
})
585585
})
586586
})

packages/tailwindcss-language-server/tests/fixtures/v4/auto-content-split/package-lock.json

Lines changed: 48 additions & 60 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"dependencies": {
3-
"tailwindcss": "^4.0.0-alpha.25",
4-
"@tailwindcss/oxide": "^4.0.0-alpha.25"
3+
"tailwindcss": "^4.0.0-alpha.30",
4+
"@tailwindcss/oxide": "^4.0.0-alpha.30"
55
}
66
}

0 commit comments

Comments
 (0)