@@ -412,6 +412,36 @@ export function completionsFromClassList(
412
412
)
413
413
}
414
414
415
+ // This might be a VS Code bug?
416
+ // The trigger character is not included in the document text
417
+ function ensureTriggerCharacterIsIncluded (
418
+ text : string ,
419
+ document : TextDocument ,
420
+ position : Position ,
421
+ context ?: CompletionContext
422
+ ) : string {
423
+ if ( ! context ) {
424
+ return text
425
+ }
426
+ if (
427
+ context . triggerKind === 2 && // CompletionTriggerKind.TriggerCharacter
428
+ text . slice ( - 1 ) !== context . triggerCharacter
429
+ ) {
430
+ let nextChar = document . getText ( {
431
+ start : position ,
432
+ end : document . positionAt ( document . offsetAt ( position ) + 1 ) ,
433
+ } )
434
+ // If there's a next char (i.e. we're not at the end of the document)
435
+ // then it will be included instead of the trigger character, so we replace it.
436
+ // Otherwise we just append.
437
+ if ( nextChar . length === 0 ) {
438
+ return `${ text } ${ context . triggerCharacter } `
439
+ }
440
+ return `${ text . slice ( 0 , text . length - 1 ) } ${ context . triggerCharacter } `
441
+ }
442
+ return text
443
+ }
444
+
415
445
async function provideClassAttributeCompletions (
416
446
state : State ,
417
447
document : TextDocument ,
@@ -423,6 +453,8 @@ async function provideClassAttributeCompletions(
423
453
end : position ,
424
454
} )
425
455
456
+ str = ensureTriggerCharacterIsIncluded ( str , document , position , context )
457
+
426
458
let matches = matchClassAttributes (
427
459
str ,
428
460
( await state . editor . getConfiguration ( document . uri ) ) . tailwindCSS . classAttributes
@@ -545,13 +577,16 @@ async function provideCustomClassNameCompletions(
545
577
function provideAtApplyCompletions (
546
578
state : State ,
547
579
document : TextDocument ,
548
- position : Position
580
+ position : Position ,
581
+ context ?: CompletionContext
549
582
) : CompletionList {
550
583
let str = document . getText ( {
551
584
start : { line : Math . max ( position . line - 30 , 0 ) , character : 0 } ,
552
585
end : position ,
553
586
} )
554
587
588
+ str = ensureTriggerCharacterIsIncluded ( str , document , position , context )
589
+
555
590
const match = findLast ( / @ a p p l y \s + (?< classList > [ ^ ; } ] * ) $ / gi, str )
556
591
557
592
if ( match === null ) {
@@ -596,7 +631,7 @@ async function provideClassNameCompletions(
596
631
context ?: CompletionContext
597
632
) : Promise < CompletionList > {
598
633
if ( isCssContext ( state , document , position ) ) {
599
- return provideAtApplyCompletions ( state , document , position )
634
+ return provideAtApplyCompletions ( state , document , position , context )
600
635
}
601
636
602
637
if ( isHtmlContext ( state , document , position ) || isJsxContext ( state , document , position ) ) {
0 commit comments