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 {
13651365
13661366function getVariants ( state : State ) : Array < Variant > {
13671367 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
13691382 }
13701383
13711384 if ( state . jitContext ?. getVariants ) {
Original file line number Diff line number Diff line change @@ -72,6 +72,8 @@ export function completionsFromClassList(
7272 }
7373
7474 if ( state . v4 ) {
75+ let prefix = state . designSystem . theme . prefix ?? ''
76+
7577 let { variants : existingVariants , offset } = getVariantsFromClassName ( state , partialClassName )
7678
7779 if (
@@ -277,6 +279,35 @@ export function completionsFromClassList(
277279 }
278280 }
279281
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+
280311 return withDefaults (
281312 {
282313 isIncomplete : false ,
You can’t perform that action at this time.
0 commit comments