Shell completions#3481
Conversation
|
I think this is now working on my machine. We have custom completions for template names (in Two hacks and one red herring were harmed in the making of this PR, but otherwise it has been surprisingly torment-free. |
|
Oh I suppose I should do the template management commands but those seem to happen mostly in the installer those days so my motivation is not skyrocketing. |
vdice
left a comment
There was a problem hiding this comment.
Tire kicker reporting in for duty. This appears to work a charm with my setup (Mac, bash). Very handy!
A few minor items:
-
When the only option is
--help, repeated Tabs will just keep appending. (egspin plugins update --help --help --help --help --help --help --help --help --help --help --help --help --help --help --help --help) (Clearly I need help.)Any chance when there is only one option (likely,
--helpas above), auto-complete won't attempt to append after the first injection? Or it could be this is just the case with completions in general; I admit I haven't cross-referenced others. (If it might be addressable, clearly a follow-up candidate!) -
For the new
generate-completionssub-command, I'm seeing the following:$ spin maintenance generate-completions --help Generate shell completions Usage: spin maintenance generate-completions Options: -h, --help Print helpAny chance this help output can include that a
COMPLETE=<shell>is required to do anything meaningful? And/or perhaps update the command itself to error out if noCOMPLETEvar is present (currently it appears to no-op).
Otherwise, a few vision-casting Qs:
-
Any thoughts on attempting an out-of-the-box experience with these completions? Not sure if that would mean bundling the supported shell completion scripts in with the binary, fetching them at install (script) time or what.
-
Is there a vision for plugins to offer completion scripts? Thinking eg
cloudorakadeploy plugins but presumably could/would apply to all. Do they somehow need to be added to the main/core Spin completion script or would they just be add'l scripts for the user to source?
|
Thanks so much for trying this out, Vaughn. It's very reassuring!
Hmm, that might be a clap-complete bug, although I don't see one listed.
Good catch - let me see if I can come up with something. The
Not sure yet. We could in theory run the I imagine we could integrate it into the Homebrew package, although I dunno if those are allowed to modify the profile. (It would not mean bundling the generated shell scripts. The idea seems to be that you run
Would you settle for a swirling mass of fog with vague hints of things that might be the shapes of visions barely perceptible within it? Shell completions go only off the program name, which is always |
577cc46 to
2d3c781
Compare
|
Tried it on Mac/zsh and it seems to work although not as snappy as I'd expect. But maybe we should ship it with the caveat that it may not be perfect but hey it's probably less worse than no completions at all and anyway if you do prefer nothing to imperfect then just don't install the completions? |
3b6c5eb to
a18ad3c
Compare
vdice
left a comment
There was a problem hiding this comment.
Definitely agree that it would be great to get this functionality in now and then iterate as needed from there. Might give @fibonacci1729 a chance to review finer points of the implementation; otherwise I can vouch the feature works nicely!
|
|
||
| impl GenerateCompletions { | ||
| async fn run() -> anyhow::Result<()> { | ||
| if std::env::var_os("COMPLETE").is_none() { |
There was a problem hiding this comment.
Could we re-use the is_completion_request func from lib.rs? Right now the emptiness check between these two are inconsistent.
There was a problem hiding this comment.
It's intentional that I didn't reuse is_completion_request - that function may well evolve if we find there are false positives. Whereas the check here is basically just to give a good error message if someone decides to type it into their terminal rather than following instructions, and is intentionally as minimal as possible so as not to give false negatives.
But I should add comments to explain that reasoning because it is highly non-obvious (and may, of course, be entirely wrong).
| next_display_order = None, | ||
| )] | ||
| #[expect(clippy::large_enum_variant)] | ||
| enum TheRealSpinApp { |
There was a problem hiding this comment.
As a favor to future us, could you leave a comment as to why this is needed?
There was a problem hiding this comment.
Something like:
// We use `UpCommandInner` here because `UpCommand` is intentionally lossy to handle trigger
specific flags and the completion generator require the lossless command.
There was a problem hiding this comment.
but what has future us done for me lately
fibonacci1729
left a comment
There was a problem hiding this comment.
It would be great if we could figure out how to eliminate TheRealSpinApp but that can be a follow up.
a18ad3c to
cbf4b3c
Compare
Ha, that is almost exactly what I wrote in my comment explaining why this stain on our otherwise beautiful program had to exist.
EDIT: BRIAN FIGURED OUT A WAY. Noting this here to give credit where credit is due. (Also, it occurs to me that |
Signed-off-by: itowlson <ivan.towlson@fermyon.com>
cbf4b3c to
ad41439
Compare
FIFTH TIME'S THE CHARM PLEASE LET FIFTH TIME BE THE CHARM
Okay this is still kinda WIP. I need to do a pass for other things that would benefit from completions other than "uh filename", and I need to figure out how to get any completions working at all with the new
spin upbecause oof. It also needs testing on zsh at minimum. But in the meantime, tyre kicking fans:HOW IT WORKS IF IT DOES WORK WHICH IS YET TO BE CONFIRMED
The idea is that
spin maintenance generate-completionsgenerates a bash script, and that generated bash script calls back into Spin to get the completions. That's why Spin now needs to check "am I being called for completions" and divert processing before doing normal command parsing. I am not entirely easy about this but it is what it is. Open to better thoughts.HOW TO USE IT
IMPORTANT: the
spinbinary must be on your PATH (as far as I can tell)spin maintenance generate-completionswith theCOMPLETEenvironment variable set to your shell. This will produce a completion script. E.g.COMPLETE=bash spin maintenance generate-completions >completions.shsourcethe completion script e.g.source ./completions.shIf this works reliably, then we can do what
clap-completedescribes - at startup, pipe the output script directly tosource. In this model, to install the completions is:(But obviously, "this works reliably" is vanishingly unlikely, so I'll probably see y'all back here in a year's time.)