@@ -448,27 +448,184 @@ describe("AutoCompleteAdapter", () => {
448
448
expect ( result . replacementPrefix ) . equals ( "" )
449
449
} )
450
450
451
- it ( "applies changes from TextEdit to text" , async ( ) => {
451
+ describe ( "applies changes from TextEdit to text" , async ( ) => {
452
452
const customRequest = createRequest ( { prefix : "" , position : new Point ( 0 , 10 ) } )
453
453
customRequest . editor . setText ( "foo #align bar" )
454
454
455
- const results = await getSuggestionsMock (
456
- [
457
- {
458
- label : "align" ,
459
- sortText : "a" ,
460
- textEdit : {
461
- range : { start : { line : 0 , character : 4 } , end : { line : 0 , character : 10 } } ,
462
- newText : "hello world" ,
455
+ it ( "applies the change if range is provided" , async ( ) => {
456
+ const results = await getSuggestionsMock (
457
+ [
458
+ {
459
+ label : "align" ,
460
+ sortText : "a" ,
461
+ textEdit : {
462
+ range : { start : { line : 0 , character : 4 } , end : { line : 0 , character : 10 } } ,
463
+ newText : "hello world" ,
464
+ } ,
463
465
} ,
464
- } ,
465
- ] ,
466
- customRequest
467
- )
466
+ ] ,
467
+ customRequest
468
+ )
468
469
469
- expect ( results [ 0 ] . displayText ) . equals ( "align" )
470
- expect ( ( results [ 0 ] as TextSuggestion ) . text ) . equals ( "hello world" )
471
- expect ( results [ 0 ] . replacementPrefix ) . equals ( "#align" )
470
+ expect ( results [ 0 ] . displayText ) . equals ( "align" )
471
+ expect ( ( results [ 0 ] as TextSuggestion ) . text ) . equals ( "hello world" )
472
+ expect ( results [ 0 ] . replacementPrefix ) . equals ( "#align" )
473
+ expect ( ( results [ 0 ] as TextSuggestion ) . customReplacmentPrefix ) . equals ( "#align" )
474
+ } )
475
+
476
+ describe ( "applies the change if shouldReplace is true" , async ( ) => {
477
+ it ( "1" , async ( ) => {
478
+ const results = await getSuggestionsMock (
479
+ [
480
+ {
481
+ label : "align" ,
482
+ sortText : "a" ,
483
+ textEdit : {
484
+ replace : { start : { line : 0 , character : 2 } , end : { line : 0 , character : 5 } } , // used
485
+ insert : { start : { line : 0 , character : 4 } , end : { line : 0 , character : 10 } } ,
486
+ newText : "hello world" ,
487
+ } ,
488
+ } ,
489
+ ] ,
490
+ customRequest ,
491
+ undefined ,
492
+ undefined ,
493
+ true
494
+ )
495
+
496
+ expect ( results [ 0 ] . displayText ) . equals ( "align" )
497
+ expect ( ( results [ 0 ] as TextSuggestion ) . text ) . equals ( "hello world" )
498
+ expect ( results [ 0 ] . replacementPrefix ) . equals ( "o #align" )
499
+ expect ( ( results [ 0 ] as TextSuggestion ) . customReplacmentPrefix ) . equals ( "o #align" )
500
+ } )
501
+
502
+ it ( "2" , async ( ) => {
503
+ const results2 = await getSuggestionsMock (
504
+ [
505
+ {
506
+ label : "align" ,
507
+ sortText : "a" ,
508
+ textEdit : {
509
+ replace : { start : { line : 0 , character : 1 } , end : { line : 0 , character : 5 } } , // used
510
+ insert : { start : { line : 0 , character : 4 } , end : { line : 0 , character : 10 } } ,
511
+ newText : "hello world" ,
512
+ } ,
513
+ } ,
514
+ ] ,
515
+ customRequest ,
516
+ undefined ,
517
+ undefined ,
518
+ true
519
+ )
520
+
521
+ expect ( results2 [ 0 ] . displayText ) . equals ( "align" )
522
+ expect ( ( results2 [ 0 ] as TextSuggestion ) . text ) . equals ( "hello world" )
523
+ expect ( results2 [ 0 ] . replacementPrefix ) . equals ( "oo #align" )
524
+ expect ( ( results2 [ 0 ] as TextSuggestion ) . customReplacmentPrefix ) . equals ( "oo #align" )
525
+ } )
526
+
527
+ it ( "3" , async ( ) => {
528
+ const results3 = await getSuggestionsMock (
529
+ [
530
+ {
531
+ label : "align" ,
532
+ sortText : "a" ,
533
+ textEdit : {
534
+ replace : { start : { line : 0 , character : 3 } , end : { line : 0 , character : 1000 } } , // used
535
+ insert : { start : { line : 0 , character : 4 } , end : { line : 0 , character : 10 } } ,
536
+ newText : "hello world" ,
537
+ } ,
538
+ } ,
539
+ ] ,
540
+ customRequest ,
541
+ undefined ,
542
+ undefined ,
543
+ true
544
+ )
545
+
546
+ expect ( results3 [ 0 ] . displayText ) . equals ( "align" )
547
+ expect ( ( results3 [ 0 ] as TextSuggestion ) . text ) . equals ( "hello world" )
548
+ expect ( results3 [ 0 ] . replacementPrefix ) . equals ( " #align" )
549
+ expect ( ( results3 [ 0 ] as TextSuggestion ) . customReplacmentPrefix ) . equals ( " #align" )
550
+ } )
551
+ } )
552
+
553
+ describe ( "applies the change if shouldReplace is false" , async ( ) => {
554
+ it ( "1" , async ( ) => {
555
+ const results = await getSuggestionsMock (
556
+ [
557
+ {
558
+ label : "align" ,
559
+ sortText : "a" ,
560
+ textEdit : {
561
+ replace : { start : { line : 0 , character : 4 } , end : { line : 0 , character : 10 } } ,
562
+ insert : { start : { line : 0 , character : 2 } , end : { line : 0 , character : 5 } } , // used
563
+ newText : "hello world" ,
564
+ } ,
565
+ } ,
566
+ ] ,
567
+ customRequest ,
568
+ undefined ,
569
+ undefined ,
570
+ false
571
+ )
572
+
573
+ expect ( results [ 0 ] . displayText ) . equals ( "align" )
574
+ expect ( ( results [ 0 ] as TextSuggestion ) . text ) . equals ( "hello world" )
575
+ expect ( results [ 0 ] . replacementPrefix ) . equals ( "o #align" )
576
+ expect ( ( results [ 0 ] as TextSuggestion ) . customReplacmentPrefix ) . equals ( "o #align" )
577
+ } )
578
+
579
+ it ( "2" , async ( ) => {
580
+ const results2 = await getSuggestionsMock (
581
+ [
582
+ {
583
+ label : "align" ,
584
+ sortText : "a" ,
585
+ textEdit : {
586
+ replace : { start : { line : 0 , character : 4 } , end : { line : 0 , character : 10 } } ,
587
+ insert : { start : { line : 0 , character : 1 } , end : { line : 0 , character : 5 } } , // used
588
+ newText : "hello world" ,
589
+ } ,
590
+ } ,
591
+ ] ,
592
+ customRequest ,
593
+ undefined ,
594
+ undefined ,
595
+ false
596
+ )
597
+
598
+ expect ( results2 [ 0 ] . displayText ) . equals ( "align" )
599
+ expect ( ( results2 [ 0 ] as TextSuggestion ) . text ) . equals ( "hello world" )
600
+ expect ( results2 [ 0 ] . replacementPrefix ) . equals ( "oo #align" )
601
+ expect ( ( results2 [ 0 ] as TextSuggestion ) . customReplacmentPrefix ) . equals ( "oo #align" )
602
+ } )
603
+
604
+ it ( "3" , async ( ) => {
605
+ const results3 = await getSuggestionsMock (
606
+ [
607
+ {
608
+ label : "align" ,
609
+ sortText : "a" ,
610
+ textEdit : {
611
+ replace : { start : { line : 0 , character : 4 } , end : { line : 0 , character : 10 } } ,
612
+ insert : { start : { line : 0 , character : 3 } , end : { line : 0 , character : 1000 } } , // used
613
+ newText : "hello world" ,
614
+ } ,
615
+ } ,
616
+ ] ,
617
+ customRequest ,
618
+ undefined ,
619
+ undefined ,
620
+ false
621
+ )
622
+
623
+ expect ( results3 [ 0 ] . displayText ) . equals ( "align" )
624
+ expect ( ( results3 [ 0 ] as TextSuggestion ) . text ) . equals ( "hello world" )
625
+ expect ( results3 [ 0 ] . replacementPrefix ) . equals ( " #align" )
626
+ expect ( ( results3 [ 0 ] as TextSuggestion ) . customReplacmentPrefix ) . equals ( " #align" )
627
+ } )
628
+ } )
472
629
} )
473
630
474
631
it ( "updates the replacementPrefix when the editor text changes" , async ( ) => {
0 commit comments