-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Add value hints to command line arguments to improve shell completion accuracy #17080
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
Conversation
konstin
left a comment
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.
Not deep into how shell completions work, but the code looks good.
crates/uv-cli/src/lib.rs
Outdated
| help_heading = "Python options", | ||
| value_parser = parse_maybe_string | ||
| value_parser = parse_maybe_string, | ||
| value_hint = ValueHint::CommandName, |
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 think --python <version> is the most common use-case here, not passing an executable name.
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.
The thought process here was that if someone wants to type a version they can still do so, and we have no particular way to complete them, but if they did want to specify a python executable instead, they would have an easier time due to completions being restricted to valid executables.
The default here is to do "_default" completion on zsh, which will complete files and things like that. So CommandName actually restricts this to fewer things.
The only alternative I can think of is to make this ValueHint::Other but this would prevent zsh from ever letting you complete paths to programs or programs in your path.
What do you think?
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 think we should probably use Other. I don't want to encourage people to use Python executables from their PATH here, I think that's rarely a desirable pattern and can be confusing.
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.
Fair enough, will change these.
crates/uv-cli/src/lib.rs
Outdated
| /// in a separate, ephemeral environment. These dependencies are allowed to conflict with those | ||
| /// specified by the project. | ||
| #[arg(long)] | ||
| #[arg(long, value_hint = ValueHint::Other)] |
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.
Editables are local directories
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 can't remember why I chose ValueHint::Other here ... I think I went into looking what an editable was and found that it could be a directory or some weird syntax. But that doesn't really justify not letting you complete directories.
Will fix.
The primary use for the python interpreter option is to specify a version, so default completing executables may be confusing. Until we have a more sophisticated completion here, it's appropriate to just disable completions.
This MR contains the following updates: | Package | Update | Change | |---|---|---| | [astral-sh/uv](https://github.com/astral-sh/uv) | patch | `0.9.17` -> `0.9.18` | MR created with the help of [el-capitano/tools/renovate-bot](https://gitlab.com/el-capitano/tools/renovate-bot). **Proposed changes to behavior should be submitted there as MRs.** --- ### Release Notes <details> <summary>astral-sh/uv (astral-sh/uv)</summary> ### [`v0.9.18`](https://github.com/astral-sh/uv/blob/HEAD/CHANGELOG.md#0918) [Compare Source](astral-sh/uv@0.9.17...0.9.18) Released on 2025-12-16. ##### Enhancements - Add value hints to command line arguments to improve shell completion accuracy ([#​17080](astral-sh/uv#17080)) - Improve error handling in `uv publish` ([#​17096](astral-sh/uv#17096)) - Improve rendering of multiline error messages ([#​17132](astral-sh/uv#17132)) - Support redirects in `uv publish` ([#​17130](astral-sh/uv#17130)) - Include Docker images with the alpine version, e.g., `python3.x-alpine3.23` ([#​17100](astral-sh/uv#17100)) ##### Configuration - Accept `--torch-backend` in `[tool.uv]` ([#​17116](astral-sh/uv#17116)) ##### Performance - Speed up `uv cache size` ([#​17015](astral-sh/uv#17015)) - Initialize S3 signer once ([#​17092](astral-sh/uv#17092)) ##### Bug fixes - Avoid panics due to reads on failed requests ([#​17098](astral-sh/uv#17098)) - Enforce latest-version in `@latest` requests ([#​17114](astral-sh/uv#17114)) - Explicitly set `EntryType` for file entries in tar ([#​17043](astral-sh/uv#17043)) - Ignore `pyproject.toml` index username in lockfile comparison ([#​16995](astral-sh/uv#16995)) - Relax error when using `uv add` with `UV_GIT_LFS` set ([#​17127](astral-sh/uv#17127)) - Support file locks on ExFAT on macOS ([#​17115](astral-sh/uv#17115)) - Change schema for `exclude-newer` into optional string ([#​17121](astral-sh/uv#17121)) ##### Documentation - Drop arm musl caveat from Docker documentation ([#​17111](astral-sh/uv#17111)) - Fix version reference in resolver example ([#​17085](astral-sh/uv#17085)) - Better documentation for `exclude-newer*` ([#​17079](astral-sh/uv#17079)) </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever MR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this MR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this MR, check this box --- This MR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0Mi41Ny4xIiwidXBkYXRlZEluVmVyIjoiNDIuNTcuMSIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOlsiUmVub3ZhdGUgQm90Il19-->
Summary
This partially addresses #17076 by adding
value_hintto various arguments.For cases where an option takes a path to either specifically a file or a directory directory,
ValueHint::FilePathandValueHint::DirPathare used respectively to try to limit the amount of noise presented by completions in shells which support it.For cases where a URL (and only a URL, not a path) can be supplied,
ValueHint::Urlis used.For cases where a python interpreter is to be specified,
ValueHint::CommandNameis used which will tab complete from$PATHby default, but will fall back to completing executable filenames if you start typing a path.Finally, for the many cases where there is no built in completion which would make sense, and where default completion of a path would make no sense (e.g. a package name, or version specifier, or date)
ValueHint::Otheris used to explicitly disable completion.Test Plan
Manually tested a bunch of these. These could be automated in the sense that we could snapshot the completion from zsh but I've not thought about how that could be done yet.