1
1
import { test } from 'vitest'
2
2
import { withFixture } from '../common'
3
3
4
- withFixture ( 'basic' , ( c ) => {
5
- async function completion ( {
4
+ function buildCompletion ( c ) {
5
+ return async function completion ( {
6
6
lang,
7
7
text,
8
8
position,
@@ -19,6 +19,10 @@ withFixture('basic', (c) => {
19
19
context,
20
20
} )
21
21
}
22
+ }
23
+
24
+ withFixture ( 'basic' , ( c ) => {
25
+ let completion = buildCompletion ( c )
22
26
23
27
async function expectCompletions ( { expect, lang, text, position, settings } ) {
24
28
let result = await completion ( { lang, text, position, settings } )
@@ -148,7 +152,7 @@ withFixture('basic', (c) => {
148
152
expect ( result ) . toBe ( null )
149
153
} )
150
154
151
- test ( 'classRegex matching empty string' , async ( { expect } ) => {
155
+ test . concurrent ( 'classRegex matching empty string' , async ( { expect } ) => {
152
156
try {
153
157
let result = await completion ( {
154
158
text : "let _ = ''" ,
@@ -203,24 +207,87 @@ withFixture('basic', (c) => {
203
207
} )
204
208
} )
205
209
206
- withFixture ( 'overrides-variants' , ( c ) => {
207
- async function completion ( {
208
- lang,
209
- text,
210
- position,
211
- context = {
212
- triggerKind : 1 ,
213
- } ,
214
- settings,
215
- } ) {
216
- let textDocument = await c . openDocument ( { text, lang, settings } )
210
+ withFixture ( 'basic' , ( c ) => {
211
+ let completion = buildCompletion ( c )
217
212
218
- return c . sendRequest ( 'textDocument/completion' , {
219
- textDocument,
220
- position,
221
- context,
213
+ test ( 'Completions have default pixel equivalents (1rem == 16px)' , async ( { expect } ) => {
214
+ let result = await completion ( {
215
+ lang : 'html' ,
216
+ text : '<div class=""></div>' ,
217
+ position : { line : 0 , character : 12 } ,
222
218
} )
223
- }
219
+
220
+ let item = result . items . find ( ( item ) => item . label === 'text-sm' )
221
+ let resolved = await c . sendRequest ( 'completionItem/resolve' , item )
222
+
223
+ expect ( resolved ) . toEqual ( {
224
+ ...item ,
225
+ detail : 'font-size: 0.875rem/* 14px */; line-height: 1.25rem/* 20px */;' ,
226
+ documentation : {
227
+ kind : 'markdown' ,
228
+ value :
229
+ '```css\n.text-sm {\n font-size: 0.875rem/* 14px */;\n line-height: 1.25rem/* 20px */;\n}\n```' ,
230
+ } ,
231
+ } )
232
+ } )
233
+ } )
234
+
235
+ withFixture ( 'basic' , ( c ) => {
236
+ let completion = buildCompletion ( c )
237
+
238
+ test ( 'Completions have customizable pixel equivalents (1rem == 10px)' , async ( { expect } ) => {
239
+ await c . updateSettings ( {
240
+ tailwindCSS : {
241
+ rootFontSize : 10 ,
242
+ } ,
243
+ } )
244
+
245
+ let result = await completion ( {
246
+ lang : 'html' ,
247
+ text : '<div class=""></div>' ,
248
+ position : { line : 0 , character : 12 } ,
249
+ } )
250
+
251
+ let item = result . items . find ( ( item ) => item . label === 'text-sm' )
252
+
253
+ let resolved = await c . sendRequest ( 'completionItem/resolve' , item )
254
+
255
+ expect ( resolved ) . toEqual ( {
256
+ ...item ,
257
+ detail : 'font-size: 0.875rem/* 8.75px */; line-height: 1.25rem/* 12.5px */;' ,
258
+ documentation : {
259
+ kind : 'markdown' ,
260
+ value :
261
+ '```css\n.text-sm {\n font-size: 0.875rem/* 8.75px */;\n line-height: 1.25rem/* 12.5px */;\n}\n```' ,
262
+ } ,
263
+ } )
264
+ } )
265
+ } )
266
+
267
+ withFixture ( 'basic' , ( c ) => {
268
+ let completion = buildCompletion ( c )
269
+
270
+ test ( 'Completions have color equivalents presented as hex' , async ( { expect } ) => {
271
+ let result = await completion ( {
272
+ lang : 'html' ,
273
+ text : '<div class=""></div>' ,
274
+ position : { line : 0 , character : 12 } ,
275
+ } )
276
+
277
+ let item = result . items . find ( ( item ) => item . label === 'bg-red-500' )
278
+
279
+ let resolved = await c . sendRequest ( 'completionItem/resolve' , item )
280
+
281
+ expect ( resolved ) . toEqual ( {
282
+ ...item ,
283
+ detail : '--tw-bg-opacity: 1; background-color: rgb(239 68 68 / var(--tw-bg-opacity));' ,
284
+ documentation : '#ef4444' ,
285
+ } )
286
+ } )
287
+ } )
288
+
289
+ withFixture ( 'overrides-variants' , ( c ) => {
290
+ let completion = buildCompletion ( c )
224
291
225
292
test . concurrent (
226
293
'duplicate variant + value pairs do not produce multiple completions' ,
@@ -236,23 +303,7 @@ withFixture('overrides-variants', (c) => {
236
303
} )
237
304
238
305
withFixture ( 'v4/basic' , ( c ) => {
239
- async function completion ( {
240
- lang,
241
- text,
242
- position,
243
- context = {
244
- triggerKind : 1 ,
245
- } ,
246
- settings,
247
- } ) {
248
- let textDocument = await c . openDocument ( { text, lang, settings } )
249
-
250
- return c . sendRequest ( 'textDocument/completion' , {
251
- textDocument,
252
- position,
253
- context,
254
- } )
255
- }
306
+ let completion = buildCompletion ( c )
256
307
257
308
async function expectCompletions ( { expect, lang, text, position, settings } ) {
258
309
let result = await completion ( { lang, text, position, settings } )
@@ -439,11 +490,65 @@ withFixture('v4/basic', (c) => {
439
490
440
491
expect ( resolved ) . toEqual ( {
441
492
...item ,
442
- detail : 'text-transform: uppercase' ,
493
+ detail : 'text-transform: uppercase; ' ,
443
494
documentation : {
444
495
kind : 'markdown' ,
445
496
value : '```css\n.uppercase {\n text-transform: uppercase;\n}\n```' ,
446
497
} ,
447
498
} )
448
499
} )
449
500
} )
501
+
502
+ withFixture ( 'v4/basic' , ( c ) => {
503
+ let completion = buildCompletion ( c )
504
+
505
+ test ( 'Completions have customizable pixel equivalents (1rem == 10px)' , async ( { expect } ) => {
506
+ await c . updateSettings ( {
507
+ tailwindCSS : {
508
+ rootFontSize : 10 ,
509
+ } ,
510
+ } )
511
+
512
+ let result = await completion ( {
513
+ lang : 'html' ,
514
+ text : '<div class=""></div>' ,
515
+ position : { line : 0 , character : 12 } ,
516
+ } )
517
+
518
+ let item = result . items . find ( ( item ) => item . label === 'text-sm' )
519
+
520
+ let resolved = await c . sendRequest ( 'completionItem/resolve' , item )
521
+
522
+ expect ( resolved ) . toEqual ( {
523
+ ...item ,
524
+ detail : 'font-size: 0.875rem/* 8.75px */; line-height: 1.25rem/* 12.5px */;' ,
525
+ documentation : {
526
+ kind : 'markdown' ,
527
+ value :
528
+ '```css\n.text-sm {\n font-size: 0.875rem/* 8.75px */;\n line-height: 1.25rem/* 12.5px */;\n}\n```' ,
529
+ } ,
530
+ } )
531
+ } )
532
+ } )
533
+
534
+ withFixture ( 'v4/basic' , ( c ) => {
535
+ let completion = buildCompletion ( c )
536
+
537
+ test ( 'Completions have color equivalents presented as hex' , async ( { expect } ) => {
538
+ let result = await completion ( {
539
+ lang : 'html' ,
540
+ text : '<div class=""></div>' ,
541
+ position : { line : 0 , character : 12 } ,
542
+ } )
543
+
544
+ let item = result . items . find ( ( item ) => item . label === 'bg-red-500' )
545
+
546
+ let resolved = await c . sendRequest ( 'completionItem/resolve' , item )
547
+
548
+ expect ( resolved ) . toEqual ( {
549
+ ...item ,
550
+ detail : 'background-color: #ef4444;' ,
551
+ documentation : '#ef4444' ,
552
+ } )
553
+ } )
554
+ } )
0 commit comments