@@ -1199,7 +1199,6 @@ impl Config {
1199
1199
}
1200
1200
1201
1201
pub fn cargo ( & self ) -> CargoConfig {
1202
- let target_directory = self . target_dir_from_config ( ) ;
1203
1202
let rustc_source = self . data . rustc_source . as_ref ( ) . map ( |rustc_src| {
1204
1203
if rustc_src == "discover" {
1205
1204
RustLibSource :: Discover
@@ -1217,10 +1216,6 @@ impl Config {
1217
1216
let sysroot_src =
1218
1217
self . data . cargo_sysrootSrc . as_ref ( ) . map ( |sysroot| self . root_path . join ( sysroot) ) ;
1219
1218
1220
- let mut extra_args = self . data . cargo_extraArgs . clone ( ) ;
1221
-
1222
- add_target_dir_to_args ( & mut extra_args, target_directory) ;
1223
-
1224
1219
CargoConfig {
1225
1220
features : match & self . data . cargo_features {
1226
1221
CargoFeaturesDef :: All => CargoFeatures :: All ,
@@ -1273,8 +1268,9 @@ impl Config {
1273
1268
InvocationLocation :: Workspace => project_model:: InvocationLocation :: Workspace ,
1274
1269
} ,
1275
1270
run_build_script_command : self . data . cargo_buildScripts_overrideCommand . clone ( ) ,
1276
- extra_args,
1271
+ extra_args : self . data . cargo_extraArgs . clone ( ) ,
1277
1272
extra_env : self . data . cargo_extraEnv . clone ( ) ,
1273
+ target_dir : self . target_dir_from_config ( ) ,
1278
1274
}
1279
1275
}
1280
1276
@@ -1293,14 +1289,10 @@ impl Config {
1293
1289
}
1294
1290
1295
1291
pub fn flycheck ( & self ) -> FlycheckConfig {
1296
- let target_directory = self . target_dir_from_config ( ) ;
1297
-
1298
1292
match & self . data . check_overrideCommand {
1299
1293
Some ( args) if !args. is_empty ( ) => {
1300
1294
let mut args = args. clone ( ) ;
1301
1295
let command = args. remove ( 0 ) ;
1302
- add_target_dir_to_args ( & mut args, target_directory) ;
1303
-
1304
1296
FlycheckConfig :: CustomCommand {
1305
1297
command,
1306
1298
args,
@@ -1319,54 +1311,50 @@ impl Config {
1319
1311
} ,
1320
1312
}
1321
1313
}
1322
- Some ( _) | None => {
1323
- let mut extra_args = self . check_extra_args ( ) ;
1324
- add_target_dir_to_args ( & mut extra_args, target_directory) ;
1325
-
1326
- FlycheckConfig :: CargoCommand {
1327
- command : self . data . check_command . clone ( ) ,
1328
- target_triples : self
1329
- . data
1330
- . check_targets
1331
- . clone ( )
1332
- . and_then ( |targets| match & targets. 0 [ ..] {
1333
- [ ] => None ,
1334
- targets => Some ( targets. into ( ) ) ,
1335
- } )
1336
- . unwrap_or_else ( || self . data . cargo_target . clone ( ) . into_iter ( ) . collect ( ) ) ,
1337
- all_targets : self . data . check_allTargets ,
1338
- no_default_features : self
1339
- . data
1340
- . check_noDefaultFeatures
1341
- . unwrap_or ( self . data . cargo_noDefaultFeatures ) ,
1342
- all_features : matches ! (
1343
- self . data. check_features. as_ref( ) . unwrap_or( & self . data. cargo_features) ,
1344
- CargoFeaturesDef :: All
1345
- ) ,
1346
- features : match self
1347
- . data
1348
- . check_features
1349
- . clone ( )
1350
- . unwrap_or_else ( || self . data . cargo_features . clone ( ) )
1351
- {
1352
- CargoFeaturesDef :: All => vec ! [ ] ,
1353
- CargoFeaturesDef :: Selected ( it) => it,
1354
- } ,
1355
- extra_args,
1356
- extra_env : self . check_extra_env ( ) ,
1357
- ansi_color_output : self . color_diagnostic_output ( ) ,
1358
- }
1359
- }
1314
+ Some ( _) | None => FlycheckConfig :: CargoCommand {
1315
+ command : self . data . check_command . clone ( ) ,
1316
+ target_triples : self
1317
+ . data
1318
+ . check_targets
1319
+ . clone ( )
1320
+ . and_then ( |targets| match & targets. 0 [ ..] {
1321
+ [ ] => None ,
1322
+ targets => Some ( targets. into ( ) ) ,
1323
+ } )
1324
+ . unwrap_or_else ( || self . data . cargo_target . clone ( ) . into_iter ( ) . collect ( ) ) ,
1325
+ all_targets : self . data . check_allTargets ,
1326
+ no_default_features : self
1327
+ . data
1328
+ . check_noDefaultFeatures
1329
+ . unwrap_or ( self . data . cargo_noDefaultFeatures ) ,
1330
+ all_features : matches ! (
1331
+ self . data. check_features. as_ref( ) . unwrap_or( & self . data. cargo_features) ,
1332
+ CargoFeaturesDef :: All
1333
+ ) ,
1334
+ features : match self
1335
+ . data
1336
+ . check_features
1337
+ . clone ( )
1338
+ . unwrap_or_else ( || self . data . cargo_features . clone ( ) )
1339
+ {
1340
+ CargoFeaturesDef :: All => vec ! [ ] ,
1341
+ CargoFeaturesDef :: Selected ( it) => it,
1342
+ } ,
1343
+ extra_args : self . check_extra_args ( ) ,
1344
+ extra_env : self . check_extra_env ( ) ,
1345
+ ansi_color_output : self . color_diagnostic_output ( ) ,
1346
+ target_dir : self . target_dir_from_config ( ) ,
1347
+ } ,
1360
1348
}
1361
1349
}
1362
1350
1363
- fn target_dir_from_config ( & self ) -> Option < String > {
1351
+ fn target_dir_from_config ( & self ) -> Option < PathBuf > {
1364
1352
self . data
1365
1353
. rust_analyzerTargetDir
1366
1354
. as_ref ( )
1367
1355
. map ( |target_dir| match target_dir {
1368
1356
TargetDirectory :: UseSubdirectory ( yes) if * yes => {
1369
- Some ( String :: from ( "target/rust-analyzer" ) )
1357
+ Some ( PathBuf :: from ( "target/rust-analyzer" ) )
1370
1358
}
1371
1359
TargetDirectory :: UseSubdirectory ( _) => None ,
1372
1360
TargetDirectory :: Directory ( dir) => Some ( dir. clone ( ) ) ,
@@ -1725,13 +1713,6 @@ impl Config {
1725
1713
self . is_visual_studio_code
1726
1714
}
1727
1715
}
1728
-
1729
- fn add_target_dir_to_args ( args : & mut Vec < String > , target_dir : Option < String > ) {
1730
- if let Some ( target_dir) = target_dir {
1731
- args. push ( format ! ( "--target-dir={}" , target_dir) ) ;
1732
- }
1733
- }
1734
-
1735
1716
// Deserialization definitions
1736
1717
1737
1718
macro_rules! create_bool_or_string_de {
@@ -2084,7 +2065,7 @@ pub enum MemoryLayoutHoverRenderKindDef {
2084
2065
#[ serde( untagged) ]
2085
2066
pub enum TargetDirectory {
2086
2067
UseSubdirectory ( bool ) ,
2087
- Directory ( String ) ,
2068
+ Directory ( PathBuf ) ,
2088
2069
}
2089
2070
2090
2071
macro_rules! _config_data {
@@ -2703,9 +2684,8 @@ mod tests {
2703
2684
} ) )
2704
2685
. unwrap ( ) ;
2705
2686
assert_eq ! ( config. data. rust_analyzerTargetDir, None ) ;
2706
- assert_eq ! ( config. cargo( ) . extra_args. len( ) , 0 ) ;
2707
2687
assert ! (
2708
- matches!( config. flycheck( ) , FlycheckConfig :: CargoCommand { extra_args , .. } if extra_args . is_empty ( ) )
2688
+ matches!( config. flycheck( ) , FlycheckConfig :: CargoCommand { target_dir , .. } if target_dir == None )
2709
2689
) ;
2710
2690
}
2711
2691
@@ -2726,12 +2706,8 @@ mod tests {
2726
2706
config. data. rust_analyzerTargetDir,
2727
2707
Some ( TargetDirectory :: UseSubdirectory ( true ) )
2728
2708
) ;
2729
- assert_eq ! (
2730
- config. cargo( ) . extra_args,
2731
- vec![ "--target-dir=target/rust-analyzer" . to_string( ) ]
2732
- ) ;
2733
2709
assert ! (
2734
- matches!( config. flycheck( ) , FlycheckConfig :: CargoCommand { extra_args , .. } if extra_args == vec! [ "-- target-dir=target /rust-analyzer". to_string ( ) ] )
2710
+ matches!( config. flycheck( ) , FlycheckConfig :: CargoCommand { target_dir , .. } if target_dir == Some ( PathBuf :: from ( " target/rust-analyzer") ) )
2735
2711
) ;
2736
2712
}
2737
2713
@@ -2750,11 +2726,10 @@ mod tests {
2750
2726
. unwrap ( ) ;
2751
2727
assert_eq ! (
2752
2728
config. data. rust_analyzerTargetDir,
2753
- Some ( TargetDirectory :: Directory ( "other_folder" . to_string ( ) ) )
2729
+ Some ( TargetDirectory :: Directory ( PathBuf :: from ( "other_folder" ) ) )
2754
2730
) ;
2755
- assert_eq ! ( config. cargo( ) . extra_args, vec![ "--target-dir=other_folder" . to_string( ) ] ) ;
2756
2731
assert ! (
2757
- matches!( config. flycheck( ) , FlycheckConfig :: CargoCommand { extra_args , .. } if extra_args == vec! [ "--target-dir= other_folder". to_string ( ) ] )
2732
+ matches!( config. flycheck( ) , FlycheckConfig :: CargoCommand { target_dir , .. } if target_dir == Some ( PathBuf :: from ( " other_folder") ) )
2758
2733
) ;
2759
2734
}
2760
2735
}
0 commit comments