@@ -51,6 +51,8 @@ pub use lsp_data::FindImpls;
51
51
52
52
use std:: collections:: HashMap ;
53
53
use std:: path:: Path ;
54
+ use std:: sync:: atomic:: Ordering ;
55
+
54
56
55
57
/// Represent the result of a deglob action for a single wildcard import.
56
58
///
@@ -380,6 +382,7 @@ impl RequestAction for Rename {
380
382
ctx : InitActionContext ,
381
383
params : Self :: Params ,
382
384
) -> Result < Self :: Response , ResponseError > {
385
+ ctx. quiescent . store ( true , Ordering :: SeqCst ) ;
383
386
// We're going to mutate based on our data so we should block until the
384
387
// data is ready.
385
388
ctx. block_on_build ( ) ;
@@ -424,6 +427,10 @@ impl RequestAction for Rename {
424
427
} ) ;
425
428
}
426
429
430
+ if !ctx. quiescent . load ( Ordering :: SeqCst ) {
431
+ return Self :: fallback_response ( ) ;
432
+ }
433
+
427
434
Ok ( WorkspaceEdit { changes : Some ( edits) , document_changes : None } )
428
435
}
429
436
}
@@ -464,15 +471,15 @@ impl RequestAction for ExecuteCommand {
464
471
465
472
/// Currently supports "rls.applySuggestion", "rls.deglobImports".
466
473
fn handle (
467
- _ : InitActionContext ,
474
+ ctx : InitActionContext ,
468
475
params : ExecuteCommandParams ,
469
476
) -> Result < Self :: Response , ResponseError > {
470
477
match & * params. command {
471
478
"rls.applySuggestion" => {
472
479
apply_suggestion ( & params. arguments ) . map ( ExecuteCommandResponse :: ApplyEdit )
473
480
}
474
481
"rls.deglobImports" => {
475
- apply_deglobs ( params. arguments ) . map ( ExecuteCommandResponse :: ApplyEdit )
482
+ apply_deglobs ( params. arguments , & ctx ) . map ( ExecuteCommandResponse :: ApplyEdit )
476
483
}
477
484
c => {
478
485
debug ! ( "Unknown command: {}" , c) ;
@@ -497,12 +504,13 @@ fn apply_suggestion(
497
504
} )
498
505
}
499
506
500
- fn apply_deglobs ( args : Vec < serde_json:: Value > ) -> Result < ApplyWorkspaceEditParams , ResponseError > {
507
+ fn apply_deglobs ( args : Vec < serde_json:: Value > , ctx : & InitActionContext ) -> Result < ApplyWorkspaceEditParams , ResponseError > {
508
+ ctx. quiescent . store ( true , Ordering :: SeqCst ) ;
501
509
let deglob_results: Vec < DeglobResult > = args. into_iter ( )
502
510
. map ( |res| serde_json:: from_value ( res) . expect ( "Bad argument" ) )
503
511
. collect ( ) ;
504
512
505
- trace ! ( "apply_deglob {:?}" , deglob_results) ;
513
+ trace ! ( "apply_deglobs {:?}" , deglob_results) ;
506
514
507
515
assert ! ( !deglob_results. is_empty( ) ) ;
508
516
let uri = deglob_results[ 0 ] . location . uri . clone ( ) ;
@@ -526,6 +534,9 @@ fn apply_deglobs(args: Vec<serde_json::Value>) -> Result<ApplyWorkspaceEditParam
526
534
document_changes : None ,
527
535
} ;
528
536
537
+ if !ctx. quiescent . load ( Ordering :: SeqCst ) {
538
+ return Err ( ResponseError :: Empty ) ;
539
+ }
529
540
Ok ( ApplyWorkspaceEditParams { edit } )
530
541
}
531
542
@@ -714,6 +725,7 @@ fn reformat(
714
725
opts : & FormattingOptions ,
715
726
ctx : & InitActionContext ,
716
727
) -> Result < [ TextEdit ; 1 ] , ResponseError > {
728
+ ctx. quiescent . store ( true , Ordering :: SeqCst ) ;
717
729
trace ! (
718
730
"Reformat: {:?} {:?} {} {}" ,
719
731
doc,
@@ -771,6 +783,13 @@ fn reformat(
771
783
// echos back the change to us.
772
784
let text = String :: from_utf8 ( buf) . unwrap ( ) ;
773
785
786
+ if !ctx. quiescent . load ( Ordering :: SeqCst ) {
787
+ return Err ( ResponseError :: Message (
788
+ ErrorCode :: InternalError ,
789
+ "Reformat failed to complete successfully" . into ( ) ,
790
+ ) )
791
+ }
792
+
774
793
// If Rustfmt returns range of text that changed,
775
794
// we will be able to pass only range of changed text to the client.
776
795
Ok ( [
0 commit comments