Skip to content

[Console] [WIP] Handle case where user tries to complete more arguments than there are available #47726

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 Sep 29, 2022

Q A
Branch? 5.4
Bug fix? yes
New feature? no
Deprecations? no
Tickets Related to #47432
License MIT
Doc PR n/a

Imagine a command with 1 argument. If the user tried to complete 2 arguments (e.g. bin/console some:cmd first sec|), the current CompletionInput will always suggest new values for the first argument.

This PR fixes it by taking a count of the accepted tokens. If there are less tokens accepted then provided, the user is doing something bad (providing too many arguments) and we should stop providing suggestions.

This fix is required for #47432 to work correctly.

@stof
Copy link
Member

stof commented Sep 29, 2022

Does this work fine for commands accepting array arguments, where the number of accepted arguments is infinite ?

@wouterj wouterj force-pushed the completioninput-beyond-end branch from df54466 to b50485a Compare September 29, 2022 11:45
@stof
Copy link
Member

stof commented Sep 29, 2022

based on your comment in #47432 (comment), shouldn't this PR target 5.4 ?

@wouterj wouterj changed the base branch from 6.2 to 5.4 September 29, 2022 11:47
@wouterj
Copy link
Member Author

wouterj commented Sep 29, 2022

Does this work fine for commands accepting array arguments, where the number of accepted arguments is infinite ?

Yes, the $acceptedIndex += \count($argumentValue); line should take care of that (the number of argument values equals the number of tokens passed to the infinite array argument).

Existing tests should cover all these array argument cases:

public function provideBindWithLastArrayArgumentData()
{
yield [CompletionInput::fromTokens(['bin/console'], 1), null];
yield [CompletionInput::fromTokens(['bin/console', 'symfony', 'sensiolabs'], 3), null];
yield [CompletionInput::fromTokens(['bin/console', 'symfony', 'sen'], 2), 'sen'];
}

based on your comment in #47432 (comment), shouldn't this PR target 5.4 ?

🤦‍♂️ yep

@wouterj wouterj modified the milestones: 6.2, 5.4 Sep 29, 2022
@Seldaek
Copy link
Member

Seldaek commented Sep 29, 2022

Note that my PR also targets 5.4, but anyway thanks for the fix here!

@stof
Copy link
Member

stof commented Sep 29, 2022

@wouterj but if we are after the last written argument value, we still want completion for a next one in case of an infinite list. That's what I'm unsure about.

@wouterj wouterj changed the title [Console] Handle case where user tries to complete more arguments than there are available [WIP] [Console] Handle case where user tries to complete more arguments than there are available Sep 29, 2022
@wouterj
Copy link
Member Author

wouterj commented Sep 29, 2022

Marking this as WIP, the failing test in FrameworkBundle reveals some errors with this approach (we should only compare argument tokens, not all tokens as this includes options and option values).

@wouterj
Copy link
Member Author

wouterj commented Sep 29, 2022

@wouterj but if we are after the last written argument value, we still want completion for a next one in case of an infinite list. That's what I'm unsure about.

That should be covered by: yield [CompletionInput::fromTokens(['bin/console', 'symfony', 'sensiolabs'], 3), null];

This data set replicates bin/console symfony sensiolabs | and the test case verifies that we're still completing the array argument (the null here indicates that there is no completion value, because there is no value for the last item in the array).

@fabpot fabpot modified the milestones: 5.4, 6.4 Dec 14, 2024
@wouterj
Copy link
Member Author

wouterj commented Apr 6, 2025

Closing here for now. I haven't looked into this for years, and haven't seen any other community reports about this for the past 2.5 years. It's a complex issue to fix, and for now not worth it imho.

@wouterj wouterj closed this Apr 6, 2025
@wouterj wouterj added the Stalled label Apr 6, 2025
@carsonbot carsonbot changed the title [WIP] [Console] Handle case where user tries to complete more arguments than there are available [Console] [WIP] Handle case where user tries to complete more arguments than there are available Apr 6, 2025
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.

5 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy