Skip to content

Commit 11966a4

Browse files
committed
Auto merge of #12606 - Angelin01:tab-completion-rustup-fallback-rustc, r=weihanglo
Tab completion for --target uses rustup but fallsback to rustc ### What does this PR try to resolve? Fixes #12585 Currently, not only is the tab completion for `--target` inconsistent between bash and zsh, it depends on rustup and rustc respectively. As discussed in the issue at hand, we'll use `rustup` if it is available and fallback to `rustc` if it is not, even if it is unfriendly. ### How should we test and review this PR? Source the respective completion functions and test it out with `cargo build --target [TAB]`. **I would appreciate if someone that regularly uses zsh would test this.** I did basic testing, but since I don't use zsh commonly I am unsure if everything is as it should be. ### Additional information I switched to using `rustup target list --installed` instead of grabbing lines that contain "default" or "installed". I believe that any "default" target should be installed too, right?
2 parents 6031cda + b5c97d4 commit 11966a4

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

src/etc/_cargo

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -408,9 +408,15 @@ _cargo_cmds() {
408408
}
409409

410410
_cargo_target_triple() {
411-
local -a targets
412-
targets=( ${(f)"$(rustc --print target-list)"} )
413-
_describe 'target triple' targets
411+
local -a result
412+
413+
if (( $+commands[rustup] )); then
414+
result=( ${(f)"$(rustup target list --installed)"} )
415+
else
416+
result=( ${(f)"$(rustc --print target-list)"} )
417+
fi
418+
419+
_describe 'target triple' result
414420
}
415421

416422
#FIXME: Disabled until fixed

src/etc/cargo.bashcomp.sh

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -250,15 +250,11 @@ _get_examples(){
250250
}
251251

252252
_get_targets(){
253-
local result=()
254-
local targets=$(rustup target list)
255-
while read line
256-
do
257-
if [[ "$line" =~ default|installed ]]; then
258-
result+=("${line%% *}")
259-
fi
260-
done <<< "$targets"
261-
echo "${result[@]}"
253+
if command -v rustup >/dev/null 2>/dev/null; then
254+
rustup target list --installed
255+
else
256+
rustc --print target-list
257+
fi
262258
}
263259

264260
_toolchains(){

0 commit comments

Comments
 (0)