Skip to content

[Console] Make CompletionSuggestions final #44229

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

Closed
wants to merge 1 commit into from

Conversation

wouterj
Copy link
Member

@wouterj wouterj commented Nov 23, 2021

Q A
Branch? 5.4
Bug fix? no
New feature? no
Deprecations? no
Tickets n/a
License MIT
Doc PR n/a

A very late call, but I suddenly realized we have to do something with the CompletionSuggestions class to not cut ourselves in the fingers for 6.1.

The problem: suggestValues() currently only allows string values. ZSH and FISH shells can have much more advanced completion support - also allowing descriptions for instance. Instead of making the completion integration shell specific, it is better to allow a DecoratedSuggestion or something like that, like suggested by @GromNaN in the ZSH PR

We won't add zsh/fish support in Symfony <6.1, so we must allow ourselves to widen the argument type in Symfony 6.1.

Another option is to add the basic DecoratedSuggestion and widen this argument type in Symfony 5.4 already, without immediately using its power.

Copy link
Member

@chalasr chalasr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@stof
Copy link
Member

stof commented Nov 23, 2021

Another option is to add the basic DecoratedSuggestion and widen this argument type in Symfony 5.4 already, without immediately using its power.

I would widen it now, making it easier to write code support 5.4 and 6.1 by always providing the suggestion with description in the command

@stof
Copy link
Member

stof commented Nov 23, 2021

Note that your current plan also requires widening the getValueSuggestions return type, which is a BC break even on final classes.

@stof
Copy link
Member

stof commented Nov 23, 2021

@wouterj if you want to go for the widening type version, you need to tag getValueSuggestions as @internal so that we can change its return type to widen it (should be OK, as I don't think commands need to use it)

@nicolas-grekas
Copy link
Member

nicolas-grekas commented Nov 23, 2021

Widening a return type is not a BC break so we could do it later.

@wouterj
Copy link
Member Author

wouterj commented Nov 23, 2021

Widening a return type is not a BC break so we could do it later.

Are you sure? This means that you can never safely rely on the return type if you're the calling side of the code.

@stof
Copy link
Member

stof commented Nov 23, 2021

Widening a return type is not a BC break so we could do it later.

it definitely is a BC break for callers (which is also why child classes are not allow to widen a return type of their parent).

@wouterj
Copy link
Member Author

wouterj commented Nov 23, 2021

@nicolas-grekas
Copy link
Member

nicolas-grekas commented Nov 23, 2021

It's a behavioral BC break if something unexpected is returned, but if there's an opt-in on the input side of the API, then it's fine.

@stof
Copy link
Member

stof commented Nov 23, 2021

so you would want to have getValueSuggestions($bcCastAsString = true) to make it backward compatible ?

We cannot rely on suggestValue() as being the opt-in for the return type of getValueSuggestions. Callers of the 2 methods can be in different places (the whole point of using that object is passing it around)

@wouterj
Copy link
Member Author

wouterj commented Nov 23, 2021

Oh: "Changing a return type is only possible with a child type.". As the proposed new suggestion class would be Stringable, I guess it's allowed.

@nicolas-grekas
Copy link
Member

The BC doc needs to tell about widening/narrowing :)

@stof
Copy link
Member

stof commented Nov 23, 2021

@wouterj Stringable is not a child type of string

@nicolas-grekas
Copy link
Member

So let's widen now indeed to be on the safe side.

@wouterj
Copy link
Member Author

wouterj commented Nov 23, 2021

I've proposed the alternative solution in a new PR: #44230

@stof
Copy link
Member

stof commented Nov 23, 2021

@nicolas-grekas widening a return type is a BC break all the time. Narrowing it is a BC break for child classes (requiring them to narrow their own return type in advance, which is the whole reason for tentative return types in PHP 8.1 core and our work in DebugClassLoader).

@wouterj
Copy link
Member Author

wouterj commented Nov 23, 2021

Let's close in favor of the new one, didn't see the conclusion before creating the other PR.

@wouterj wouterj closed this Nov 23, 2021
nicolas-grekas added a commit that referenced this pull request Nov 23, 2021
…n suggestion (wouterj)

This PR was merged into the 5.4 branch.

Discussion
----------

[Console] Add Suggestion class for more advanced completion suggestion

| Q             | A
| ------------- | ---
| Branch?       | 5.4
| Bug fix?      | no
| New feature?  | yes
| Deprecations? | no
| Tickets       |
| License       | MIT
| Doc PR        | -

Alternative to #44229 , see that PR for the full context.

Commits
-------

20ba02c Add Suggestion class for more advanced completion suggestion
symfony-splitter pushed a commit to symfony/console that referenced this pull request Nov 23, 2021
…n suggestion (wouterj)

This PR was merged into the 5.4 branch.

Discussion
----------

[Console] Add Suggestion class for more advanced completion suggestion

| Q             | A
| ------------- | ---
| Branch?       | 5.4
| Bug fix?      | no
| New feature?  | yes
| Deprecations? | no
| Tickets       |
| License       | MIT
| Doc PR        | -

Alternative to symfony/symfony#44229 , see that PR for the full context.

Commits
-------

20ba02c1ee Add Suggestion class for more advanced completion suggestion
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants