Skip to content

Ensure color swatches show in completions when using a prefix #1422

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 7, 2025
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -814,6 +814,39 @@ defineTest({
},
})

defineTest({
name: 'v4: class completions show colors when using prefixes',
fs: {
'app.css': css`
@import 'tailwindcss' prefix(tw);
`,
},
prepare: async ({ root }) => ({ client: await createClient({ root }) }),
handle: async ({ client }) => {
let document = await client.open({
lang: 'html',
text: '<div class="tw:">',
})

// <div class="tw:">
// ^
let completion = await document.completions({ line: 0, character: 15 })

expect(completion).toEqual({
isIncomplete: false,
items: expect.arrayContaining([
expect.objectContaining({
label: 'bg-black',

// And it's shown as a color
kind: CompletionItemKind.Color,
documentation: '#000000',
}),
]),
})
},
})

defineTest({
name: 'v4: Completions show inside class functions in JS/TS files',
fs: {
Expand Down
10 changes: 10 additions & 0 deletions packages/tailwindcss-language-service/src/util/color.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,16 @@ export function getColor(state: State, className: string): culori.Color | Keywor

let color = getColorFromRoot(state, css)

let prefix = state.designSystem.theme.prefix ?? ''

// TODO: Either all consumers of this API should assume there's no prefix
// or pass in correctly prefixed classes
if (prefix && !color && !className.startsWith(prefix + ':')) {
className = `${prefix}:${className}`
css = state.designSystem.compile([className])[0]
color = getColorFromRoot(state, css)
}

return color
}

Expand Down
2 changes: 1 addition & 1 deletion packages/vscode-tailwindcss/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Prerelease

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

## 0.14.24

Expand Down