@@ -1218,8 +1218,11 @@ fn get_example_candidates() -> Vec<clap_complete::CompletionCandidate> {
1218
1218
get_targets_from_metadata ( )
1219
1219
. unwrap_or_default ( )
1220
1220
. into_iter ( )
1221
- . filter_map ( |target| match target. kind ( ) {
1222
- TargetKind :: ExampleBin => Some ( clap_complete:: CompletionCandidate :: new ( target. name ( ) ) ) ,
1221
+ . filter_map ( |( pkg_name, target) | match target. kind ( ) {
1222
+ TargetKind :: ExampleBin => Some (
1223
+ clap_complete:: CompletionCandidate :: new ( target. name ( ) )
1224
+ . help ( Some ( format ! ( "(from {})" , pkg_name) . into ( ) ) ) ,
1225
+ ) ,
1223
1226
_ => None ,
1224
1227
} )
1225
1228
. collect :: < Vec < _ > > ( )
@@ -1229,8 +1232,11 @@ fn get_bench_candidates() -> Vec<clap_complete::CompletionCandidate> {
1229
1232
get_targets_from_metadata ( )
1230
1233
. unwrap_or_default ( )
1231
1234
. into_iter ( )
1232
- . filter_map ( |target| match target. kind ( ) {
1233
- TargetKind :: Bench => Some ( clap_complete:: CompletionCandidate :: new ( target. name ( ) ) ) ,
1235
+ . filter_map ( |( pkg_name, target) | match target. kind ( ) {
1236
+ TargetKind :: Bench => Some (
1237
+ clap_complete:: CompletionCandidate :: new ( target. name ( ) )
1238
+ . help ( Some ( format ! ( "(from {})" , pkg_name) . into ( ) ) ) ,
1239
+ ) ,
1234
1240
_ => None ,
1235
1241
} )
1236
1242
. collect :: < Vec < _ > > ( )
@@ -1240,8 +1246,11 @@ fn get_test_candidates() -> Vec<clap_complete::CompletionCandidate> {
1240
1246
get_targets_from_metadata ( )
1241
1247
. unwrap_or_default ( )
1242
1248
. into_iter ( )
1243
- . filter_map ( |target| match target. kind ( ) {
1244
- TargetKind :: Test => Some ( clap_complete:: CompletionCandidate :: new ( target. name ( ) ) ) ,
1249
+ . filter_map ( |( pkg_name, target) | match target. kind ( ) {
1250
+ TargetKind :: Test => Some (
1251
+ clap_complete:: CompletionCandidate :: new ( target. name ( ) )
1252
+ . help ( Some ( format ! ( "(from {})" , pkg_name) . into ( ) ) ) ,
1253
+ ) ,
1245
1254
_ => None ,
1246
1255
} )
1247
1256
. collect :: < Vec < _ > > ( )
@@ -1251,14 +1260,17 @@ fn get_bin_candidates() -> Vec<clap_complete::CompletionCandidate> {
1251
1260
get_targets_from_metadata ( )
1252
1261
. unwrap_or_default ( )
1253
1262
. into_iter ( )
1254
- . filter_map ( |target| match target. kind ( ) {
1255
- TargetKind :: Bin => Some ( clap_complete:: CompletionCandidate :: new ( target. name ( ) ) ) ,
1263
+ . filter_map ( |( pkg_name, target) | match target. kind ( ) {
1264
+ TargetKind :: Bin => Some (
1265
+ clap_complete:: CompletionCandidate :: new ( target. name ( ) )
1266
+ . help ( Some ( format ! ( "(from {})" , pkg_name) . into ( ) ) ) ,
1267
+ ) ,
1256
1268
_ => None ,
1257
1269
} )
1258
1270
. collect :: < Vec < _ > > ( )
1259
1271
}
1260
1272
1261
- fn get_targets_from_metadata ( ) -> CargoResult < Vec < Target > > {
1273
+ fn get_targets_from_metadata ( ) -> CargoResult < Vec < ( InternedString , Target ) > > {
1262
1274
let cwd = std:: env:: current_dir ( ) ?;
1263
1275
let gctx = GlobalContext :: new ( shell:: Shell :: new ( ) , cwd. clone ( ) , cargo_home_with_cwd ( & cwd) ?) ;
1264
1276
let ws = Workspace :: new ( & find_root_manifest_for_wd ( & cwd) ?, & gctx) ?;
@@ -1267,7 +1279,7 @@ fn get_targets_from_metadata() -> CargoResult<Vec<Target>> {
1267
1279
1268
1280
let targets = packages
1269
1281
. into_iter ( )
1270
- . flat_map ( |pkg| pkg. targets ( ) . into_iter ( ) . cloned ( ) )
1282
+ . flat_map ( |pkg| pkg. targets ( ) . into_iter ( ) . cloned ( ) . map ( |t| ( pkg . name ( ) , t ) ) )
1271
1283
. collect :: < Vec < _ > > ( ) ;
1272
1284
1273
1285
Ok ( targets)
0 commit comments