Skip to content

Commit 4b8ae97

Browse files
committed
feat: completion detail for utility with values fn
1 parent 22d4ee0 commit 4b8ae97

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

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

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,6 @@ export function setupTokensHelpers(setup: PandaExtensionSetup) {
419419
try {
420420
return await findClosestToken(node, stack, ({ propName, propNode, shorthand }) => {
421421
if (!box.isLiteral(propNode)) return undefined
422-
console.log({ propNode, shorthand })
423422
return getCompletionFor({ ctx, propName, propNode, settings, shorthand })
424423
})
425424
} catch (err) {
@@ -434,7 +433,8 @@ export function setupTokensHelpers(setup: PandaExtensionSetup) {
434433
if (!ctx) return
435434

436435
const settings = await setup.getPandaSettings()
437-
const { propName, token, shorthand } = (item.data ?? {}) as { propName: string; token: Token; shorthand: string }
436+
const { propName, token, shorthand } = (item.data ?? {}) as { propName: string; token?: Token; shorthand: string }
437+
if (!token) return
438438
const markdownCss = getMarkdownCss(ctx, { [propName]: token.value }, settings)
439439

440440
const markdown = [markdownCss.withCss]
@@ -662,8 +662,11 @@ const getCompletionFor = ({
662662
// margin: "2" -> ['var(--spacing-2)', 'var(--spacing-12)', 'var(--spacing-20)', ...]
663663
if (str && !name.includes(str)) return
664664

665+
const tokenPath = matchVar(value ?? '')?.replace('-', '.')
666+
const token = tokenPath && ctx.tokens.getByName(tokenPath)
667+
665668
items.push({
666-
data: { propName, token: getTokenFromPropValue(ctx, propName, value), shorthand },
669+
data: { propName, token, shorthand },
667670
label: name,
668671
kind: CompletionItemKind.EnumMember,
669672
sortText: '-' + getSortText(name),
@@ -715,3 +718,9 @@ const getFirstAncestorMatching = <Ancestor extends Node>(
715718
if (parent && callback(parent, i)) return parent
716719
}
717720
}
721+
722+
const regex = /var\(--([\w-.]+)\)/g
723+
const matchVar = (str: string) => {
724+
const match = regex.exec(str)
725+
return match ? match[1] : null
726+
}

0 commit comments

Comments
 (0)