@@ -22,7 +22,7 @@ impl RustAnalyzerArg {
2222 output_base : & Utf8Path ,
2323 workspace : & Utf8Path ,
2424 config_group : Option < & str > ,
25- ) -> anyhow:: Result < ( Utf8PathBuf , Vec < String > ) > {
25+ ) -> anyhow:: Result < ( Utf8PathBuf , String ) > {
2626 match self {
2727 Self :: Path ( file) => {
2828 let buildfile = query_buildfile_for_source_file (
@@ -32,12 +32,10 @@ impl RustAnalyzerArg {
3232 config_group,
3333 & file,
3434 ) ?;
35- query_targets ( bazel, output_base, workspace, config_group, & buildfile)
36- . map ( |t| ( buildfile, t) )
35+ buildfile_to_targets ( workspace, & buildfile) . map ( |t| ( buildfile, t) )
3736 }
3837 Self :: Buildfile ( buildfile) => {
39- query_targets ( bazel, output_base, workspace, config_group, & buildfile)
40- . map ( |t| ( buildfile, t) )
38+ buildfile_to_targets ( workspace, & buildfile) . map ( |t| ( buildfile, t) )
4139 }
4240 }
4341 }
@@ -114,44 +112,18 @@ fn query_buildfile_for_source_file(
114112 bail ! ( "no buildfile found for {file}" ) ;
115113}
116114
117- fn query_targets (
118- bazel : & Utf8Path ,
119- output_base : & Utf8Path ,
120- workspace : & Utf8Path ,
121- config_group : Option < & str > ,
122- buildfile : & Utf8Path ,
123- ) -> anyhow:: Result < Vec < String > > {
124- log:: info!( "running bazel query on buildfile: {buildfile}" ) ;
115+ fn buildfile_to_targets ( workspace : & Utf8Path , buildfile : & Utf8Path ) -> anyhow:: Result < String > {
116+ log:: info!( "getting targets for buildfile: {buildfile}" ) ;
125117
126118 let parent_dir = buildfile
127119 . strip_prefix ( workspace)
128120 . with_context ( || format ! ( "{buildfile} not part of workspace" ) ) ?
129121 . parent ( ) ;
130122
131123 let targets = match parent_dir {
132- Some ( p) if !p. as_str ( ) . is_empty ( ) => format ! ( "{p}/..." ) ,
124+ Some ( p) if !p. as_str ( ) . is_empty ( ) => format ! ( "// {p}/..." ) ,
133125 _ => "//..." . to_string ( ) ,
134126 } ;
135127
136- let query_output = Command :: new ( bazel)
137- . current_dir ( workspace)
138- . env_remove ( "BAZELISK_SKIP_WRAPPER" )
139- . env_remove ( "BUILD_WORKING_DIRECTORY" )
140- . env_remove ( "BUILD_WORKSPACE_DIRECTORY" )
141- . arg ( format ! ( "--output_base={output_base}" ) )
142- . arg ( "query" )
143- . args ( config_group. map ( |s| format ! ( "--config={s}" ) ) )
144- . arg ( format ! (
145- "kind(\" rust_(library|binary|proc_macro|test)\" , {targets})"
146- ) )
147- . output ( )
148- . with_context ( || format ! ( "failed to run bazel query for buildfile: {buildfile}" ) ) ?;
149-
150- log:: debug!( "{}" , String :: from_utf8_lossy( & query_output. stderr) ) ;
151- log:: info!( "bazel query for buildfile {buildfile} finished" ) ;
152-
153- let text = String :: from_utf8 ( query_output. stdout ) ?;
154- let targets = text. lines ( ) . map ( ToOwned :: to_owned) . collect ( ) ;
155-
156128 Ok ( targets)
157129}
0 commit comments