Skip to content

Commit a396e35

Browse files
Ensure color swatches show in completions when using a prefix (#1422)
Fixes #1421 Before: <img width="937" alt="Screenshot 2025-07-07 at 10 38 10" src="https://github.com/user-attachments/assets/da008d37-4b81-4306-b86d-bb1a47df42b4" /> After: <img width="959" alt="Screenshot 2025-07-07 at 10 37 24" src="https://github.com/user-attachments/assets/d9b536e0-d916-48b8-aeb0-3f4d621a460c" />
1 parent 30eb3dc commit a396e35

File tree

3 files changed

+44
-1
lines changed

3 files changed

+44
-1
lines changed

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

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -814,6 +814,39 @@ defineTest({
814814
},
815815
})
816816

817+
defineTest({
818+
name: 'v4: class completions show colors when using prefixes',
819+
fs: {
820+
'app.css': css`
821+
@import 'tailwindcss' prefix(tw);
822+
`,
823+
},
824+
prepare: async ({ root }) => ({ client: await createClient({ root }) }),
825+
handle: async ({ client }) => {
826+
let document = await client.open({
827+
lang: 'html',
828+
text: '<div class="tw:">',
829+
})
830+
831+
// <div class="tw:">
832+
// ^
833+
let completion = await document.completions({ line: 0, character: 15 })
834+
835+
expect(completion).toEqual({
836+
isIncomplete: false,
837+
items: expect.arrayContaining([
838+
expect.objectContaining({
839+
label: 'bg-black',
840+
841+
// And it's shown as a color
842+
kind: CompletionItemKind.Color,
843+
documentation: '#000000',
844+
}),
845+
]),
846+
})
847+
},
848+
})
849+
817850
defineTest({
818851
name: 'v4: Completions show inside class functions in JS/TS files',
819852
fs: {

packages/tailwindcss-language-service/src/util/color.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,16 @@ export function getColor(state: State, className: string): culori.Color | Keywor
216216

217217
let color = getColorFromRoot(state, css)
218218

219+
let prefix = state.designSystem.theme.prefix ?? ''
220+
221+
// TODO: Either all consumers of this API should assume there's no prefix
222+
// or pass in correctly prefixed classes
223+
if (prefix && !color && !className.startsWith(prefix + ':')) {
224+
className = `${prefix}:${className}`
225+
css = state.designSystem.compile([className])[0]
226+
color = getColorFromRoot(state, css)
227+
}
228+
219229
return color
220230
}
221231

packages/vscode-tailwindcss/CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## Prerelease
44

5-
- Nothing yet!
5+
- Ensure color swatches show up in completions when using a prefix in v4 ([#1422](https://github.com/tailwindlabs/tailwindcss-intellisense/pull/1422))
66

77
## 0.14.24
88

0 commit comments

Comments
 (0)