@@ -419,6 +419,7 @@ 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 } )
422
423
return getCompletionFor ( { ctx, propName, propNode, settings, shorthand } )
423
424
} )
424
425
} catch ( err ) {
@@ -636,20 +637,50 @@ const getCompletionFor = ({
636
637
637
638
// token(colors.red.300) -> category = "colors"
638
639
// color="red.300" -> no category, need to find it
640
+ let propValues : Record < string , string > | undefined
639
641
if ( ! category ) {
640
642
const utility = ctx . config . utilities ?. [ propName ]
641
- if ( typeof utility ?. values === 'string' && utility ?. values ) {
643
+ if ( ! utility ?. values ) return
644
+
645
+ // values: "spacing"
646
+ if ( typeof utility ?. values === 'string' ) {
642
647
category = utility . values
648
+ } else if ( typeof utility . values === 'function' ) {
649
+ // values: (theme) => { ...theme("spacing") }
650
+ const record = ctx . utility . getPropertyValues ( utility )
651
+ if ( record ) {
652
+ if ( record . type ) category = record . type
653
+ else propValues = record
654
+ }
643
655
}
644
656
}
645
657
658
+ // values: { "1": "1px", "2": "2px", ... }
659
+ if ( propValues ) {
660
+ const items = [ ] as CompletionItem [ ]
661
+ Object . entries ( propValues ) . map ( ( [ name , value ] ) => {
662
+ // margin: "2" -> ['var(--spacing-2)', 'var(--spacing-12)', 'var(--spacing-20)', ...]
663
+ if ( str && ! name . includes ( str ) ) return
664
+
665
+ items . push ( {
666
+ data : { propName, token : getTokenFromPropValue ( ctx , propName , value ) , shorthand } ,
667
+ label : name ,
668
+ kind : CompletionItemKind . EnumMember ,
669
+ sortText : '-' + getSortText ( name ) ,
670
+ preselect : false ,
671
+ } )
672
+ } )
673
+
674
+ return items
675
+ }
676
+
646
677
if ( ! category ) return [ ]
647
678
648
- const values = ctx . tokens . categoryMap . get ( category )
649
- if ( ! values ) return [ ]
679
+ const categoryValues = ctx . tokens . categoryMap . get ( category ! )
680
+ if ( ! categoryValues ) return [ ]
650
681
651
682
const items = [ ] as CompletionItem [ ]
652
- values . forEach ( ( token , name ) => {
683
+ categoryValues . forEach ( ( token , name ) => {
653
684
if ( str && ! name . includes ( str ) ) return
654
685
655
686
const isColor = token . extensions . category === 'colors'
0 commit comments