1
1
//! See `CargoTargetSpec`
2
2
3
+ use std:: mem;
4
+
3
5
use cfg:: { CfgAtom , CfgExpr } ;
4
6
use ide:: { FileId , RunnableKind , TestId } ;
5
7
use project_model:: { self , ManifestPath , TargetKind } ;
@@ -18,17 +20,22 @@ pub(crate) struct CargoTargetSpec {
18
20
pub ( crate ) package : String ,
19
21
pub ( crate ) target : String ,
20
22
pub ( crate ) target_kind : TargetKind ,
23
+ pub ( crate ) required_features : Vec < String > ,
21
24
}
22
25
23
26
impl CargoTargetSpec {
24
27
pub ( crate ) fn runnable_args (
25
28
snap : & GlobalStateSnapshot ,
26
- spec : Option < CargoTargetSpec > ,
29
+ mut spec : Option < CargoTargetSpec > ,
27
30
kind : & RunnableKind ,
28
31
cfg : & Option < CfgExpr > ,
29
32
) -> Result < ( Vec < String > , Vec < String > ) > {
30
33
let mut args = Vec :: new ( ) ;
31
34
let mut extra_args = Vec :: new ( ) ;
35
+
36
+ let target_required_features =
37
+ spec. as_mut ( ) . map ( |spec| mem:: take ( & mut spec. required_features ) ) . unwrap_or ( Vec :: new ( ) ) ;
38
+
32
39
match kind {
33
40
RunnableKind :: Test { test_id, attr } => {
34
41
args. push ( "test" . to_string ( ) ) ;
@@ -87,14 +94,20 @@ impl CargoTargetSpec {
87
94
let cargo_config = snap. config . cargo ( ) ;
88
95
if cargo_config. all_features {
89
96
args. push ( "--all-features" . to_string ( ) ) ;
97
+
98
+ for feature in target_required_features {
99
+ args. push ( "--features" . to_string ( ) ) ;
100
+ args. push ( feature) ;
101
+ }
90
102
} else {
91
103
let mut features = Vec :: new ( ) ;
92
104
if let Some ( cfg) = cfg. as_ref ( ) {
93
105
required_features ( cfg, & mut features) ;
94
106
}
95
- for feature in cargo_config. features {
96
- features. push ( feature. clone ( ) ) ;
97
- }
107
+
108
+ features. extend ( cargo_config. features ) ;
109
+ features. extend ( target_required_features) ;
110
+
98
111
features. dedup ( ) ;
99
112
for feature in features {
100
113
args. push ( "--features" . to_string ( ) ) ;
@@ -126,6 +139,7 @@ impl CargoTargetSpec {
126
139
package : cargo_ws. package_flag ( package_data) ,
127
140
target : target_data. name . clone ( ) ,
128
141
target_kind : target_data. kind ,
142
+ required_features : target_data. required_features . clone ( ) ,
129
143
} ;
130
144
131
145
Ok ( Some ( res) )
0 commit comments