Skip to content

Commit

Permalink
Auto merge of #12606 - Angelin01:tab-completion-rustup-fallback-rustc…
Browse files Browse the repository at this point in the history
…, 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?
  • Loading branch information
bors committed Aug 31, 2023
2 parents 6031cda + b5c97d4 commit 11966a4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
12 changes: 9 additions & 3 deletions src/etc/_cargo
Original file line number Diff line number Diff line change
Expand Up @@ -408,9 +408,15 @@ _cargo_cmds() {
}

_cargo_target_triple() {
local -a targets
targets=( ${(f)"$(rustc --print target-list)"} )
_describe 'target triple' targets
local -a result

if (( $+commands[rustup] )); then
result=( ${(f)"$(rustup target list --installed)"} )
else
result=( ${(f)"$(rustc --print target-list)"} )
fi

_describe 'target triple' result
}

#FIXME: Disabled until fixed
Expand Down
14 changes: 5 additions & 9 deletions src/etc/cargo.bashcomp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -250,15 +250,11 @@ _get_examples(){
}

_get_targets(){
local result=()
local targets=$(rustup target list)
while read line
do
if [[ "$line" =~ default|installed ]]; then
result+=("${line%% *}")
fi
done <<< "$targets"
echo "${result[@]}"
if command -v rustup >/dev/null 2>/dev/null; then
rustup target list --installed
else
rustc --print target-list
fi
}

_toolchains(){
Expand Down

0 comments on commit 11966a4

Please sign in to comment.