@@ -419,7 +419,6 @@ export function setupTokensHelpers(setup: PandaExtensionSetup) {
419
419
try {
420
420
return await findClosestToken ( node , stack , ( { propName, propNode, shorthand } ) => {
421
421
if ( ! box . isLiteral ( propNode ) ) return undefined
422
- console . log ( { propNode, shorthand } )
423
422
return getCompletionFor ( { ctx, propName, propNode, settings, shorthand } )
424
423
} )
425
424
} catch ( err ) {
@@ -434,7 +433,8 @@ export function setupTokensHelpers(setup: PandaExtensionSetup) {
434
433
if ( ! ctx ) return
435
434
436
435
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
438
438
const markdownCss = getMarkdownCss ( ctx , { [ propName ] : token . value } , settings )
439
439
440
440
const markdown = [ markdownCss . withCss ]
@@ -662,8 +662,11 @@ const getCompletionFor = ({
662
662
// margin: "2" -> ['var(--spacing-2)', 'var(--spacing-12)', 'var(--spacing-20)', ...]
663
663
if ( str && ! name . includes ( str ) ) return
664
664
665
+ const tokenPath = matchVar ( value ?? '' ) ?. replace ( '-' , '.' )
666
+ const token = tokenPath && ctx . tokens . getByName ( tokenPath )
667
+
665
668
items . push ( {
666
- data : { propName, token : getTokenFromPropValue ( ctx , propName , value ) , shorthand } ,
669
+ data : { propName, token, shorthand } ,
667
670
label : name ,
668
671
kind : CompletionItemKind . EnumMember ,
669
672
sortText : '-' + getSortText ( name ) ,
@@ -715,3 +718,9 @@ const getFirstAncestorMatching = <Ancestor extends Node>(
715
718
if ( parent && callback ( parent , i ) ) return parent
716
719
}
717
720
}
721
+
722
+ const regex = / v a r \( - - ( [ \w - . ] + ) \) / g
723
+ const matchVar = ( str : string ) => {
724
+ const match = regex . exec ( str )
725
+ return match ? match [ 1 ] : null
726
+ }
0 commit comments