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
[Console] Autocompletion problems #44729
Comments
Thanks for the issue! The actual issue raises from diff --git a/bin/phpstan b/bin/phpstan
index b87104469..fd27ed0a6 100755
--- a/bin/phpstan
+++ b/bin/phpstan
@@ -88,7 +88,7 @@ use Symfony\Component\Console\Helper\ProgressBar;
$version = 'Version unknown';
try {
- $version = \Jean85\PrettyVersions::getVersion('phpstan/phpstan')->getPrettyVersion();
+ $version = \Jean85\PrettyVersions::getVersion('phpstan/phpstan')->getPrettyVersion() ?: 'Version unknown';
} catch (\OutOfBoundsException $e) {
} However, this issue made me realize that we probably forgot about the standalone app usage when implementing This option is used to determine if the installed shell completion script is still compatible with the complete command in Symfony (e.g. if we add a feature in 6.1 that requires a modification of the bash script). However, we currently set it using |
👍 for adding a completion version that is incremented only when there is a breaking change. Like composer does for plugins. |
yeah. either that or we should use |
After patching bin/phpstan like this: @@ -88,7 +88,7 @@ use Symfony\Component\Console\Helper\ProgressBar;
$version = 'Version unknown';
try {
- $version = \Jean85\PrettyVersions::getVersion('phpstan/phpstan')->getPrettyVersion();
+ $version = \Jean85\PrettyVersions::getVersion('phpstan/phpstan')->getPrettyVersion() ?: $version;
} catch (\OutOfBoundsException $e) {
} I'm getting this when I try to autocomplete:
|
@ondrejmirtes this patch is not the solution, as the script still expects to have something matching the version of symfony/console |
Maybe something under the |
The suggestion by @stof was exactly the solution I had in mind when I suggested this flag: we need to know which version of Symfony Console created the completion script. This means the version of Symfony Console should always get hardcoded into the resulting (Bash, Zsh, Fish) script, if that currently doesn't happen in any scenario (framework, just the component, etc), it's a bug. IMO if it ends up being |
@wouterj it should not pass PHPStan's version here because it will not make sense to the Symfony completion command (which will in the future notify the user the completion script needs to be updated), it should in all cases be Alternative to this is PHPStan also overriding the |
For clarity, let's keep discussions separate :) I've moved the Unless that issue is fixed, we're now focusing on testing PHPstan completion with the application's version. For this, the patch used by @ondrejmirtes is correct. The Some background: we need this advanced completion function as Bash does not support commands with colons in it - which are very common in apps using Symfony Console. |
Hi, I'd love the autocompletion to work with as little user intervention as possible. Otherwise I can't really sell this to PHPStan users if they need to figure out how to make it work on their machine in the first place :) For example I've got this in my # Check for interactive bash and that we haven't already been sourced.
[ -z "$BASH_VERSION" -o -z "$PS1" -o -n "$BASH_COMPLETION" ] && return
# Check for recent enough version of bash.
bash=${BASH_VERSION%.*}; bmajor=${bash%.*}; bminor=${bash#*.}
if [ $bmajor -gt 3 ] || [ $bmajor -eq 3 -a $bminor -ge 2 ]; then
if shopt -q progcomp && [ -r /opt/homebrew/Cellar/bash-completion/1.3_3/etc/bash_completion ]; then
# Source completion code.
. /opt/homebrew/Cellar/bash-completion/1.3_3/etc/bash_completion
fi
fi
unset bash bmajor bminor And apparently this is all I need to make $ git clone --<TAB>
--bare --jobs= --recurse-submodules --shared
--branch= --local --reference-if-able= --single-branch
--checkout --mirror --reference= --sparse
--config= --no-... --reject-shallow --tags
--depth= --no-checkout --remote-submodules --template=
--dissociate --no-hardlinks --separate-git-dir= --upload-pack=
--filter= --no-tags --server-option= --verbose
--hardlinks --origin= --shallow-exclude=
--ipv4 --progress --shallow-since=
--ipv6 --quiet --shallow-submodules Could Symfony do something similar? E.g. once autocompletion for other tools works on my system, Symfony would also work automatically? As you can see, I know nothing about bash, I just know what the end goal for the end user should be :) Another thing that's not clear to me is what should be done when PHPStan is installed multiple times locally in different projects and maybe even in different versions. Do I need currently need to run |
The reason
|
Is it possible to architect the solution in such a way that there would have to be only one bash completion script for all Symfony apps? It'd be nice to somehow get into those OS packages and have for example BTW I made it work, it's really nice! :)
I made it work by running |
No, the completion script's last line registers the completion function for a specific executable name, in your case complete -F _sf_phpstan phpstan It cannot be registered for all Symfony based apps because it doesn't know all of their (executable) names. Even if it's exactly the same script, it will need to be created/registered for each individual app. That's the reason why the That could be added as a feature: allow specifying additional names in the completion command, so you could do for example:
And it would generate
But IMO, it would be very unwieldy and messy for the user. Maybe core team disagrees. Great, looks good. |
BTW this is exactly my expectation what will happen when composer/composer#10292 is merged, the package maintainers put the completion script(s) generated by the executable into the OS packages and it just works. |
Hey, thanks for your report! |
Friendly reminder that this issue exists. If I don't hear anything I'll close this. |
I believe this is now fixed in 6.2 by #46901 |
Symfony version(s) affected
5.4.1
Description
I'm trying out the new autocompletion feature on a console app. I've put
eval "$(/Users/ondrej/Development/phpstan/bin/phpstan completion bash)"
into my~/.bash_profile
file.I'm trying to autocomplete various things like option names and command names, but unsuccessfully. This is how the output looks like:
And after pressing enter, the default command of the application runs.
How to reproduce
Possible Solution
No response
Additional Context
This is how the bash completion script looks like:
The text was updated successfully, but these errors were encountered: