-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
base: master
Are you sure you want to change the base?
Conversation
@@ -246,7 +246,7 @@ _get_examples(){ | |||
local manifest=$(_locate_manifest) | |||
[ -z "$manifest" ] && return 0 | |||
|
|||
local files=("${manifest%/*}"/examples/*.rs) | |||
local files=("${manifest%/*}"/examples/**/*.rs) |
There was a problem hiding this comment.
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?
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 | |
} |
@@ -246,7 +246,7 @@ _get_examples(){ | |||
local manifest=$(_locate_manifest) | |||
[ -z "$manifest" ] && return 0 | |||
|
|||
local files=("${manifest%/*}"/examples/*.rs) | |||
local files=("${manifest%/*}"/examples/**/*.rs) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
Are you aware of our experimental completion system (docs)? It uses |
@epage I wasn't aware of the experimental system, just wanted to contribute back a quick fix I had. |
What does this PR try to resolve?
Not all examples show up in auto-completion.
If the
examples
directory has nested examples, only the top level ones will be shown withcargo build --example<TAB>
.cargo build --example<TAB>
.Bevy examples only show
hello_world
instead of all available examples.Old:

New:

How should we test and review this PR?
The completion logic for me is in
~/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/etc/bash_completion.d/cargo
.So to test, this has to be edited as it doesn't get updated when you simply build cargo (I think rustup installs it).
Then go into a Rust project with nested examples (e. g. Bevy) and type
cargo build --example
and press<TAB>
.