4949//! user explores them belongs to that extension (it's totally valid to change
5050//! rust-project.json over time via configuration request!)
5151
52- use base_db:: { CrateDisplayName , CrateId , CrateName , Dependency } ;
53- use la_arena:: RawIdx ;
52+ use base_db:: { CrateDisplayName , CrateName } ;
5453use paths:: { AbsPath , AbsPathBuf , Utf8PathBuf } ;
5554use rustc_hash:: FxHashMap ;
5655use serde:: { de, Deserialize } ;
@@ -77,7 +76,7 @@ pub struct Crate {
7776 pub root_module : AbsPathBuf ,
7877 pub ( crate ) edition : Edition ,
7978 pub ( crate ) version : Option < String > ,
80- pub ( crate ) deps : Vec < Dependency > ,
79+ pub ( crate ) deps : Vec < Dep > ,
8180 pub ( crate ) cfg : Vec < CfgFlag > ,
8281 pub ( crate ) target : Option < String > ,
8382 pub ( crate ) env : FxHashMap < String , String > ,
@@ -128,16 +127,7 @@ impl ProjectJson {
128127 root_module,
129128 edition : crate_data. edition . into ( ) ,
130129 version : crate_data. version . as_ref ( ) . map ( ToString :: to_string) ,
131- deps : crate_data
132- . deps
133- . into_iter ( )
134- . map ( |dep_data| {
135- Dependency :: new (
136- dep_data. name ,
137- CrateId :: from_raw ( RawIdx :: from ( dep_data. krate as u32 ) ) ,
138- )
139- } )
140- . collect :: < Vec < _ > > ( ) ,
130+ deps : crate_data. deps ,
141131 cfg : crate_data. cfg ,
142132 target : crate_data. target ,
143133 env : crate_data. env ,
@@ -161,11 +151,8 @@ impl ProjectJson {
161151 }
162152
163153 /// Returns an iterator over the crates in the project.
164- pub fn crates ( & self ) -> impl Iterator < Item = ( CrateId , & Crate ) > + ' _ {
165- self . crates
166- . iter ( )
167- . enumerate ( )
168- . map ( |( idx, krate) | ( CrateId :: from_raw ( RawIdx :: from ( idx as u32 ) ) , krate) )
154+ pub fn crates ( & self ) -> impl Iterator < Item = ( CrateArrayIdx , & Crate ) > {
155+ self . crates . iter ( ) . enumerate ( ) . map ( |( idx, krate) | ( CrateArrayIdx ( idx) , krate) )
169156 }
170157
171158 /// Returns the path to the project's root folder.
@@ -188,7 +175,7 @@ struct CrateData {
188175 edition : EditionData ,
189176 #[ serde( default ) ]
190177 version : Option < semver:: Version > ,
191- deps : Vec < DepData > ,
178+ deps : Vec < Dep > ,
192179 #[ serde( default ) ]
193180 cfg : Vec < CfgFlag > ,
194181 target : Option < String > ,
@@ -227,13 +214,21 @@ impl From<EditionData> for Edition {
227214 }
228215}
229216
230- #[ derive( Deserialize , Debug , Clone ) ]
231- struct DepData {
217+ /// Identifies a crate by position in the crates array.
218+ ///
219+ /// This will differ from `CrateId` when multiple `ProjectJson`
220+ /// workspaces are loaded.
221+ #[ derive( Deserialize , Debug , Clone , Copy , Eq , PartialEq , Hash ) ]
222+ #[ serde( transparent) ]
223+ pub struct CrateArrayIdx ( pub usize ) ;
224+
225+ #[ derive( Deserialize , Debug , Clone , Eq , PartialEq ) ]
226+ pub ( crate ) struct Dep {
232227 /// Identifies a crate by position in the crates array.
233228 #[ serde( rename = "crate" ) ]
234- krate : usize ,
229+ pub ( crate ) krate : CrateArrayIdx ,
235230 #[ serde( deserialize_with = "deserialize_crate_name" ) ]
236- name : CrateName ,
231+ pub ( crate ) name : CrateName ,
237232}
238233
239234#[ derive( Deserialize , Debug , Clone ) ]
0 commit comments