@@ -14,12 +14,13 @@ use lsp_server::{Connection, Notification, Request};
14
14
use lsp_types:: { notification:: Notification as _, TextDocumentIdentifier } ;
15
15
use stdx:: thread:: ThreadIntent ;
16
16
use tracing:: { error, span, Level } ;
17
+ use triomphe:: Arc ;
17
18
use vfs:: { loader:: LoadingProgress , AbsPathBuf , FileId } ;
18
19
19
20
use crate :: {
20
21
config:: Config ,
21
22
diagnostics:: { fetch_native_diagnostics, DiagnosticsGeneration , NativeDiagnosticsFetchKind } ,
22
- discover:: { DiscoverArgument , DiscoverCommand , DiscoverProjectMessage } ,
23
+ discover:: { DiscoverArgument , DiscoverProjectJson , DiscoverProjectMessage } ,
23
24
flycheck:: { self , FlycheckMessage } ,
24
25
global_state:: { file_id_to_url, url_to_file_id, FetchWorkspaceRequest , GlobalState } ,
25
26
hack_recover_crate_name,
@@ -113,6 +114,7 @@ pub(crate) enum Task {
113
114
pub ( crate ) enum DiscoverProjectParam {
114
115
Buildfile ( AbsPathBuf ) ,
115
116
Path ( AbsPathBuf ) ,
117
+ ClassicOnDisk ,
116
118
}
117
119
118
120
#[ derive( Debug ) ]
@@ -159,8 +161,6 @@ impl fmt::Debug for Event {
159
161
160
162
impl GlobalState {
161
163
fn run ( mut self , inbox : Receiver < lsp_server:: Message > ) -> anyhow:: Result < ( ) > {
162
- self . update_status_or_notify ( ) ;
163
-
164
164
if self . config . did_save_text_document_dynamic_registration ( ) {
165
165
let additional_patterns = self
166
166
. config
@@ -172,17 +172,7 @@ impl GlobalState {
172
172
self . register_did_save_capability ( additional_patterns) ;
173
173
}
174
174
175
- if self . config . discover_workspace_config ( ) . is_none ( ) {
176
- self . fetch_workspaces_queue . request_op (
177
- "startup" . to_owned ( ) ,
178
- FetchWorkspaceRequest { path : None , force_crate_graph_reload : false } ,
179
- ) ;
180
- if let Some ( ( cause, FetchWorkspaceRequest { path, force_crate_graph_reload } ) ) =
181
- self . fetch_workspaces_queue . should_start_op ( )
182
- {
183
- self . fetch_workspaces ( cause, path, force_crate_graph_reload) ;
184
- }
185
- }
175
+ self . discover_workspace_queue . request_op ( "startup" . to_owned ( ) , ( ) ) ;
186
176
187
177
while let Ok ( event) = self . next_event ( & inbox) {
188
178
let Some ( event) = event else {
@@ -699,13 +689,14 @@ impl GlobalState {
699
689
self . report_progress ( "Fetching" , state, msg, None , None ) ;
700
690
}
701
691
Task :: DiscoverLinkedProjects ( arg) => {
702
- if let Some ( cfg ) = self . config . discover_workspace_config ( ) {
703
- if ! self . discover_workspace_queue . op_in_progress ( ) {
692
+ if ! self . discover_workspace_queue . op_in_progress ( ) {
693
+ if let Some ( cfg ) = self . config . discover_workspace_config ( ) {
704
694
// the clone is unfortunately necessary to avoid a borrowck error when
705
695
// `self.report_progress` is called later
706
696
let title = & cfg. progress_label . clone ( ) ;
707
697
let command = cfg. command . clone ( ) ;
708
- let discover = DiscoverCommand :: new ( self . discover_sender . clone ( ) , command) ;
698
+ let discover =
699
+ DiscoverProjectJson :: new ( self . discover_sender . clone ( ) , command) ;
709
700
710
701
self . report_progress ( title, Progress :: Begin , None , None , None ) ;
711
702
self . discover_workspace_queue
@@ -715,10 +706,19 @@ impl GlobalState {
715
706
let arg = match arg {
716
707
DiscoverProjectParam :: Buildfile ( it) => DiscoverArgument :: Buildfile ( it) ,
717
708
DiscoverProjectParam :: Path ( it) => DiscoverArgument :: Path ( it) ,
709
+ _ => return , // this is a bug; the arg should not be sent if `discover_workspace_config` is set
718
710
} ;
719
711
720
712
let handle = discover. spawn ( arg) . unwrap ( ) ;
721
713
self . discover_handle = Some ( handle) ;
714
+ } else {
715
+ let config = Arc :: make_mut ( & mut self . config ) ;
716
+ config. rediscover_workspaces ( ) ;
717
+
718
+ let req =
719
+ FetchWorkspaceRequest { path : None , force_crate_graph_reload : false } ;
720
+ self . fetch_workspaces_queue
721
+ . request_op ( "workspaces have been discovered" . to_owned ( ) , req) ;
722
722
}
723
723
}
724
724
}
@@ -829,11 +829,18 @@ impl GlobalState {
829
829
let id = from_proto:: file_id ( & snap, & uri) . expect ( "unable to get FileId" ) ;
830
830
if let Ok ( crates) = & snap. analysis . crates_for ( id) {
831
831
if crates. is_empty ( ) {
832
- if snap. config . discover_workspace_config ( ) . is_some ( ) {
833
- let path =
834
- from_proto:: abs_path ( & uri) . expect ( "Unable to get AbsPath" ) ;
835
- let arg = DiscoverProjectParam :: Path ( path) ;
836
- sender. send ( Task :: DiscoverLinkedProjects ( arg) ) . unwrap ( ) ;
832
+ match snap. config . discover_workspace_config ( ) {
833
+ Some ( _) => {
834
+ let path =
835
+ from_proto:: abs_path ( & uri) . expect ( "Unable to get AbsPath" ) ;
836
+ let arg = DiscoverProjectParam :: Path ( path) ;
837
+ sender. send ( Task :: DiscoverLinkedProjects ( arg) ) . unwrap ( ) ;
838
+ }
839
+ // default behavior; do standard discovery
840
+ None => {
841
+ let arg = DiscoverProjectParam :: ClassicOnDisk ;
842
+ sender. send ( Task :: DiscoverLinkedProjects ( arg) ) . unwrap ( ) ;
843
+ }
837
844
}
838
845
} else {
839
846
tracing:: debug!( ?uri, "is indexed" ) ;
0 commit comments