@@ -379,51 +379,75 @@ async fn test_collaborating_with_completion(cx_a: &mut TestAppContext, cx_b: &mu
379
379
. next ( )
380
380
. await
381
381
. unwrap ( ) ;
382
- cx_a. executor ( ) . finish_waiting ( ) ;
383
-
384
382
// Open the buffer on the host.
385
383
let buffer_a = project_a
386
384
. update ( cx_a, |p, cx| p. open_buffer ( ( worktree_id, "main.rs" ) , cx) )
387
385
. await
388
386
. unwrap ( ) ;
389
- cx_a. executor ( ) . run_until_parked ( ) ;
390
387
391
388
buffer_a. read_with ( cx_a, |buffer, _| {
392
389
assert_eq ! ( buffer. text( ) , "fn main() { a. }" )
393
390
} ) ;
394
391
395
- // Confirm a completion on the guest.
396
- editor_b. update ( cx_b, |editor, cx| {
397
- assert ! ( editor. context_menu_visible( ) ) ;
398
- editor. confirm_completion ( & ConfirmCompletion { item_ix : Some ( 0 ) } , cx) ;
399
- assert_eq ! ( editor. text( cx) , "fn main() { a.first_method() }" ) ;
400
- } ) ;
401
-
402
392
// Return a resolved completion from the host's language server.
403
393
// The resolved completion has an additional text edit.
404
394
fake_language_server. handle_request :: < lsp:: request:: ResolveCompletionItem , _ , _ > (
405
395
|params, _| async move {
406
- assert_eq ! ( params. label, "first_method(…)" ) ;
407
- Ok ( lsp:: CompletionItem {
408
- label : "first_method(…)" . into ( ) ,
409
- detail : Some ( "fn(&mut self, B) -> C" . into ( ) ) ,
410
- text_edit : Some ( lsp:: CompletionTextEdit :: Edit ( lsp:: TextEdit {
411
- new_text : "first_method($1)" . to_string ( ) ,
412
- range : lsp:: Range :: new ( lsp:: Position :: new ( 0 , 14 ) , lsp:: Position :: new ( 0 , 14 ) ) ,
413
- } ) ) ,
414
- additional_text_edits : Some ( vec ! [ lsp:: TextEdit {
415
- new_text: "use d::SomeTrait;\n " . to_string( ) ,
416
- range: lsp:: Range :: new( lsp:: Position :: new( 0 , 0 ) , lsp:: Position :: new( 0 , 0 ) ) ,
417
- } ] ) ,
418
- insert_text_format : Some ( lsp:: InsertTextFormat :: SNIPPET ) ,
419
- ..Default :: default ( )
396
+ Ok ( match params. label . as_str ( ) {
397
+ "first_method(…)" => lsp:: CompletionItem {
398
+ label : "first_method(…)" . into ( ) ,
399
+ detail : Some ( "fn(&mut self, B) -> C" . into ( ) ) ,
400
+ text_edit : Some ( lsp:: CompletionTextEdit :: Edit ( lsp:: TextEdit {
401
+ new_text : "first_method($1)" . to_string ( ) ,
402
+ range : lsp:: Range :: new (
403
+ lsp:: Position :: new ( 0 , 14 ) ,
404
+ lsp:: Position :: new ( 0 , 14 ) ,
405
+ ) ,
406
+ } ) ) ,
407
+ additional_text_edits : Some ( vec ! [ lsp:: TextEdit {
408
+ new_text: "use d::SomeTrait;\n " . to_string( ) ,
409
+ range: lsp:: Range :: new( lsp:: Position :: new( 0 , 0 ) , lsp:: Position :: new( 0 , 0 ) ) ,
410
+ } ] ) ,
411
+ insert_text_format : Some ( lsp:: InsertTextFormat :: SNIPPET ) ,
412
+ ..Default :: default ( )
413
+ } ,
414
+ "second_method(…)" => lsp:: CompletionItem {
415
+ label : "second_method(…)" . into ( ) ,
416
+ detail : Some ( "fn(&mut self, C) -> D<E>" . into ( ) ) ,
417
+ text_edit : Some ( lsp:: CompletionTextEdit :: Edit ( lsp:: TextEdit {
418
+ new_text : "second_method()" . to_string ( ) ,
419
+ range : lsp:: Range :: new (
420
+ lsp:: Position :: new ( 0 , 14 ) ,
421
+ lsp:: Position :: new ( 0 , 14 ) ,
422
+ ) ,
423
+ } ) ) ,
424
+ insert_text_format : Some ( lsp:: InsertTextFormat :: SNIPPET ) ,
425
+ additional_text_edits : Some ( vec ! [ lsp:: TextEdit {
426
+ new_text: "use d::SomeTrait;\n " . to_string( ) ,
427
+ range: lsp:: Range :: new( lsp:: Position :: new( 0 , 0 ) , lsp:: Position :: new( 0 , 0 ) ) ,
428
+ } ] ) ,
429
+ ..Default :: default ( )
430
+ } ,
431
+ _ => panic ! ( "unexpected completion label: {:?}" , params. label) ,
420
432
} )
421
433
} ,
422
434
) ;
435
+ cx_a. executor ( ) . finish_waiting ( ) ;
436
+ cx_a. executor ( ) . run_until_parked ( ) ;
423
437
424
- // The additional edit is applied.
438
+ // Confirm a completion on the guest.
439
+ editor_b
440
+ . update ( cx_b, |editor, cx| {
441
+ assert ! ( editor. context_menu_visible( ) ) ;
442
+ editor. confirm_completion ( & ConfirmCompletion { item_ix : Some ( 0 ) } , cx)
443
+ } )
444
+ . unwrap ( )
445
+ . await
446
+ . unwrap ( ) ;
425
447
cx_a. executor ( ) . run_until_parked ( ) ;
448
+ cx_b. executor ( ) . run_until_parked ( ) ;
426
449
450
+ // The additional edit is applied.
427
451
buffer_a. read_with ( cx_a, |buffer, _| {
428
452
assert_eq ! (
429
453
buffer. text( ) ,
@@ -516,9 +540,15 @@ async fn test_collaborating_with_completion(cx_a: &mut TestAppContext, cx_b: &mu
516
540
cx_b. executor ( ) . run_until_parked ( ) ;
517
541
518
542
// When accepting the completion, the snippet is insert.
543
+ editor_b
544
+ . update ( cx_b, |editor, cx| {
545
+ assert ! ( editor. context_menu_visible( ) ) ;
546
+ editor. confirm_completion ( & ConfirmCompletion { item_ix : Some ( 0 ) } , cx)
547
+ } )
548
+ . unwrap ( )
549
+ . await
550
+ . unwrap ( ) ;
519
551
editor_b. update ( cx_b, |editor, cx| {
520
- assert ! ( editor. context_menu_visible( ) ) ;
521
- editor. confirm_completion ( & ConfirmCompletion { item_ix : Some ( 0 ) } , cx) ;
522
552
assert_eq ! (
523
553
editor. text( cx) ,
524
554
"use d::SomeTrait;\n fn main() { a.first_method(); a.third_method(, , ) }"
0 commit comments