@@ -9,12 +9,14 @@ use std::{
99
1010use always_assert:: always;
1111use crossbeam_channel:: { select, Receiver } ;
12+ use flycheck:: JsonArguments ;
1213use ide_db:: base_db:: { SourceDatabase , SourceDatabaseExt , VfsPath } ;
1314use lsp_server:: { Connection , Notification , Request } ;
1415use lsp_types:: { notification:: Notification as _, TextDocumentIdentifier , Url } ;
16+ use paths:: Utf8PathBuf ;
1517use stdx:: thread:: ThreadIntent ;
1618use tracing:: { span, Level } ;
17- use vfs:: { AbsPathBuf , FileId } ;
19+ use vfs:: FileId ;
1820
1921use crate :: {
2022 config:: Config ,
@@ -88,7 +90,7 @@ pub(crate) enum QueuedTask {
8890#[ derive( Debug ) ]
8991pub ( crate ) enum Task {
9092 Response ( lsp_server:: Response ) ,
91- DiscoverLinkedProjects ( Url ) ,
93+ DiscoverLinkedProjects ( DiscoverProjectParam ) ,
9294 Retry ( lsp_server:: Request ) ,
9395 Diagnostics ( DiagnosticsGeneration , Vec < ( FileId , Vec < lsp_types:: Diagnostic > ) > ) ,
9496 DiscoverTest ( lsp_ext:: DiscoverTestResults ) ,
@@ -99,6 +101,12 @@ pub(crate) enum Task {
99101 BuildDepsHaveChanged ,
100102}
101103
104+ #[ derive( Debug ) ]
105+ pub ( crate ) enum DiscoverProjectParam {
106+ Label ( String ) ,
107+ Path ( Url ) ,
108+ }
109+
102110#[ derive( Debug ) ]
103111pub ( crate ) enum PrimeCachesProgress {
104112 Begin ,
@@ -150,11 +158,11 @@ impl GlobalState {
150158 }
151159
152160 if self . config . discover_command ( ) . is_none ( ) {
153- self . fetch_workspaces_queue . request_op ( "startup" . to_owned ( ) , false ) ;
154- if let Some ( ( cause, force_crate_graph_reload) ) =
161+ self . fetch_workspaces_queue . request_op ( "startup" . to_owned ( ) , ( None , false ) ) ;
162+ if let Some ( ( cause, ( path , force_crate_graph_reload) ) ) =
155163 self . fetch_workspaces_queue . should_start_op ( )
156164 {
157- self . fetch_workspaces ( cause, force_crate_graph_reload) ;
165+ self . fetch_workspaces ( cause, path , force_crate_graph_reload) ;
158166 }
159167 }
160168
@@ -195,7 +203,12 @@ impl GlobalState {
195203 lsp_types:: DocumentFilter {
196204 language: None ,
197205 scheme: None ,
198- pattern: Some ( "**/rust-analyzer.toml" . into( ) ) ,
206+ pattern: Some ( "**/BUCK" . into( ) ) ,
207+ } ,
208+ lsp_types:: DocumentFilter {
209+ language: None ,
210+ scheme: None ,
211+ pattern: Some ( "**/TARGETS" . into( ) ) ,
199212 } ,
200213 ] ) ,
201214 } ,
@@ -442,10 +455,10 @@ impl GlobalState {
442455 }
443456
444457 if self . config . cargo_autoreload_config ( ) || self . config . discover_command ( ) . is_some ( ) {
445- if let Some ( ( cause, force_crate_graph_reload) ) =
458+ if let Some ( ( cause, ( path , force_crate_graph_reload) ) ) =
446459 self . fetch_workspaces_queue . should_start_op ( )
447460 {
448- self . fetch_workspaces ( cause, force_crate_graph_reload) ;
461+ self . fetch_workspaces ( cause, path , force_crate_graph_reload) ;
449462 }
450463 }
451464
@@ -658,23 +671,29 @@ impl GlobalState {
658671
659672 self . report_progress ( "Fetching" , state, msg, None , None ) ;
660673 }
661- Task :: DiscoverLinkedProjects ( url ) => {
674+ Task :: DiscoverLinkedProjects ( arg ) => {
662675 if let Some ( command) = self . config . discover_command ( ) {
663676 if !self . discover_workspace_queue . op_in_progress ( ) {
664677 let discover =
665678 flycheck:: JsonWorkspace :: new ( self . discover_sender . clone ( ) , command) ;
666679
667- let path = url
668- . to_file_path ( )
669- . unwrap_or_else ( |_| panic ! ( "Unable to get file path from {}" , url) ) ;
670- let files = vec ! [ AbsPathBuf :: try_from( path) . unwrap( ) ] ;
671-
672680 self . report_progress ( "Buck" , Progress :: Begin , None , None , None ) ;
673681 self . discover_workspace_queue
674682 . request_op ( "Discovering workspace" . to_owned ( ) , ( ) ) ;
675683 let _ = self . discover_workspace_queue . should_start_op ( ) ;
676684
677- let handle = discover. spawn ( files) . unwrap ( ) ;
685+ let arg = match arg {
686+ DiscoverProjectParam :: Label ( label) => JsonArguments :: Label ( label) ,
687+ DiscoverProjectParam :: Path ( path) => {
688+ let path =
689+ path. to_file_path ( ) . expect ( "unable to convert to PathBuf" ) ;
690+ let path = Utf8PathBuf :: from_path_buf ( path)
691+ . expect ( "Unable to convert to Utf8PathBuf" ) ;
692+ JsonArguments :: Path ( path)
693+ }
694+ } ;
695+
696+ let handle = discover. spawn ( arg) . unwrap ( ) ;
678697 self . discover_handle = Some ( handle) ;
679698 }
680699 }
@@ -788,7 +807,8 @@ impl GlobalState {
788807 if let Ok ( crates) = & snap. analysis . crates_for ( id) {
789808 if crates. is_empty ( ) {
790809 if snap. config . discover_command ( ) . is_some ( ) {
791- sender. send ( Task :: DiscoverLinkedProjects ( uri) ) . unwrap ( ) ;
810+ let arg = DiscoverProjectParam :: Path ( uri) ;
811+ sender. send ( Task :: DiscoverLinkedProjects ( arg) ) . unwrap ( ) ;
792812 }
793813 } else {
794814 tracing:: debug!( ?uri, "is indexed" ) ;
@@ -820,11 +840,11 @@ impl GlobalState {
820840
821841 fn handle_discover_msg ( & mut self , message : flycheck:: DiscoverProjectMessage ) {
822842 match message {
823- flycheck:: DiscoverProjectMessage :: Finished { project_json } => {
843+ flycheck:: DiscoverProjectMessage :: Finished ( output ) => {
824844 self . report_progress ( "Buck" , Progress :: End , None , None , None ) ;
825845 self . discover_workspace_queue . op_completed ( ( ) ) ;
826846 let mut config = Config :: clone ( & * self . config ) ;
827- config. add_linked_projects ( project_json ) ;
847+ config. add_linked_projects ( output . project ) ;
828848 self . update_configuration ( config) ;
829849 }
830850 flycheck:: DiscoverProjectMessage :: Progress { message } => {
0 commit comments