File tree Expand file tree Collapse file tree 2 files changed +45
-1
lines changed
tailwindcss-language-server/src
tailwindcss-language-service/src Expand file tree Collapse file tree 2 files changed +45
-1
lines changed Original file line number Diff line number Diff line change @@ -1365,7 +1365,20 @@ function isAtRule(node: Node): node is AtRule {
1365
1365
1366
1366
function getVariants ( state : State ) : Array < Variant > {
1367
1367
if ( state . v4 ) {
1368
- return state . designSystem . getVariants ( )
1368
+ let variants = Array . from ( state . designSystem . getVariants ( ) )
1369
+
1370
+ let prefix = state . designSystem . theme . prefix ?? ''
1371
+ if ( prefix . length > 0 ) {
1372
+ variants . unshift ( {
1373
+ name : prefix ,
1374
+ values : [ ] ,
1375
+ isArbitrary : false ,
1376
+ hasDash : true ,
1377
+ selectors : ( ) => [ '&' ] ,
1378
+ } )
1379
+ }
1380
+
1381
+ return variants
1369
1382
}
1370
1383
1371
1384
if ( state . jitContext ?. getVariants ) {
Original file line number Diff line number Diff line change @@ -72,6 +72,8 @@ export function completionsFromClassList(
72
72
}
73
73
74
74
if ( state . v4 ) {
75
+ let prefix = state . designSystem . theme . prefix ?? ''
76
+
75
77
let { variants : existingVariants , offset } = getVariantsFromClassName ( state , partialClassName )
76
78
77
79
if (
@@ -277,6 +279,35 @@ export function completionsFromClassList(
277
279
}
278
280
}
279
281
282
+ // TODO: This is a bit of a hack
283
+ if ( prefix . length > 0 ) {
284
+ // No variants seen: suggest the prefix only
285
+ if ( existingVariants . length === 0 ) {
286
+ items = items . slice ( 0 , 1 )
287
+
288
+ return withDefaults (
289
+ {
290
+ isIncomplete : false ,
291
+ items,
292
+ } ,
293
+ {
294
+ data : {
295
+ ...( state . completionItemData ?? { } ) ,
296
+ ...( important ? { important } : { } ) ,
297
+ variants : existingVariants ,
298
+ } ,
299
+ range : replacementRange ,
300
+ } ,
301
+ state . editor . capabilities . itemDefaults ,
302
+ )
303
+ }
304
+
305
+ // The first variant is not the prefix: don't suggest anything
306
+ if ( existingVariants [ 0 ] !== prefix ) {
307
+ return null
308
+ }
309
+ }
310
+
280
311
return withDefaults (
281
312
{
282
313
isIncomplete : false ,
You can’t perform that action at this time.
0 commit comments