@@ -35,12 +35,10 @@ use cargo::core::{PackageId, Target, TargetKind};
3535use cargo:: util:: ProcessBuilder ;
3636use cargo_metadata;
3737use log:: { error, trace} ;
38- use url:: Url ;
3938
40- use crate :: build:: PackageArg ;
41- use crate :: build:: plan:: { BuildKey , BuildGraph , JobQueue , WorkStatus } ;
39+ use crate :: build:: plan:: { BuildGraph , BuildKey , JobQueue , WorkStatus } ;
4240use crate :: build:: rustc:: src_path;
43- use crate :: lsp_data :: parse_file_path ;
41+ use crate :: build :: PackageArg ;
4442
4543/// Main key type by which `Unit`s will be distinguished in the build plan.
4644/// In Target we're mostly interested in TargetKind (Lib, Bin, ...) and name
@@ -455,19 +453,16 @@ impl PackageMap {
455453 // Find each package in the workspace and record the root directory and package name.
456454 fn discover_package_paths ( manifest_path : & Path ) -> HashMap < PathBuf , String > {
457455 trace ! ( "read metadata {:?}" , manifest_path) ;
458- let metadata = match cargo_metadata:: metadata ( Some ( manifest_path) ) {
459- Ok ( metadata) => metadata,
460- Err ( _) => return HashMap :: new ( ) ,
461- } ;
462- metadata
463- . workspace_members
464- . into_iter ( )
465- . map ( |wm| {
466- assert ! ( wm. url( ) . starts_with( "path+" ) ) ;
467- let url = Url :: parse ( & wm. url ( ) [ 5 ..] ) . expect ( "Bad URL" ) ;
468- let path = parse_file_path ( & url) . expect ( "URL not a path" ) ;
469- ( path, wm. name ( ) . into ( ) )
470- } ) . collect ( )
456+ cargo_metadata:: MetadataCommand :: new ( )
457+ . manifest_path ( manifest_path)
458+ . exec ( )
459+ . iter ( )
460+ . flat_map ( |meta| meta. workspace_members . iter ( ) . map ( move |id| & meta[ id] ) )
461+ . filter_map ( |pkg| {
462+ let dir = pkg. manifest_path . parent ( ) ?. to_path_buf ( ) ;
463+ Some ( ( dir, pkg. name . clone ( ) ) )
464+ } )
465+ . collect ( )
471466 }
472467
473468 /// Given modified set of files, returns a set of corresponding dirty packages.
0 commit comments