@@ -9,7 +9,7 @@ use std::{error::Error, fmt, panic, path::PathBuf, sync::Arc, time::Instant};
9
9
10
10
use crossbeam_channel:: { select, unbounded, RecvError , Sender } ;
11
11
use lsp_server:: { Connection , ErrorCode , Message , Notification , Request , RequestId , Response } ;
12
- use lsp_types:: { ClientCapabilities , NumberOrString , Url } ;
12
+ use lsp_types:: { ClientCapabilities , NumberOrString } ;
13
13
use ra_cargo_watch:: { CheckOptions , CheckTask } ;
14
14
use ra_ide:: { Canceled , FeatureFlags , FileId , LibraryData , SourceRootId } ;
15
15
use ra_prof:: profile;
@@ -352,7 +352,7 @@ fn loop_turn(
352
352
world_state. maybe_collect_garbage ( ) ;
353
353
loop_state. in_flight_libraries -= 1 ;
354
354
}
355
- Event :: CheckWatcher ( task) => on_check_task ( task, world_state, task_sender) ?,
355
+ Event :: CheckWatcher ( task) => on_check_task ( pool , task, world_state, task_sender) ?,
356
356
Event :: Msg ( msg) => match msg {
357
357
Message :: Request ( req) => on_request (
358
358
world_state,
@@ -602,31 +602,23 @@ fn on_notification(
602
602
}
603
603
604
604
fn on_check_task (
605
+ pool : & ThreadPool ,
605
606
task : CheckTask ,
606
607
world_state : & mut WorldState ,
607
608
task_sender : & Sender < Task > ,
608
609
) -> Result < ( ) > {
609
- match task {
610
+ let urls = match task {
610
611
CheckTask :: ClearDiagnostics => {
611
612
let state = Arc :: get_mut ( & mut world_state. check_watcher . state )
612
613
. expect ( "couldn't get check watcher state as mutable" ) ;
613
- let cleared_files = state. clear ( ) ;
614
-
615
- // Send updated diagnostics for each cleared file
616
- for url in cleared_files {
617
- publish_diagnostics_for_url ( & url, world_state, task_sender) ?;
618
- }
614
+ state. clear ( )
619
615
}
620
616
621
617
CheckTask :: AddDiagnostic ( url, diagnostic) => {
622
618
let state = Arc :: get_mut ( & mut world_state. check_watcher . state )
623
619
. expect ( "couldn't get check watcher state as mutable" ) ;
624
620
state. add_diagnostic_with_fixes ( url. clone ( ) , diagnostic) ;
625
-
626
- // We manually send a diagnostic update when the watcher asks
627
- // us to, to avoid the issue of having to change the file to
628
- // receive updated diagnostics.
629
- publish_diagnostics_for_url ( & url, world_state, task_sender) ?;
621
+ vec ! [ url]
630
622
}
631
623
632
624
CheckTask :: Status ( progress) => {
@@ -636,22 +628,30 @@ fn on_check_task(
636
628
} ;
637
629
let not = notification_new :: < req:: Progress > ( params) ;
638
630
task_sender. send ( Task :: Notify ( not) ) . unwrap ( ) ;
631
+ Vec :: new ( )
639
632
}
640
- }
641
- Ok ( ( ) )
642
- }
633
+ } ;
634
+
635
+ let subscriptions = urls
636
+ . into_iter ( )
637
+ . map ( |url| {
638
+ let path = url. to_file_path ( ) . map_err ( |( ) | format ! ( "invalid uri: {}" , url) ) ?;
639
+ Ok ( world_state. vfs . read ( ) . path2file ( & path) . map ( |it| FileId ( it. 0 ) ) )
640
+ } )
641
+ . filter_map ( |res| res. transpose ( ) )
642
+ . collect :: < Result < Vec < _ > > > ( ) ?;
643
+
644
+ // We manually send a diagnostic update when the watcher asks
645
+ // us to, to avoid the issue of having to change the file to
646
+ // receive updated diagnostics.
647
+ update_file_notifications_on_threadpool (
648
+ pool,
649
+ world_state. snapshot ( ) ,
650
+ false ,
651
+ task_sender. clone ( ) ,
652
+ subscriptions,
653
+ ) ;
643
654
644
- fn publish_diagnostics_for_url (
645
- url : & Url ,
646
- world_state : & WorldState ,
647
- task_sender : & Sender < Task > ,
648
- ) -> Result < ( ) > {
649
- let path = url. to_file_path ( ) . map_err ( |( ) | format ! ( "invalid uri: {}" , url) ) ?;
650
- if let Some ( file_id) = world_state. vfs . read ( ) . path2file ( & path) {
651
- let params = handlers:: publish_diagnostics ( & world_state. snapshot ( ) , FileId ( file_id. 0 ) ) ?;
652
- let not = notification_new :: < req:: PublishDiagnostics > ( params) ;
653
- task_sender. send ( Task :: Notify ( not) ) . unwrap ( ) ;
654
- }
655
655
Ok ( ( ) )
656
656
}
657
657
0 commit comments