Skip to content

Add autocomplete for nested examples #15574

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/etc/cargo.bashcomp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ _get_examples(){
local manifest=$(_locate_manifest)
[ -z "$manifest" ] && return 0

local files=("${manifest%/*}"/examples/*.rs)
local files=("${manifest%/*}"/examples/**/*.rs)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we do something similar for zsh?

cargo/src/etc/_cargo

Lines 472 to 477 in c2c636a

_cargo_example_names() {
if [[ -d examples ]]; then
local -a files=(${(@f)$(echo examples/*.rs(:t:r))})
_values 'example' "${files[@]}"
fi
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could pick up both examples and submodules. Unsure whether that is worth it or not

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would be a little worried that the false-positive rate would be too high. In bevy for example, this would auto-complete a ton of names that aren't examples.

I think the only real solution here is to parse Cargo.toml, and I think native-completions is the only way to realistically do that. This bashcomp could do some json parsing of cargo metadata, but I wouldn't want to go there.

local names=("${files[@]##*/}")
local names=("${names[@]%.*}")
# "*" means no examples found
Expand Down