File tree Expand file tree Collapse file tree 1 file changed +32
-0
lines changed
packages/tailwindcss-language-service/src Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -1540,6 +1540,23 @@ function provideCssDirectiveCompletions(
1540
1540
) } )`,
1541
1541
} ,
1542
1542
} )
1543
+
1544
+ // If we're inside an @variant directive, also add `@slot`
1545
+ if ( isInsideAtRule ( 'variant' , document , position ) ) {
1546
+ items . push ( {
1547
+ label : '@slot' ,
1548
+ documentation : {
1549
+ kind : 'markdown' as typeof MarkupKind . Markdown ,
1550
+ value : `Use the \`@slot\` directive to define where rules go in a custom variant.\n\n[Tailwind CSS Documentation](${ docsUrl (
1551
+ state . version ,
1552
+ 'functions-and-directives/#slot' ,
1553
+ ) } )`,
1554
+ } ,
1555
+
1556
+ // Make sure this appears as the first at-rule
1557
+ sortText : '-0000000' ,
1558
+ } )
1559
+ }
1543
1560
}
1544
1561
1545
1562
return withDefaults (
@@ -1567,6 +1584,21 @@ function provideCssDirectiveCompletions(
1567
1584
)
1568
1585
}
1569
1586
1587
+ function isInsideAtRule ( name : string , document : TextDocument , position : Position ) {
1588
+ // 1. Get all text up to the current position
1589
+ let text = document . getText ( {
1590
+ start : { line : 0 , character : 0 } ,
1591
+ end : position ,
1592
+ } )
1593
+
1594
+ // 2. Find the last instance of the at-rule
1595
+ let block = text . lastIndexOf ( `@${ name } ` )
1596
+ if ( block === - 1 ) return false
1597
+
1598
+ // 4. Count the number of open and close braces following the rule to determine if we're inside it
1599
+ return braceLevel ( text . slice ( block ) ) > 0
1600
+ }
1601
+
1570
1602
// Provide completions for directives that take file paths
1571
1603
async function provideFileDirectiveCompletions (
1572
1604
state : State ,
You can’t perform that action at this time.
0 commit comments