completions/cargo: Fix package completion

The original only worked in the manifest directory *and* didn't even
list the right packages.

E.g. for fish it listed "printf", when the package is called
"fish-printf". So we're not keeping it because it's wrong.

Instead let's parse the actual json. It's a shame there is no
simple command to just get it line-delimited, of course.

Fixes #11384
This commit is contained in:
Fabian Boehm
2025-04-15 20:21:41 +02:00
parent ab7d52d727
commit 6ede047680

View File

@@ -45,9 +45,14 @@ function __fish_cargo_features
end
function __fish_cargo_packages
find . -name Cargo.toml | string replace -rf '.*/([^/]+)/?Cargo.toml' '$1'
if command -q jq
cargo metadata --no-deps --format-version 1 | jq -r '.packages | .[] | .name' | __fish_concat_completions
else if set -l python (__fish_anypython)
cargo metadata --no-deps --format-version 1 |
command $python -Sc "import sys, json"\n"print(*[x['name'] for x in json.load(sys.stdin)['packages']], sep='\n')"
end
end
complete -c cargo -n '__fish_seen_subcommand_from run test build debug check' -l package \
complete -c cargo -n '__fish_seen_subcommand_from run test build debug check clippy' -s p -l package \
-xa "(__fish_cargo_packages)"
## --- AUTO-GENERATED WITH `cargo complete fish` ---