@@ -9,7 +9,7 @@ use std::{error::Error, fmt, panic, path::PathBuf, sync::Arc, time::Instant};
99
1010use crossbeam_channel:: { select, unbounded, RecvError , Sender } ;
1111use lsp_server:: { Connection , ErrorCode , Message , Notification , Request , RequestId , Response } ;
12- use lsp_types:: { ClientCapabilities , NumberOrString , Url } ;
12+ use lsp_types:: { ClientCapabilities , NumberOrString } ;
1313use ra_cargo_watch:: { CheckOptions , CheckTask } ;
1414use ra_ide:: { Canceled , FeatureFlags , FileId , LibraryData , SourceRootId } ;
1515use ra_prof:: profile;
@@ -352,7 +352,7 @@ fn loop_turn(
352352 world_state. maybe_collect_garbage ( ) ;
353353 loop_state. in_flight_libraries -= 1 ;
354354 }
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) ?,
356356 Event :: Msg ( msg) => match msg {
357357 Message :: Request ( req) => on_request (
358358 world_state,
@@ -602,31 +602,23 @@ fn on_notification(
602602}
603603
604604fn on_check_task (
605+ pool : & ThreadPool ,
605606 task : CheckTask ,
606607 world_state : & mut WorldState ,
607608 task_sender : & Sender < Task > ,
608609) -> Result < ( ) > {
609- match task {
610+ let urls = match task {
610611 CheckTask :: ClearDiagnostics => {
611612 let state = Arc :: get_mut ( & mut world_state. check_watcher . state )
612613 . 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 ( )
619615 }
620616
621617 CheckTask :: AddDiagnostic ( url, diagnostic) => {
622618 let state = Arc :: get_mut ( & mut world_state. check_watcher . state )
623619 . expect ( "couldn't get check watcher state as mutable" ) ;
624620 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]
630622 }
631623
632624 CheckTask :: Status ( progress) => {
@@ -636,22 +628,30 @@ fn on_check_task(
636628 } ;
637629 let not = notification_new :: < req:: Progress > ( params) ;
638630 task_sender. send ( Task :: Notify ( not) ) . unwrap ( ) ;
631+ Vec :: new ( )
639632 }
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+ ) ;
643654
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- }
655655 Ok ( ( ) )
656656}
657657
0 commit comments