@@ -379,51 +379,75 @@ 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-
384382 // Open the buffer on the host.
385383 let buffer_a = project_a
386384 . update ( cx_a, |p, cx| p. open_buffer ( ( worktree_id, "main.rs" ) , cx) )
387385 . await
388386 . unwrap ( ) ;
389- cx_a. executor ( ) . run_until_parked ( ) ;
390387
391388 buffer_a. read_with ( cx_a, |buffer, _| {
392389 assert_eq ! ( buffer. text( ) , "fn main() { a. }" )
393390 } ) ;
394391
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-
402392 // Return a resolved completion from the host's language server.
403393 // The resolved completion has an additional text edit.
404394 fake_language_server. handle_request :: < lsp:: request:: ResolveCompletionItem , _ , _ > (
405395 |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) ,
420432 } )
421433 } ,
422434 ) ;
435+ cx_a. executor ( ) . finish_waiting ( ) ;
436+ cx_a. executor ( ) . run_until_parked ( ) ;
423437
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 ( ) ;
425447 cx_a. executor ( ) . run_until_parked ( ) ;
448+ cx_b. executor ( ) . run_until_parked ( ) ;
426449
450+ // The additional edit is applied.
427451 buffer_a. read_with ( cx_a, |buffer, _| {
428452 assert_eq ! (
429453 buffer. text( ) ,
@@ -516,9 +540,15 @@ async fn test_collaborating_with_completion(cx_a: &mut TestAppContext, cx_b: &mu
516540 cx_b. executor ( ) . run_until_parked ( ) ;
517541
518542 // 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 ( ) ;
519551 editor_b. update ( cx_b, |editor, cx| {
520- assert ! ( editor. context_menu_visible( ) ) ;
521- editor. confirm_completion ( & ConfirmCompletion { item_ix : Some ( 0 ) } , cx) ;
522552 assert_eq ! (
523553 editor. text( cx) ,
524554 "use d::SomeTrait;\n fn main() { a.first_method(); a.third_method(, , ) }"
0 commit comments