@@ -57,16 +57,21 @@ pub fn main_loop(config: Config, connection: Connection) -> anyhow::Result<()> {
57
57
enum Event {
58
58
Lsp ( lsp_server:: Message ) ,
59
59
Task ( Task ) ,
60
+ QueuedTask ( QueuedTask ) ,
60
61
Vfs ( vfs:: loader:: Message ) ,
61
62
Flycheck ( flycheck:: Message ) ,
62
63
}
63
64
65
+ #[ derive( Debug ) ]
66
+ pub ( crate ) enum QueuedTask {
67
+ CheckIfIndexed ( lsp_types:: Url ) ,
68
+ }
69
+
64
70
#[ derive( Debug ) ]
65
71
pub ( crate ) enum Task {
66
72
Response ( lsp_server:: Response ) ,
67
73
Retry ( lsp_server:: Request ) ,
68
74
Diagnostics ( Vec < ( FileId , Vec < lsp_types:: Diagnostic > ) > ) ,
69
- FileIndexState ( lsp_types:: Url ) ,
70
75
PrimeCaches ( PrimeCachesProgress ) ,
71
76
FetchWorkspace ( ProjectWorkspaceProgress ) ,
72
77
FetchBuildData ( BuildDataProgress ) ,
@@ -106,6 +111,7 @@ impl fmt::Debug for Event {
106
111
match self {
107
112
Event :: Lsp ( it) => fmt:: Debug :: fmt ( it, f) ,
108
113
Event :: Task ( it) => fmt:: Debug :: fmt ( it, f) ,
114
+ Event :: QueuedTask ( it) => fmt:: Debug :: fmt ( it, f) ,
109
115
Event :: Vfs ( it) => fmt:: Debug :: fmt ( it, f) ,
110
116
Event :: Flycheck ( it) => fmt:: Debug :: fmt ( it, f) ,
111
117
}
@@ -184,6 +190,9 @@ impl GlobalState {
184
190
recv( self . task_pool. receiver) -> task =>
185
191
Some ( Event :: Task ( task. unwrap( ) ) ) ,
186
192
193
+ recv( self . task_queue. receiver) -> task =>
194
+ Some ( Event :: QueuedTask ( task. unwrap( ) ) ) ,
195
+
187
196
recv( self . fmt_pool. receiver) -> task =>
188
197
Some ( Event :: Task ( task. unwrap( ) ) ) ,
189
198
@@ -216,6 +225,10 @@ impl GlobalState {
216
225
lsp_server:: Message :: Notification ( not) => self . on_notification ( not) ?,
217
226
lsp_server:: Message :: Response ( resp) => self . complete_request ( resp) ,
218
227
} ,
228
+ Event :: QueuedTask ( task) => {
229
+ let _p = profile:: span ( "GlobalState::handle_event/deferred_task" ) ;
230
+ self . handle_deferred_task ( task) ;
231
+ }
219
232
Event :: Task ( task) => {
220
233
let _p = profile:: span ( "GlobalState::handle_event/task" ) ;
221
234
let mut prime_caches_progress = Vec :: new ( ) ;
@@ -488,23 +501,6 @@ impl GlobalState {
488
501
// Only retry requests that haven't been cancelled. Otherwise we do unnecessary work.
489
502
Task :: Retry ( req) if !self . is_completed ( & req) => self . on_request ( req) ,
490
503
Task :: Retry ( _) => ( ) ,
491
- Task :: FileIndexState ( uri) => {
492
- let _p = profile:: span ( "run_unindexed_project" ) ;
493
- let snap = self . snapshot ( ) ;
494
- let id = from_proto:: file_id ( & snap, & uri) . expect ( "unable to get FileId" ) ;
495
- if let Ok ( crates) = & snap. analysis . crates_for ( id) {
496
- if crates. is_empty ( ) {
497
- tracing:: debug!( ?uri, "rust-analyzer does not track this file" ) ;
498
- self . send_notification :: < ext:: UnindexedProject > (
499
- ext:: UnindexedProjectParams {
500
- text_documents : vec ! [ lsp_types:: TextDocumentIdentifier { uri } ] ,
501
- } ,
502
- ) ;
503
- } else {
504
- tracing:: warn!( "was unable to get analysis for crate" )
505
- }
506
- }
507
- }
508
504
Task :: Diagnostics ( diagnostics_per_file) => {
509
505
for ( file_id, diagnostics) in diagnostics_per_file {
510
506
self . diagnostics . set_native_diagnostics ( file_id, diagnostics)
@@ -626,6 +622,32 @@ impl GlobalState {
626
622
}
627
623
}
628
624
625
+ fn handle_deferred_task ( & mut self , task : QueuedTask ) {
626
+ match task {
627
+ QueuedTask :: CheckIfIndexed ( uri) => {
628
+ let snap = self . snapshot ( ) ;
629
+ let conn = self . conn . clone ( ) ;
630
+
631
+ self . task_pool . handle . spawn_with_sender ( ThreadIntent :: Worker , move |_| {
632
+ tracing:: debug!( ?uri, "handling uri" ) ;
633
+ let id = from_proto:: file_id ( & snap, & uri) . expect ( "unable to get FileId" ) ;
634
+ if let Ok ( crates) = & snap. analysis . crates_for ( id) {
635
+ if crates. is_empty ( ) {
636
+ conn. send_notification :: < ext:: UnindexedProject > (
637
+ ext:: UnindexedProjectParams {
638
+ text_documents : vec ! [ lsp_types:: TextDocumentIdentifier { uri } ] ,
639
+ } ,
640
+ ) ;
641
+ tracing:: debug!( "sent notification" ) ;
642
+ } else {
643
+ tracing:: debug!( ?uri, "is indexed" ) ;
644
+ }
645
+ }
646
+ } ) ;
647
+ }
648
+ }
649
+ }
650
+
629
651
fn handle_flycheck_msg ( & mut self , message : flycheck:: Message ) {
630
652
match message {
631
653
flycheck:: Message :: AddDiagnostic { id, workspace_root, diagnostic } => {
0 commit comments