@@ -379,75 +379,51 @@ async fn test_collaborating_with_completion(cx_a: &mut TestAppContext, cx_b: &mu
379379 . next ( )
380380 . await
381381 . unwrap ( ) ;
382+ cx_a. executor ( ) . finish_waiting ( ) ;
383+
382384 // Open the buffer on the host.
383385 let buffer_a = project_a
384386 . update ( cx_a, |p, cx| p. open_buffer ( ( worktree_id, "main.rs" ) , cx) )
385387 . await
386388 . unwrap ( ) ;
389+ cx_a. executor ( ) . run_until_parked ( ) ;
387390
388391 buffer_a. read_with ( cx_a, |buffer, _| {
389392 assert_eq ! ( buffer. text( ) , "fn main() { a. }" )
390393 } ) ;
391394
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+
392402 // Return a resolved completion from the host's language server.
393403 // The resolved completion has an additional text edit.
394404 fake_language_server. handle_request :: < lsp:: request:: ResolveCompletionItem , _ , _ > (
395405 |params, _| async move {
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) ,
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 ( )
432420 } )
433421 } ,
434422 ) ;
435- cx_a. executor ( ) . finish_waiting ( ) ;
436- cx_a. executor ( ) . run_until_parked ( ) ;
437423
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 ( ) ;
424+ // The additional edit is applied.
447425 cx_a. executor ( ) . run_until_parked ( ) ;
448- cx_b. executor ( ) . run_until_parked ( ) ;
449426
450- // The additional edit is applied.
451427 buffer_a. read_with ( cx_a, |buffer, _| {
452428 assert_eq ! (
453429 buffer. text( ) ,
@@ -540,15 +516,9 @@ async fn test_collaborating_with_completion(cx_a: &mut TestAppContext, cx_b: &mu
540516 cx_b. executor ( ) . run_until_parked ( ) ;
541517
542518 // 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 ( ) ;
551519 editor_b. update ( cx_b, |editor, cx| {
520+ assert ! ( editor. context_menu_visible( ) ) ;
521+ editor. confirm_completion ( & ConfirmCompletion { item_ix : Some ( 0 ) } , cx) ;
552522 assert_eq ! (
553523 editor. text( cx) ,
554524 "use d::SomeTrait;\n fn main() { a.first_method(); a.third_method(, , ) }"
0 commit comments