Skip to content
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

[Feature] Complete packages after require statement #1

Open
nifr opened this issue Sep 10, 2014 · 3 comments
Open

[Feature] Complete packages after require statement #1

nifr opened this issue Sep 10, 2014 · 3 comments

Comments

@nifr
Copy link

nifr commented Sep 10, 2014

Hey Stephen,
first of all ... let me thank you for that awesome plugin. The idea of fetching valid suggestions from the available *Commands and InputOptions is brilliant and logical.

I've seen other completion functions capable of providing completions for the require command by using a (cached) result of composer show.

composer show -a | grep -v '^No composer' 

... can be used to find all available packages without the line ...

No composer.json found in the current directory, showing available packages from packagist

... if composer is executed inside a directory that has no composer.json.

I didn't have the time to dive into the code of the CompletionCommand yet.

Would you rather add something like this in the bash/zsh-snippets or do this in PHP with a ComposerCompletionCommand that extends CompletionCommand added to this repository?

@nifr
Copy link
Author

nifr commented Sep 10, 2014

Just for completeness:

composer archive <package>
composer show <package>

... should use the same list.

@stecman
Copy link
Owner

stecman commented Sep 12, 2014

Hey @nifr, I'm interested in adding this, though it'll be a bit of challenge making it run fast enough for completion to not be painful and show reasonably up to date package names. The completion behaviour can be implemented in PHP using a callback function as a completion handler.

The first call to composer show --available --name-only for me is pretty slow at ~14 seconds, and subsequent requests are still slow at ~4 seconds each, so that approach would need caching to some degree. Dumping the output of that command into a file and scanning it for matches seems like a good approach - matching against the full list only takes 20ms with grep, or ~170ms in PHP.

Another possible way to source package details would be to read the cached composer repository JSON files in ~/.composer/cache/repo/. This is faster than composer show at around 0.5 to 1s, but it doesn't list packages you've never downloaded and it's still not that snappy considering it has to parse tens of MB of JSON:

$ find ~/.composer/cache/repo/ -iname '*json' -exec du -ch {} +

You're welcome to have a go at implementing this. I'll have a think about a good solution in any case. Thanks for your other suggestions too 👍

@glensc
Copy link
Contributor

glensc commented Oct 18, 2014

https://github.com/iArren/composer-bash-completion does the caching into "packages.list" file. maybe do the same? extra ttl could be set too, perhaps 10-60 minutes to redo the fetch (could be smaller if cache is fetched in background)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants