Skip to content

Commit 64b6a59

Browse files
committed
feat(completer): Add completion for --features flag
- Added completion for --features flag - Collect features from all workspaces
1 parent 84a38b9 commit 64b6a59

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

src/cargo/util/command_prelude.rs

+27-1
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,11 @@ pub trait CommandExt: Sized {
246246
"Space or comma separated list of features to activate",
247247
)
248248
.short('F')
249-
.help_heading(heading::FEATURE_SELECTION),
249+
.help_heading(heading::FEATURE_SELECTION)
250+
.add(clap_complete::ArgValueCandidates::new(|| {
251+
let candidates = get_feature_candidates();
252+
candidates.unwrap_or_default()
253+
})),
250254
)
251255
._arg(
252256
flag("all-features", "Activate all available features")
@@ -1169,6 +1173,28 @@ fn default_profile_candidates() -> Vec<clap_complete::CompletionCandidate> {
11691173
]
11701174
}
11711175

1176+
fn get_feature_candidates() -> CargoResult<Vec<clap_complete::CompletionCandidate>> {
1177+
let gctx = new_gctx_for_completions()?;
1178+
let manifest_path = find_root_manifest_for_wd(gctx.cwd())?;
1179+
let ws = Workspace::new(&manifest_path, &gctx)?;
1180+
let mut feature_candidates = Vec::new();
1181+
1182+
// Process all packages in the workspace
1183+
for package in ws.members() {
1184+
let package_name = package.name();
1185+
1186+
// Add direct features with package info
1187+
for feature_name in package.summary().features().keys() {
1188+
feature_candidates.push(
1189+
clap_complete::CompletionCandidate::new(feature_name)
1190+
.help(Some(format!("(from {})", package_name).into())),
1191+
);
1192+
}
1193+
}
1194+
1195+
Ok(feature_candidates)
1196+
}
1197+
11721198
fn get_example_candidates() -> Vec<clap_complete::CompletionCandidate> {
11731199
get_targets_from_metadata()
11741200
.unwrap_or_default()

0 commit comments

Comments
 (0)