@@ -233,8 +233,7 @@ describe("AutoCompleteAdapter", () => {
233
233
it ( "converts LSP CompletionItem array to AutoComplete Suggestions array" , async ( ) => {
234
234
const customRequest = createRequest ( { prefix : "" , position : new Point ( 0 , 10 ) } )
235
235
customRequest . editor . setText ( "foo #align bar" )
236
- sinon . stub ( server . connection , "completion" ) . resolves ( items )
237
- const results = await autoCompleteAdapter . getSuggestions ( server , customRequest )
236
+ const results = await getSuggestionsMock ( items , customRequest )
238
237
239
238
expect ( results . length ) . equals ( items . length )
240
239
expect ( results [ 0 ] . displayText ) . equals ( "align" )
@@ -263,8 +262,7 @@ describe("AutoCompleteAdapter", () => {
263
262
} )
264
263
265
264
it ( "respects onDidConvertCompletionItem" , async ( ) => {
266
- sinon . stub ( server . connection , "completion" ) . resolves ( [ { label : "label" } ] as CompletionItem [ ] )
267
- const results = await autoCompleteAdapter . getSuggestions ( server , createRequest ( { } ) , ( c , a , r ) => {
265
+ const results = await getSuggestionsMock ( [ { label : "label" } ] , createRequest ( { } ) , ( c , a , r ) => {
268
266
; ( a as ac . TextSuggestion ) . text = c . label + " ok"
269
267
a . displayText = r . scopeDescriptor . getScopesArray ( ) [ 0 ]
270
268
} )
@@ -275,23 +273,26 @@ describe("AutoCompleteAdapter", () => {
275
273
} )
276
274
277
275
it ( "converts empty array into an empty AutoComplete Suggestions array" , async ( ) => {
278
- sinon . stub ( server . connection , "completion" ) . resolves ( [ ] )
279
- const results = await autoCompleteAdapter . getSuggestions ( server , createRequest ( { } ) )
276
+ const results = await getSuggestionsMock ( [ ] , createRequest ( { } ) )
280
277
expect ( results . length ) . equals ( 0 )
281
278
} )
282
279
283
280
it ( "converts LSP CompletionItem to AutoComplete Suggestion without textEdit" , async ( ) => {
284
- sinon . stub ( server . connection , "completion" ) . resolves ( [
285
- {
286
- label : "label" ,
287
- insertText : "insert" ,
288
- filterText : "filter" ,
289
- kind : ls . CompletionItemKind . Keyword ,
290
- detail : "keyword" ,
291
- documentation : "a truly useful keyword" ,
292
- } ,
293
- ] as CompletionItem [ ] )
294
- const result = ( await autoCompleteAdapter . getSuggestions ( server , createRequest ( { } ) ) ) [ 0 ]
281
+ const result = (
282
+ await getSuggestionsMock (
283
+ [
284
+ {
285
+ label : "label" ,
286
+ insertText : "insert" ,
287
+ filterText : "filter" ,
288
+ kind : ls . CompletionItemKind . Keyword ,
289
+ detail : "keyword" ,
290
+ documentation : "a truly useful keyword" ,
291
+ } ,
292
+ ] ,
293
+ createRequest ( { } )
294
+ )
295
+ ) [ 0 ]
295
296
expect ( ( result as TextSuggestion ) . text ) . equals ( "insert" )
296
297
expect ( result . displayText ) . equals ( "label" )
297
298
expect ( result . type ) . equals ( "keyword" )
@@ -307,22 +308,26 @@ describe("AutoCompleteAdapter", () => {
307
308
activatedManually : false ,
308
309
} )
309
310
customRequest . editor . setText ( "foo #label bar" )
310
- sinon . stub ( server . connection , "completion" ) . resolves ( [
311
- {
312
- label : "label" ,
313
- insertText : "insert" ,
314
- filterText : "filter" ,
315
- kind : ls . CompletionItemKind . Variable ,
316
- detail : "number" ,
317
- documentation : "a truly useful variable" ,
318
- textEdit : {
319
- range : { start : { line : 0 , character : 4 } , end : { line : 0 , character : 10 } } ,
320
- newText : "newText" ,
321
- } ,
322
- } ,
323
- ] as CompletionItem [ ] )
324
311
325
- const result = ( await autoCompleteAdapter . getSuggestions ( server , customRequest ) ) [ 0 ]
312
+ const result = (
313
+ await getSuggestionsMock (
314
+ [
315
+ {
316
+ label : "label" ,
317
+ insertText : "insert" ,
318
+ filterText : "filter" ,
319
+ kind : ls . CompletionItemKind . Variable ,
320
+ detail : "number" ,
321
+ documentation : "a truly useful variable" ,
322
+ textEdit : {
323
+ range : { start : { line : 0 , character : 4 } , end : { line : 0 , character : 10 } } ,
324
+ newText : "newText" ,
325
+ } ,
326
+ } ,
327
+ ] ,
328
+ customRequest
329
+ )
330
+ ) [ 0 ]
326
331
expect ( result . displayText ) . equals ( "label" )
327
332
expect ( result . type ) . equals ( "variable" )
328
333
expect ( result . rightLabel ) . equals ( "number" )
@@ -333,19 +338,20 @@ describe("AutoCompleteAdapter", () => {
333
338
} )
334
339
335
340
it ( "converts LSP CompletionItem with insertText and filterText to AutoComplete Suggestion" , async ( ) => {
336
- sinon . stub ( server . connection , "completion" ) . resolves ( [
337
- {
338
- label : "label" ,
339
- insertText : "insert" ,
340
- filterText : "filter" ,
341
- kind : ls . CompletionItemKind . Keyword ,
342
- detail : "detail" ,
343
- documentation : "a very exciting keyword" ,
344
- } ,
345
- { label : "filteredOut" , filterText : "nop" } ,
346
- ] as CompletionItem [ ] )
347
-
348
- const results = await autoCompleteAdapter . getSuggestions ( server , createRequest ( { prefix : "fil" } ) )
341
+ const results = await getSuggestionsMock (
342
+ [
343
+ {
344
+ label : "label" ,
345
+ insertText : "insert" ,
346
+ filterText : "filter" ,
347
+ kind : ls . CompletionItemKind . Keyword ,
348
+ detail : "detail" ,
349
+ documentation : "a very exciting keyword" ,
350
+ } ,
351
+ { label : "filteredOut" , filterText : "nop" } ,
352
+ ] ,
353
+ createRequest ( { prefix : "fil" } )
354
+ )
349
355
expect ( results . length ) . equals ( 1 )
350
356
351
357
const result = results [ 0 ]
@@ -358,51 +364,50 @@ describe("AutoCompleteAdapter", () => {
358
364
} )
359
365
360
366
it ( "converts LSP CompletionItem with missing documentation to AutoComplete Suggestion" , async ( ) => {
361
- sinon . stub ( server . connection , "completion" ) . resolves ( [ { label : "label" , detail : "detail" } ] as CompletionItem [ ] )
362
-
363
- const result = ( await autoCompleteAdapter . getSuggestions ( server , createRequest ( { } ) ) ) [ 0 ]
367
+ const result = ( await getSuggestionsMock ( [ { label : "label" , detail : "detail" } ] , createRequest ( { } ) ) ) [ 0 ]
364
368
expect ( result . rightLabel ) . equals ( "detail" )
365
369
expect ( result . description ) . equals ( undefined )
366
370
expect ( result . descriptionMarkdown ) . equals ( undefined )
367
371
} )
368
372
369
373
it ( "converts LSP CompletionItem with markdown documentation to AutoComplete Suggestion" , async ( ) => {
370
- sinon
371
- . stub ( server . connection , "completion" )
372
- . resolves ( [
373
- { label : "label" , detail : "detail" , documentation : { value : "Some *markdown*" , kind : "markdown" } } ,
374
- ] as CompletionItem [ ] )
375
-
376
- const result = ( await autoCompleteAdapter . getSuggestions ( server , createRequest ( { } ) ) ) [ 0 ]
374
+ const result = (
375
+ await getSuggestionsMock (
376
+ [ { label : "label" , detail : "detail" , documentation : { value : "Some *markdown*" , kind : "markdown" } } ] ,
377
+ createRequest ( { } )
378
+ )
379
+ ) [ 0 ]
377
380
expect ( result . rightLabel ) . equals ( "detail" )
378
381
expect ( result . description ) . equals ( undefined )
379
382
expect ( result . descriptionMarkdown ) . equals ( "Some *markdown*" )
380
383
} )
381
384
382
385
it ( "converts LSP CompletionItem with plaintext documentation to AutoComplete Suggestion" , async ( ) => {
383
- sinon
384
- . stub ( server . connection , "completion" )
385
- . resolves ( [
386
- { label : "label" , detail : "detail" , documentation : { value : "Some plain text" , kind : "plaintext" } } ,
387
- ] as CompletionItem [ ] )
388
-
389
- const result = ( await autoCompleteAdapter . getSuggestions ( server , createRequest ( { } ) ) ) [ 0 ]
386
+ const result = (
387
+ await getSuggestionsMock (
388
+ [ { label : "label" , detail : "detail" , documentation : { value : "Some plain text" , kind : "plaintext" } } ] ,
389
+ createRequest ( { } )
390
+ )
391
+ ) [ 0 ]
390
392
expect ( result . rightLabel ) . equals ( "detail" )
391
393
expect ( result . description ) . equals ( "Some plain text" )
392
394
expect ( result . descriptionMarkdown ) . equals ( undefined )
393
395
} )
394
396
395
397
it ( "converts LSP CompletionItem without insertText or filterText to AutoComplete Suggestion" , async ( ) => {
396
- sinon . stub ( server . connection , "completion" ) . resolves ( [
397
- {
398
- label : "label" ,
399
- kind : ls . CompletionItemKind . Keyword ,
400
- detail : "detail" ,
401
- documentation : "A very useful keyword" ,
402
- } ,
403
- ] as CompletionItem [ ] )
404
-
405
- const result = ( await autoCompleteAdapter . getSuggestions ( server , createRequest ( { } ) ) ) [ 0 ]
398
+ const result = (
399
+ await getSuggestionsMock (
400
+ [
401
+ {
402
+ label : "label" ,
403
+ kind : ls . CompletionItemKind . Keyword ,
404
+ detail : "detail" ,
405
+ documentation : "A very useful keyword" ,
406
+ } ,
407
+ ] ,
408
+ createRequest ( { } )
409
+ )
410
+ ) [ 0 ]
406
411
expect ( ( result as TextSuggestion ) . text ) . equals ( "label" )
407
412
expect ( result . displayText ) . equals ( "label" )
408
413
expect ( result . type ) . equals ( "keyword" )
@@ -412,9 +417,7 @@ describe("AutoCompleteAdapter", () => {
412
417
} )
413
418
414
419
it ( "does not do anything if there is no textEdit" , async ( ) => {
415
- sinon . stub ( server . connection , "completion" ) . resolves ( [ { label : "" , filterText : "rep" } ] as CompletionItem [ ] )
416
-
417
- const result = ( await autoCompleteAdapter . getSuggestions ( server , createRequest ( { prefix : "rep" } ) ) ) [ 0 ]
420
+ const result = ( await getSuggestionsMock ( [ { label : "" , filterText : "rep" } ] , createRequest ( { prefix : "rep" } ) ) ) [ 0 ]
418
421
expect ( ( result as TextSuggestion ) . text ) . equals ( "" )
419
422
expect ( result . displayText ) . equals ( "" )
420
423
expect ( result . replacementPrefix ) . equals ( "" )
@@ -423,17 +426,20 @@ describe("AutoCompleteAdapter", () => {
423
426
it ( "applies changes from TextEdit to text" , async ( ) => {
424
427
const customRequest = createRequest ( { prefix : "" , position : new Point ( 0 , 10 ) } )
425
428
customRequest . editor . setText ( "foo #align bar" )
426
- sinon . stub ( server . connection , "completion" ) . resolves ( [
427
- {
428
- label : "align" ,
429
- sortText : "a" ,
430
- textEdit : {
431
- range : { start : { line : 0 , character : 4 } , end : { line : 0 , character : 10 } } ,
432
- newText : "hello world" ,
429
+
430
+ const results = await getSuggestionsMock (
431
+ [
432
+ {
433
+ label : "align" ,
434
+ sortText : "a" ,
435
+ textEdit : {
436
+ range : { start : { line : 0 , character : 4 } , end : { line : 0 , character : 10 } } ,
437
+ newText : "hello world" ,
438
+ } ,
433
439
} ,
434
- } ,
435
- ] as CompletionItem [ ] )
436
- const results = await autoCompleteAdapter . getSuggestions ( server , customRequest )
440
+ ] ,
441
+ customRequest
442
+ )
437
443
438
444
expect ( results [ 0 ] . displayText ) . equals ( "align" )
439
445
expect ( ( results [ 0 ] as TextSuggestion ) . text ) . equals ( "hello world" )
@@ -443,7 +449,7 @@ describe("AutoCompleteAdapter", () => {
443
449
it ( "updates the replacementPrefix when the editor text changes" , async ( ) => {
444
450
const customRequest = createRequest ( { prefix : "" , position : new Point ( 0 , 8 ) } )
445
451
customRequest . editor . setText ( "foo #ali bar" )
446
- sinon . stub ( server . connection , "completion" ) . resolves ( [
452
+ const items = [
447
453
{
448
454
label : "align" ,
449
455
sortText : "a" ,
@@ -452,9 +458,9 @@ describe("AutoCompleteAdapter", () => {
452
458
newText : "hello world" ,
453
459
} ,
454
460
} ,
455
- ] as CompletionItem [ ] )
461
+ ]
456
462
457
- let result = ( await autoCompleteAdapter . getSuggestions ( server , customRequest ) ) [ 0 ]
463
+ let result = ( await getSuggestionsMock ( items , customRequest ) ) [ 0 ]
458
464
expect ( result . replacementPrefix ) . equals ( "#ali" )
459
465
460
466
customRequest . editor . setTextInBufferRange (
@@ -465,7 +471,7 @@ describe("AutoCompleteAdapter", () => {
465
471
"g"
466
472
)
467
473
customRequest . bufferPosition = new Point ( 0 , 9 )
468
- result = ( await autoCompleteAdapter . getSuggestions ( server , customRequest ) ) [ 0 ]
474
+ result = ( await getSuggestionsMock ( items , customRequest ) ) [ 0 ]
469
475
expect ( result . replacementPrefix ) . equals ( "#alig" )
470
476
471
477
customRequest . editor . setTextInBufferRange (
@@ -476,7 +482,7 @@ describe("AutoCompleteAdapter", () => {
476
482
"n"
477
483
)
478
484
customRequest . bufferPosition = new Point ( 0 , 10 )
479
- result = ( await autoCompleteAdapter . getSuggestions ( server , customRequest ) ) [ 0 ]
485
+ result = ( await getSuggestionsMock ( items , customRequest ) ) [ 0 ]
480
486
expect ( result . replacementPrefix ) . equals ( "#align" )
481
487
482
488
customRequest . editor . setTextInBufferRange (
@@ -487,16 +493,16 @@ describe("AutoCompleteAdapter", () => {
487
493
""
488
494
)
489
495
customRequest . bufferPosition = new Point ( 0 , 7 )
490
- result = ( await autoCompleteAdapter . getSuggestions ( server , customRequest ) ) [ 0 ]
496
+ result = ( await getSuggestionsMock ( items , customRequest ) ) [ 0 ]
491
497
expect ( result . replacementPrefix ) . equals ( "#al" )
492
498
} )
493
499
494
500
it ( "does not include the triggerChar in replacementPrefix" , async ( ) => {
495
501
const customRequest = createRequest ( { prefix : "." , position : new Point ( 0 , 4 ) } )
496
502
customRequest . editor . setText ( "foo." )
497
503
server . capabilities . completionProvider ! . triggerCharacters = [ "." ]
498
- sinon . stub ( server . connection , "completion" ) . resolves ( [ { label : "bar" } ] as CompletionItem [ ] )
499
- let result = ( await autoCompleteAdapter . getSuggestions ( server , customRequest ) ) [ 0 ]
504
+ const items = [ { label : "bar" } ]
505
+ let result = ( await getSuggestionsMock ( items , customRequest ) ) [ 0 ]
500
506
expect ( result . replacementPrefix ) . equals ( "" )
501
507
customRequest . editor . setTextInBufferRange (
502
508
[
@@ -507,7 +513,7 @@ describe("AutoCompleteAdapter", () => {
507
513
)
508
514
customRequest . prefix = "b"
509
515
customRequest . bufferPosition = new Point ( 0 , 5 )
510
- result = ( await autoCompleteAdapter . getSuggestions ( server , customRequest ) ) [ 0 ]
516
+ result = ( await getSuggestionsMock ( items , customRequest ) ) [ 0 ]
511
517
expect ( result . replacementPrefix ) . equals ( "b" )
512
518
customRequest . editor . setTextInBufferRange (
513
519
[
@@ -518,15 +524,15 @@ describe("AutoCompleteAdapter", () => {
518
524
)
519
525
customRequest . prefix = "ba"
520
526
customRequest . bufferPosition = new Point ( 0 , 6 )
521
- result = ( await autoCompleteAdapter . getSuggestions ( server , customRequest ) ) [ 0 ]
527
+ result = ( await getSuggestionsMock ( items , customRequest ) ) [ 0 ]
522
528
expect ( result . replacementPrefix ) . equals ( "ba" )
523
529
} )
524
530
525
531
it ( "includes non trigger character prefix in replacementPrefix" , async ( ) => {
526
532
const customRequest = createRequest ( { prefix : "foo" , position : new Point ( 0 , 3 ) } )
527
533
customRequest . editor . setText ( "foo" )
528
- sinon . stub ( server . connection , "completion" ) . resolves ( [ { label : "foobar" } ] as CompletionItem [ ] )
529
- let result = ( await autoCompleteAdapter . getSuggestions ( server , customRequest ) ) [ 0 ]
534
+ const items = [ { label : "foobar" } ]
535
+ let result = ( await getSuggestionsMock ( items , customRequest ) ) [ 0 ]
530
536
531
537
expect ( result . replacementPrefix ) . equals ( "foo" )
532
538
customRequest . editor . setTextInBufferRange (
@@ -538,7 +544,7 @@ describe("AutoCompleteAdapter", () => {
538
544
)
539
545
customRequest . prefix = "foob"
540
546
customRequest . bufferPosition = new Point ( 0 , 4 )
541
- result = ( await autoCompleteAdapter . getSuggestions ( server , customRequest ) ) [ 0 ]
547
+ result = ( await getSuggestionsMock ( items , customRequest ) ) [ 0 ]
542
548
expect ( result . replacementPrefix ) . equals ( "foob" )
543
549
customRequest . editor . setTextInBufferRange (
544
550
[
@@ -549,7 +555,7 @@ describe("AutoCompleteAdapter", () => {
549
555
)
550
556
customRequest . prefix = "fooba"
551
557
customRequest . bufferPosition = new Point ( 0 , 5 )
552
- result = ( await autoCompleteAdapter . getSuggestions ( server , customRequest ) ) [ 0 ]
558
+ result = ( await getSuggestionsMock ( items , customRequest ) ) [ 0 ]
553
559
expect ( result . replacementPrefix ) . equals ( "fooba" )
554
560
} )
555
561
} )
0 commit comments