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 std:: path:: PathBuf ;
53
-
54
52
use base_db:: { CrateDisplayName , CrateId , CrateName , Dependency , Edition } ;
55
53
use la_arena:: RawIdx ;
56
54
use paths:: { AbsPath , AbsPathBuf } ;
57
55
use rustc_hash:: FxHashMap ;
58
56
use serde:: { de, Deserialize } ;
57
+ use std:: path:: PathBuf ;
59
58
60
59
use crate :: cfg_flag:: CfgFlag ;
61
60
@@ -99,26 +98,24 @@ impl ProjectJson {
99
98
/// * `data` - The parsed contents of `rust-project.json`, or project json that's passed via
100
99
/// configuration.
101
100
pub fn new ( base : & AbsPath , data : ProjectJsonData ) -> ProjectJson {
101
+ let absolutize =
102
+ |p| AbsPathBuf :: try_from ( p) . unwrap_or_else ( |path| base. join ( & path) ) . normalize ( ) ;
102
103
ProjectJson {
103
- sysroot : data. sysroot . map ( |it| base . join ( it ) ) ,
104
- sysroot_src : data. sysroot_src . map ( |it| base . join ( it ) ) ,
104
+ sysroot : data. sysroot . map ( absolutize ) ,
105
+ sysroot_src : data. sysroot_src . map ( absolutize ) ,
105
106
project_root : base. to_path_buf ( ) ,
106
107
crates : data
107
108
. crates
108
109
. into_iter ( )
109
110
. map ( |crate_data| {
110
- let is_workspace_member = crate_data. is_workspace_member . unwrap_or_else ( || {
111
- crate_data. root_module . is_relative ( )
112
- && !crate_data. root_module . starts_with ( ".." )
113
- || crate_data. root_module . starts_with ( base)
114
- } ) ;
115
- let root_module = base. join ( crate_data. root_module ) . normalize ( ) ;
111
+ let root_module = absolutize ( crate_data. root_module ) ;
112
+ let is_workspace_member = crate_data
113
+ . is_workspace_member
114
+ . unwrap_or_else ( || root_module. starts_with ( base) ) ;
116
115
let ( include, exclude) = match crate_data. source {
117
116
Some ( src) => {
118
117
let absolutize = |dirs : Vec < PathBuf > | {
119
- dirs. into_iter ( )
120
- . map ( |it| base. join ( it) . normalize ( ) )
121
- . collect :: < Vec < _ > > ( )
118
+ dirs. into_iter ( ) . map ( absolutize) . collect :: < Vec < _ > > ( )
122
119
} ;
123
120
( absolutize ( src. include_dirs ) , absolutize ( src. exclude_dirs ) )
124
121
}
@@ -145,17 +142,15 @@ impl ProjectJson {
145
142
cfg : crate_data. cfg ,
146
143
target : crate_data. target ,
147
144
env : crate_data. env ,
148
- proc_macro_dylib_path : crate_data
149
- . proc_macro_dylib_path
150
- . map ( |it| base. join ( it) ) ,
145
+ proc_macro_dylib_path : crate_data. proc_macro_dylib_path . map ( absolutize) ,
151
146
is_workspace_member,
152
147
include,
153
148
exclude,
154
149
is_proc_macro : crate_data. is_proc_macro ,
155
150
repository : crate_data. repository ,
156
151
}
157
152
} )
158
- . collect :: < Vec < _ > > ( ) ,
153
+ . collect ( ) ,
159
154
}
160
155
}
161
156
@@ -243,7 +238,7 @@ struct CrateSource {
243
238
exclude_dirs : Vec < PathBuf > ,
244
239
}
245
240
246
- fn deserialize_crate_name < ' de , D > ( de : D ) -> Result < CrateName , D :: Error >
241
+ fn deserialize_crate_name < ' de , D > ( de : D ) -> std :: result :: Result < CrateName , D :: Error >
247
242
where
248
243
D : de:: Deserializer < ' de > ,
249
244
{
0 commit comments