Skip to content

Commit 7294675

Browse files
committed
fix(complete): Show local crates/features over other members
Our options are: - Not offer these completions - Hide them - De-prioritize them Since someone could be using `--package`, I felt de-prioritizing would give the best experience.
1 parent c775f34 commit 7294675

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/cargo/util/command_prelude.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1210,8 +1210,14 @@ fn get_feature_candidates() -> CargoResult<Vec<clap_complete::CompletionCandidat
12101210

12111211
// Add direct features with package info
12121212
for feature_name in package.summary().features().keys() {
1213+
let order = if ws.current_opt().map(|p| p.name()) == Some(package_name) {
1214+
0
1215+
} else {
1216+
1
1217+
};
12131218
feature_candidates.push(
12141219
clap_complete::CompletionCandidate::new(feature_name)
1220+
.display_order(Some(order))
12151221
.help(Some(format!("(from {})", package_name).into())),
12161222
);
12171223
}
@@ -1230,7 +1236,13 @@ fn get_crate_candidates(kind: TargetKind) -> CargoResult<Vec<clap_complete::Comp
12301236
.flat_map(|pkg| pkg.targets().into_iter().cloned().map(|t| (pkg.name(), t)))
12311237
.filter(|(_, target)| *target.kind() == kind)
12321238
.map(|(pkg_name, target)| {
1239+
let order = if ws.current_opt().map(|p| p.name()) == Some(pkg_name) {
1240+
0
1241+
} else {
1242+
1
1243+
};
12331244
clap_complete::CompletionCandidate::new(target.name())
1245+
.display_order(Some(order))
12341246
.help(Some(format!("(from {})", pkg_name).into()))
12351247
})
12361248
.collect::<Vec<_>>();

0 commit comments

Comments
 (0)