@@ -47,8 +47,8 @@ export function completionsFromClassList(
47
47
document ?: TextDocument ,
48
48
context ?: CompletionContext
49
49
) : CompletionList {
50
- let classNames = classList . split ( / [ \s + ] / )
51
- const partialClassName = classNames [ classNames . length - 1 ]
50
+ let classNamesAndWhitespace = classList . split ( / ( \s + ) / )
51
+ const partialClassName = classNamesAndWhitespace [ classNamesAndWhitespace . 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 : {
61
- ... classListRange . start ,
62
- character : classListRange . end . character - partialClassName . length ,
63
- } ,
60
+ start : document . positionAt (
61
+ document . offsetAt ( classListRange . start ) +
62
+ classNamesAndWhitespace . slice ( 0 , classNamesAndWhitespace . length - 1 ) . join ( '' ) . length
63
+ ) ,
64
64
}
65
65
66
66
if ( state . jit ) {
@@ -201,10 +201,12 @@ export function completionsFromClassList(
201
201
resultingVariants . slice ( 0 , resultingVariants . length - 1 ) . join ( sep ) +
202
202
sep ,
203
203
range : {
204
- start : {
205
- ...classListRange . start ,
206
- character : classListRange . end . character - partialClassName . length ,
207
- } ,
204
+ start : document . positionAt (
205
+ document . offsetAt ( classListRange . start ) +
206
+ classNamesAndWhitespace
207
+ . slice ( 0 , classNamesAndWhitespace . length - 1 )
208
+ . join ( '' ) . length
209
+ ) ,
208
210
end : {
209
211
...replacementRange . start ,
210
212
character : replacementRange . start . character ,
@@ -427,16 +429,6 @@ function ensureTriggerCharacterIsIncluded(
427
429
context . triggerKind === 2 && // CompletionTriggerKind.TriggerCharacter
428
430
text . slice ( - 1 ) !== context . triggerCharacter
429
431
) {
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
432
return `${ text . slice ( 0 , text . length - 1 ) } ${ context . triggerCharacter } `
441
433
}
442
434
return text
@@ -448,8 +440,9 @@ async function provideClassAttributeCompletions(
448
440
position : Position ,
449
441
context ?: CompletionContext
450
442
) : Promise < CompletionList > {
443
+ let startOffset = Math . max ( 0 , document . offsetAt ( position ) - 1000 )
451
444
let str = document . getText ( {
452
- start : document . positionAt ( Math . max ( 0 , document . offsetAt ( position ) - 1000 ) ) ,
445
+ start : document . positionAt ( startOffset ) ,
453
446
end : position ,
454
447
} )
455
448
@@ -466,11 +459,13 @@ async function provideClassAttributeCompletions(
466
459
467
460
let match = matches [ matches . length - 1 ]
468
461
469
- const lexer =
462
+ let lexer =
470
463
match [ 0 ] [ 0 ] === ':' || ( match [ 1 ] . startsWith ( '[' ) && match [ 1 ] . endsWith ( ']' ) )
471
464
? getComputedClassAttributeLexer ( )
472
465
: getClassAttributeLexer ( )
473
- lexer . reset ( str . substr ( match . index + match [ 0 ] . length - 1 ) )
466
+ let attributeOffset = match . index + match [ 0 ] . length - 1
467
+ let attributeText = str . substr ( attributeOffset )
468
+ lexer . reset ( attributeText )
474
469
475
470
try {
476
471
let tokens = Array . from ( lexer )
@@ -489,10 +484,9 @@ async function provideClassAttributeCompletions(
489
484
state ,
490
485
classList ,
491
486
{
492
- start : {
493
- line : position . line ,
494
- character : position . character - classList . length ,
495
- } ,
487
+ start : document . positionAt (
488
+ startOffset + attributeOffset + ( attributeText . length - classList . length )
489
+ ) ,
496
490
end : position ,
497
491
} ,
498
492
undefined ,
0 commit comments