49
49
//! user explores them belongs to that extension (it's totally valid to change
50
50
//! rust-project.json over time via configuration request!)
51
51
52
- use base_db:: { CrateDisplayName , CrateId , CrateName , Dependency } ;
53
- use la_arena:: RawIdx ;
52
+ use base_db:: { CrateDisplayName , CrateName } ;
54
53
use paths:: { AbsPath , AbsPathBuf , Utf8PathBuf } ;
55
54
use rustc_hash:: FxHashMap ;
56
55
use serde:: { de, Deserialize } ;
@@ -77,7 +76,7 @@ pub struct Crate {
77
76
pub root_module : AbsPathBuf ,
78
77
pub ( crate ) edition : Edition ,
79
78
pub ( crate ) version : Option < String > ,
80
- pub ( crate ) deps : Vec < Dependency > ,
79
+ pub ( crate ) deps : Vec < Dep > ,
81
80
pub ( crate ) cfg : Vec < CfgFlag > ,
82
81
pub ( crate ) target : Option < String > ,
83
82
pub ( crate ) env : FxHashMap < String , String > ,
@@ -128,16 +127,7 @@ impl ProjectJson {
128
127
root_module,
129
128
edition : crate_data. edition . into ( ) ,
130
129
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 ,
141
131
cfg : crate_data. cfg ,
142
132
target : crate_data. target ,
143
133
env : crate_data. env ,
@@ -161,11 +151,8 @@ impl ProjectJson {
161
151
}
162
152
163
153
/// 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) )
169
156
}
170
157
171
158
/// Returns the path to the project's root folder.
@@ -188,7 +175,7 @@ struct CrateData {
188
175
edition : EditionData ,
189
176
#[ serde( default ) ]
190
177
version : Option < semver:: Version > ,
191
- deps : Vec < DepData > ,
178
+ deps : Vec < Dep > ,
192
179
#[ serde( default ) ]
193
180
cfg : Vec < CfgFlag > ,
194
181
target : Option < String > ,
@@ -227,13 +214,21 @@ impl From<EditionData> for Edition {
227
214
}
228
215
}
229
216
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 {
232
227
/// Identifies a crate by position in the crates array.
233
228
#[ serde( rename = "crate" ) ]
234
- krate : usize ,
229
+ pub ( crate ) krate : CrateArrayIdx ,
235
230
#[ serde( deserialize_with = "deserialize_crate_name" ) ]
236
- name : CrateName ,
231
+ pub ( crate ) name : CrateName ,
237
232
}
238
233
239
234
#[ derive( Deserialize , Debug , Clone ) ]
0 commit comments