Skip to content

Commit 1ba7936

Browse files
committed
fix: semantic tokens color hints
1 parent 3d9911e commit 1ba7936

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

packages/language-server/src/features/color-hints.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export function registerColorHints(extension: PandaExtension) {
3333
const isColor = match.kind === 'token' && match.token.extensions?.vscodeColor
3434
if (!isColor) return
3535

36-
// Add 1 color hint for each condition
36+
// Add 1 color hint for each root condition
3737
if (match.token.extensions.conditions) {
3838
if (settings['color-hints.semantic-tokens.enabled']) {
3939
Object.entries(match.token.extensions.conditions).forEach(([cond, value]) => {

packages/language-server/src/tokens/setup-tokens-helpers.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -573,8 +573,19 @@ const getTokenFromPropValue = (ctx: PandaContext, prop: string, value: string):
573573
// known theme token
574574
// px: "2", fontSize: "xl", ...
575575
// color: "blue.300"
576-
if (isColor(token.value)) {
577-
const extensions = getColorExtensions(token.value, 'color')
576+
577+
let color = token.value
578+
// could be a semantic token, so the token.value wouldn't be a color directly, it's actually a CSS variable
579+
if (!isColor(color) && token.value.startsWith('var(--')) {
580+
const [tokenRef] = ctx.tokens.getReferences(token.originalValue)
581+
if (tokenRef?.value) {
582+
color = tokenRef.value
583+
}
584+
}
585+
586+
// now it could be a color
587+
if (isColor(color)) {
588+
const extensions = getColorExtensions(color, 'color')
578589
if (!extensions) return
579590

580591
return token.setExtensions(extensions)

0 commit comments

Comments
 (0)