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
feat: get completion for composer commands #5756
feat: get completion for composer commands #5756
Conversation
Download the artifacts for this pull request:
See Testing a PR |
Although I'm a bash stalwart, there are an awful lot of zsh users out there, and it seems like most of them have oh-my-zsh. |
I use ohmyzsh myself. Composer doesn't currently support autocompletion for zsh. There's a ohmyzsh plugin that provides composer completion - I'd say if zsh stans want completion for |
Upon reflection it occurred to me that cobra will handle making the completion results correct for a given shell - and indeed it does. So we can just tell composer we're using bash (just to get the completion suggestions) and then feed those to cobra, and cobra can feed them to our shell in the correct format. Testing locally in zsh it works well. I don't have fish so I can't check that - but there's no reason to assume it won't work. I'll update the PR description to match. |
Note that I've made the adjustment as a separate commit so that this PR still contains a record of what the code looked like for finding the host shell. That might still come in handy some day. |
And had one last epiphany. I said there'd be no container when running Note I've also hidden Assuming CI goes green, this should be good to go now. |
FParseErrWhitelist: cobra.FParseErrWhitelist{ | ||
UnknownFlags: true, | ||
}, | ||
Short: "Executes 'composer create-project' within the web container with the arguments and flags provided", | ||
DisableFlagParsing: true, |
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'm 90% sure DisableFlagParsing
and FParseErrWhitelist: cobra.FParseErrWhitelist{UnknownFlags: true}
are functionally equivalent as far as running the command goes - but DisableFlagParsing
is explicitly required for the completion function to be called. Not sure why, couldn't find any docs on it, but that's why I've made this particular change.
pkg/exec/exec.go
Outdated
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.
Changes in this file were automatically made by my IDE because in my first commit I had added some code there, then in the second commit I removed it again.
See #5756 (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.
This seems great to me, manually tested and it did all the things. It can go in when the tests are green; currently TestComposerCreateAutocomplete fails.
Running Could you please check if you can reproduce this locally, or give me some pointers about either how to reproduce it or what might be causing it to fail? |
It succeeds for me as well. I ran the whole file's tests in Goland, with GOTEST_SHORT=12 (drupal10). The buildkite tests use GOTEST_SHORT=8 (drupal9) But every single test failed, so the assumption has to be crosstalk between tests, some state is not being cleaned up. Try Or try running all the tests in the cmd directory with BTW, if you're not doing this already, you'll want to be running tests in vscode, it does a great job of running individual tests, and of course you can debug through them. You're awesome! Could you please PM me with your contact info (any way you want, Discord might be easiest?) I'd like to set up a meeting soon. |
The tests run in this order result in the failure:
|
Oh look, isn't this the same thing happening here? https://github.com/ddev/ddev/actions/runs/7778487300/job/21208251886?pr=5058 That's in #5058 which was recently rebased to upstream/master. However, upstream/master doesn't seem to be seeing this. |
Thanks! That worked, and I've adjusted the test accordingly. I was taking advantage of the site to test being started before my test run, but it seems that in some cases other tests will stop a site - so I need to make sure the sites are started before the test code is run. I've done this to both of the new autocompletion tests.
Thanks! I find with my workflow running tests in the terminal is preferable, though if I ever get a test that I need to debug properly I'll probably do that via vscode.
Aww, shucks, thanks.
I've flicked you an email. |
Congratulations! |
Looks like this is passing (just colima to go but with everything else passing I'd be shocked if that had a legitimate failure) |
Is autocomplete in general working for you @rpkoller ? For example, does |
|
You have to install autocompletion or any of this to work. https://ddev.readthedocs.io/en/latest/users/install/shell-completion/ |
on brief addition I did some digging trying to understand zsh completions and how to get them working for me (i've opened an issue about that #5803) and i've noticed that there actually is a completion for composer already available at |
To the best of my knowledge, that will work for composer itself (i.e. |
Figured I'd get this done while autocompletion is on my brain.
The Issue
There's no autocompletion for composer commands right now, other than what cobra can give us.
How This PR Solves The Issue
If the cwd is inside a project with a running web container, we request completions from composer in the container.
This should work for all shells cobra supports autocompletion for - which is more than composer itself!
I've also added autocompletion for the
create
command (pretty much only useful for flags, but that's not nothing) and hidden thecreate-project
command from completion suggestions.Manual Testing Instructions
Running in any shell cobra supports for autocompletion, type
ddev composer <tab>
, and other combinations you'd expect to get autocompletions for (likeddev composer re<tab>
to get completion suggestions forcomposer remove
andcomposer require
)Also try out
ddev composer create --<tab>
to see completion suggestions for the create command.Automated Testing Overview
Added a couple of small tests to check we do in fact get expected completions from composer. That test is pretty light because we don't need to actually test composer's auto completion suggestions - we just need to validate that we're passing the completion request through, and getting a correct response.
Related Issue Link(s)
N/A
Release/Deployment Notes
Should just work out of the box, no breaking changes, just nice auto complete goodness.