@@ -43,12 +43,12 @@ export function completionsFromClassList(
43
43
state : State ,
44
44
classList : string ,
45
45
classListRange : Range ,
46
- document : TextDocument ,
47
46
filter ?: ( item : CompletionItem ) => boolean ,
47
+ document ?: TextDocument ,
48
48
context ?: CompletionContext
49
49
) : CompletionList {
50
- let classNamesAndWhitespace = classList . split ( / ( \s + ) / )
51
- const partialClassName = classNamesAndWhitespace [ classNamesAndWhitespace . length - 1 ]
50
+ let classNames = classList . split ( / [ \s + ] / )
51
+ const partialClassName = classNames [ classNames . length - 1 ]
52
52
let sep = state . separator
53
53
let parts = partialClassName . split ( sep )
54
54
let subset : any
@@ -57,10 +57,10 @@ export function completionsFromClassList(
57
57
58
58
let replacementRange = {
59
59
...classListRange ,
60
- start : document . positionAt (
61
- document . offsetAt ( classListRange . start ) +
62
- classNamesAndWhitespace . slice ( 0 , classNamesAndWhitespace . length - 1 ) . join ( '' ) . length
63
- ) ,
60
+ start : {
61
+ ... classListRange . start ,
62
+ character : classListRange . end . character - partialClassName . length ,
63
+ } ,
64
64
}
65
65
66
66
if ( state . jit ) {
@@ -201,12 +201,10 @@ export function completionsFromClassList(
201
201
resultingVariants . slice ( 0 , resultingVariants . length - 1 ) . join ( sep ) +
202
202
sep ,
203
203
range : {
204
- start : document . positionAt (
205
- document . offsetAt ( classListRange . start ) +
206
- classNamesAndWhitespace
207
- . slice ( 0 , classNamesAndWhitespace . length - 1 )
208
- . join ( '' ) . length
209
- ) ,
204
+ start : {
205
+ ...classListRange . start ,
206
+ character : classListRange . end . character - partialClassName . length ,
207
+ } ,
210
208
end : {
211
209
...replacementRange . start ,
212
210
character : replacementRange . start . character ,
@@ -414,40 +412,17 @@ export function completionsFromClassList(
414
412
)
415
413
}
416
414
417
- // This might be a VS Code bug?
418
- // The trigger character is not included in the document text
419
- function ensureTriggerCharacterIsIncluded (
420
- text : string ,
421
- document : TextDocument ,
422
- position : Position ,
423
- context ?: CompletionContext
424
- ) : string {
425
- if ( ! context ) {
426
- return text
427
- }
428
- if (
429
- context . triggerKind === 2 && // CompletionTriggerKind.TriggerCharacter
430
- text . slice ( - 1 ) !== context . triggerCharacter
431
- ) {
432
- return `${ text . slice ( 0 , text . length - 1 ) } ${ context . triggerCharacter } `
433
- }
434
- return text
435
- }
436
-
437
415
async function provideClassAttributeCompletions (
438
416
state : State ,
439
417
document : TextDocument ,
440
418
position : Position ,
441
419
context ?: CompletionContext
442
420
) : Promise < CompletionList > {
443
- let startOffset = Math . max ( 0 , document . offsetAt ( position ) - 1000 )
444
421
let str = document . getText ( {
445
- start : document . positionAt ( startOffset ) ,
422
+ start : document . positionAt ( Math . max ( 0 , document . offsetAt ( position ) - 1000 ) ) ,
446
423
end : position ,
447
424
} )
448
425
449
- str = ensureTriggerCharacterIsIncluded ( str , document , position , context )
450
-
451
426
let matches = matchClassAttributes (
452
427
str ,
453
428
( await state . editor . getConfiguration ( document . uri ) ) . tailwindCSS . classAttributes
@@ -459,13 +434,11 @@ async function provideClassAttributeCompletions(
459
434
460
435
let match = matches [ matches . length - 1 ]
461
436
462
- let lexer =
437
+ const lexer =
463
438
match [ 0 ] [ 0 ] === ':' || ( match [ 1 ] . startsWith ( '[' ) && match [ 1 ] . endsWith ( ']' ) )
464
439
? getComputedClassAttributeLexer ( )
465
440
: getClassAttributeLexer ( )
466
- let attributeOffset = match . index + match [ 0 ] . length - 1
467
- let attributeText = str . substr ( attributeOffset )
468
- lexer . reset ( attributeText )
441
+ lexer . reset ( str . substr ( match . index + match [ 0 ] . length - 1 ) )
469
442
470
443
try {
471
444
let tokens = Array . from ( lexer )
@@ -484,13 +457,14 @@ async function provideClassAttributeCompletions(
484
457
state ,
485
458
classList ,
486
459
{
487
- start : document . positionAt (
488
- startOffset + attributeOffset + ( attributeText . length - classList . length )
489
- ) ,
460
+ start : {
461
+ line : position . line ,
462
+ character : position . character - classList . length ,
463
+ } ,
490
464
end : position ,
491
465
} ,
492
- document ,
493
466
undefined ,
467
+ document ,
494
468
context
495
469
)
496
470
}
@@ -553,18 +527,13 @@ async function provideCustomClassNameCompletions(
553
527
classList = containerMatch [ 1 ] . substr ( 0 , cursor - matchStart )
554
528
}
555
529
556
- return completionsFromClassList (
557
- state ,
558
- classList ,
559
- {
560
- start : {
561
- line : position . line ,
562
- character : position . character - classList . length ,
563
- } ,
564
- end : position ,
530
+ return completionsFromClassList ( state , classList , {
531
+ start : {
532
+ line : position . line ,
533
+ character : position . character - classList . length ,
565
534
} ,
566
- document
567
- )
535
+ end : position ,
536
+ } )
568
537
}
569
538
}
570
539
} catch ( _ ) { }
@@ -576,16 +545,13 @@ async function provideCustomClassNameCompletions(
576
545
function provideAtApplyCompletions (
577
546
state : State ,
578
547
document : TextDocument ,
579
- position : Position ,
580
- context ?: CompletionContext
548
+ position : Position
581
549
) : CompletionList {
582
550
let str = document . getText ( {
583
551
start : { line : Math . max ( position . line - 30 , 0 ) , character : 0 } ,
584
552
end : position ,
585
553
} )
586
554
587
- str = ensureTriggerCharacterIsIncluded ( str , document , position , context )
588
-
589
555
const match = findLast ( / @ a p p l y \s + (?< classList > [ ^ ; } ] * ) $ / gi, str )
590
556
591
557
if ( match === null ) {
@@ -604,7 +570,6 @@ function provideAtApplyCompletions(
604
570
} ,
605
571
end : position ,
606
572
} ,
607
- document ,
608
573
( item ) => {
609
574
if ( item . kind === 9 ) {
610
575
return (
@@ -631,7 +596,7 @@ async function provideClassNameCompletions(
631
596
context ?: CompletionContext
632
597
) : Promise < CompletionList > {
633
598
if ( isCssContext ( state , document , position ) ) {
634
- return provideAtApplyCompletions ( state , document , position , context )
599
+ return provideAtApplyCompletions ( state , document , position )
635
600
}
636
601
637
602
if ( isHtmlContext ( state , document , position ) || isJsxContext ( state , document , position ) ) {
@@ -1338,18 +1303,13 @@ async function provideEmmetCompletions(
1338
1303
const parts = emmetItems . items [ 0 ] . label . split ( '.' )
1339
1304
if ( parts . length < 2 ) return null
1340
1305
1341
- return completionsFromClassList (
1342
- state ,
1343
- parts [ parts . length - 1 ] ,
1344
- {
1345
- start : {
1346
- line : position . line ,
1347
- character : position . character - parts [ parts . length - 1 ] . length ,
1348
- } ,
1349
- end : position ,
1306
+ return completionsFromClassList ( state , parts [ parts . length - 1 ] , {
1307
+ start : {
1308
+ line : position . line ,
1309
+ character : position . character - parts [ parts . length - 1 ] . length ,
1350
1310
} ,
1351
- document
1352
- )
1311
+ end : position ,
1312
+ } )
1353
1313
}
1354
1314
1355
1315
export async function doComplete (
0 commit comments