@@ -28,11 +28,14 @@ import { ensureArray } from './util/array'
28
28
import { getClassAttributeLexer , getComputedClassAttributeLexer } from './util/lexers'
29
29
import { validateApply } from './util/validateApply'
30
30
import { flagEnabled } from './util/flagEnabled'
31
- import { remToPx } from './util/remToPx'
32
31
import * as jit from './util/jit'
33
32
import { getVariantsFromClassName } from './util/getVariantsFromClassName'
34
33
import * as culori from 'culori'
35
34
import Regex from 'becke-ch--regex--s0-0-v1--base--pl--lib'
35
+ import {
36
+ addPixelEquivalentsToMediaQuery ,
37
+ addPixelEquivalentsToValue ,
38
+ } from './util/pixelEquivalents'
36
39
37
40
let isUtil = ( className ) =>
38
41
Array . isArray ( className . __info )
@@ -43,6 +46,7 @@ export function completionsFromClassList(
43
46
state : State ,
44
47
classList : string ,
45
48
classListRange : Range ,
49
+ rootFontSize : number ,
46
50
filter ?: ( item : CompletionItem ) => boolean ,
47
51
context ?: CompletionContext
48
52
) : CompletionList {
@@ -190,7 +194,10 @@ export function completionsFromClassList(
190
194
items . push (
191
195
variantItem ( {
192
196
label : `${ variant . name } ${ sep } ` ,
193
- detail : variant . selectors ( ) . join ( ', ' ) ,
197
+ detail : variant
198
+ . selectors ( )
199
+ . map ( ( selector ) => addPixelEquivalentsToMediaQuery ( selector , rootFontSize ) )
200
+ . join ( ', ' ) ,
194
201
textEditText : resultingVariants [ resultingVariants . length - 1 ] + sep ,
195
202
additionalTextEdits :
196
203
shouldSortVariants && resultingVariants . length > 1
@@ -430,10 +437,9 @@ async function provideClassAttributeCompletions(
430
437
end : position ,
431
438
} )
432
439
433
- let matches = matchClassAttributes (
434
- str ,
435
- ( await state . editor . getConfiguration ( document . uri ) ) . tailwindCSS . classAttributes
436
- )
440
+ let settings = ( await state . editor . getConfiguration ( document . uri ) ) . tailwindCSS
441
+
442
+ let matches = matchClassAttributes ( str , settings . classAttributes )
437
443
438
444
if ( matches . length === 0 ) {
439
445
return null
@@ -470,6 +476,7 @@ async function provideClassAttributeCompletions(
470
476
} ,
471
477
end : position ,
472
478
} ,
479
+ settings . rootFontSize ,
473
480
undefined ,
474
481
context
475
482
)
@@ -544,6 +551,7 @@ async function provideCustomClassNameCompletions(
544
551
} ,
545
552
end : position ,
546
553
} ,
554
+ settings . tailwindCSS . rootFontSize ,
547
555
undefined ,
548
556
context
549
557
)
@@ -555,12 +563,13 @@ async function provideCustomClassNameCompletions(
555
563
return null
556
564
}
557
565
558
- function provideAtApplyCompletions (
566
+ async function provideAtApplyCompletions (
559
567
state : State ,
560
568
document : TextDocument ,
561
569
position : Position ,
562
570
context ?: CompletionContext
563
- ) : CompletionList {
571
+ ) : Promise < CompletionList > {
572
+ let settings = ( await state . editor . getConfiguration ( document . uri ) ) . tailwindCSS
564
573
let str = document . getText ( {
565
574
start : { line : Math . max ( position . line - 30 , 0 ) , character : 0 } ,
566
575
end : position ,
@@ -584,6 +593,7 @@ function provideAtApplyCompletions(
584
593
} ,
585
594
end : position ,
586
595
} ,
596
+ settings . rootFontSize ,
587
597
( item ) => {
588
598
if ( item . kind === 9 ) {
589
599
return (
@@ -1318,13 +1328,18 @@ async function provideEmmetCompletions(
1318
1328
const parts = emmetItems . items [ 0 ] . label . split ( '.' )
1319
1329
if ( parts . length < 2 ) return null
1320
1330
1321
- return completionsFromClassList ( state , parts [ parts . length - 1 ] , {
1322
- start : {
1323
- line : position . line ,
1324
- character : position . character - parts [ parts . length - 1 ] . length ,
1331
+ return completionsFromClassList (
1332
+ state ,
1333
+ parts [ parts . length - 1 ] ,
1334
+ {
1335
+ start : {
1336
+ line : position . line ,
1337
+ character : position . character - parts [ parts . length - 1 ] . length ,
1338
+ } ,
1339
+ end : position ,
1325
1340
} ,
1326
- end : position ,
1327
- } )
1341
+ settings . tailwindCSS . rootFontSize
1342
+ )
1328
1343
}
1329
1344
1330
1345
export async function doComplete (
@@ -1444,10 +1459,10 @@ function stringifyDecls(obj: any, settings: Settings): string {
1444
1459
. map ( ( prop ) =>
1445
1460
ensureArray ( obj [ prop ] )
1446
1461
. map ( ( value ) => {
1447
- const px = settings . tailwindCSS . showPixelEquivalents
1448
- ? remToPx ( value , settings . tailwindCSS . rootFontSize )
1449
- : undefined
1450
- return `${ prop } : ${ value } ${ px ? `/* ${ px } */` : '' } ;`
1462
+ if ( settings . tailwindCSS . showPixelEquivalents ) {
1463
+ value = addPixelEquivalentsToValue ( value , settings . tailwindCSS . rootFontSize )
1464
+ }
1465
+ return `${ prop } : ${ value } ;`
1451
1466
} )
1452
1467
. join ( ' ' )
1453
1468
)
0 commit comments