@@ -12,17 +12,9 @@ use stdx::split_delim;
12
12
/// Roots and crates that compose this Rust project.
13
13
#[ derive( Clone , Debug , Eq , PartialEq ) ]
14
14
pub struct ProjectJson {
15
- pub ( crate ) roots : Vec < Root > ,
16
15
pub ( crate ) crates : Vec < Crate > ,
17
16
}
18
17
19
- /// A root points to the directory which contains Rust crates. rust-analyzer watches all files in
20
- /// all roots. Roots might be nested.
21
- #[ derive( Clone , Debug , Eq , PartialEq ) ]
22
- pub struct Root {
23
- pub ( crate ) path : AbsPathBuf ,
24
- }
25
-
26
18
/// A crate points to the root module of a crate and lists the dependencies of the crate. This is
27
19
/// useful in creating the crate graph.
28
20
#[ derive( Clone , Debug , Eq , PartialEq ) ]
@@ -35,12 +27,13 @@ pub struct Crate {
35
27
pub ( crate ) out_dir : Option < AbsPathBuf > ,
36
28
pub ( crate ) proc_macro_dylib_path : Option < AbsPathBuf > ,
37
29
pub ( crate ) is_workspace_member : bool ,
30
+ pub ( crate ) include : Vec < AbsPathBuf > ,
31
+ pub ( crate ) exclude : Vec < AbsPathBuf > ,
38
32
}
39
33
40
34
impl ProjectJson {
41
35
pub fn new ( base : & AbsPath , data : ProjectJsonData ) -> ProjectJson {
42
36
ProjectJson {
43
- roots : data. roots . into_iter ( ) . map ( |path| Root { path : base. join ( path) } ) . collect ( ) ,
44
37
crates : data
45
38
. crates
46
39
. into_iter ( )
@@ -50,8 +43,19 @@ impl ProjectJson {
50
43
&& !crate_data. root_module . starts_with ( ".." )
51
44
|| crate_data. root_module . starts_with ( base)
52
45
} ) ;
46
+ let root_module = base. join ( crate_data. root_module ) ;
47
+ let ( include, exclude) = match crate_data. source {
48
+ Some ( src) => {
49
+ let absolutize = |dirs : Vec < PathBuf > | {
50
+ dirs. into_iter ( ) . map ( |it| base. join ( it) ) . collect :: < Vec < _ > > ( )
51
+ } ;
52
+ ( absolutize ( src. include_dirs ) , absolutize ( src. exclude_dirs ) )
53
+ }
54
+ None => ( vec ! [ root_module. parent( ) . unwrap( ) . to_path_buf( ) ] , Vec :: new ( ) ) ,
55
+ } ;
56
+
53
57
Crate {
54
- root_module : base . join ( crate_data . root_module ) ,
58
+ root_module,
55
59
edition : crate_data. edition . into ( ) ,
56
60
deps : crate_data
57
61
. deps
@@ -79,6 +83,8 @@ impl ProjectJson {
79
83
. proc_macro_dylib_path
80
84
. map ( |it| base. join ( it) ) ,
81
85
is_workspace_member,
86
+ include,
87
+ exclude,
82
88
}
83
89
} )
84
90
. collect :: < Vec < _ > > ( ) ,
@@ -88,7 +94,6 @@ impl ProjectJson {
88
94
89
95
#[ derive( Deserialize ) ]
90
96
pub struct ProjectJsonData {
91
- roots : Vec < PathBuf > ,
92
97
crates : Vec < CrateData > ,
93
98
}
94
99
@@ -103,6 +108,7 @@ struct CrateData {
103
108
out_dir : Option < PathBuf > ,
104
109
proc_macro_dylib_path : Option < PathBuf > ,
105
110
is_workspace_member : Option < bool > ,
111
+ source : Option < CrateSource > ,
106
112
}
107
113
108
114
#[ derive( Deserialize ) ]
@@ -132,6 +138,12 @@ struct DepData {
132
138
name : CrateName ,
133
139
}
134
140
141
+ #[ derive( Deserialize ) ]
142
+ struct CrateSource {
143
+ include_dirs : Vec < PathBuf > ,
144
+ exclude_dirs : Vec < PathBuf > ,
145
+ }
146
+
135
147
fn deserialize_crate_name < ' de , D > ( de : D ) -> Result < CrateName , D :: Error >
136
148
where
137
149
D : de:: Deserializer < ' de > ,
0 commit comments