[Console] Add callback support to Console\Question autocompleter#30997
Merged
fabpot merged 1 commit intosymfony:masterfrom Apr 8, 2019
MikkelPaulson:console-autocompleter-callback
Merged
[Console] Add callback support to Console\Question autocompleter#30997fabpot merged 1 commit intosymfony:masterfrom MikkelPaulson:console-autocompleter-callback
fabpot merged 1 commit intosymfony:masterfrom
MikkelPaulson:console-autocompleter-callback
Conversation
Contributor
Author
|
The CI failures on this branch also appear to be occurring on the upstream master... |
fabpot
approved these changes
Apr 8, 2019
Member
fabpot
left a comment
There was a problem hiding this comment.
LGTM. I've left some comments about CS.
In order to enable more dynamic use cases such as word-by-word autocomplete and path-based autocomplete, update the autocomplete logic of the Question object and its helper to accept a callback function. This function is called on each keystroke and should return an array of possibilities to present to the user. The original logic only accepted an array, which required implementations to anticipate in advance all possible input values. This change is fully backwards-compatible, but reimplements the old behaviour by initializing a "dumb" callback function that always returns the same array regardless of input.
nicolas-grekas
approved these changes
Apr 8, 2019
Member
nicolas-grekas
left a comment
There was a problem hiding this comment.
(I addressed Fabien's comment + did some changes while reviewing)
Member
|
Thank you @MikkelPaulson. |
fabpot
added a commit
that referenced
this pull request
Apr 8, 2019
…ocompleter (Mikkel Paulson) This PR was merged into the 4.3-dev branch. Discussion ---------- [Console] Add callback support to Console\Question autocompleter | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | minor edge case, see below | Deprecations? | no | Tests pass? | yes (with expanded coverage) | Fixed tickets | N/A | License | MIT | Doc PR | symfony/symfony-docs#11349 Autocompletion is a useful feature, but it's not always possible to anticipate every input the user could provide in advance. For instance, if we're allowing the user to input a path to a file, it's not practical to populate an array with every file and directory in the filesystem, but we can easily build a callback function that populates its suggestions based on the path already inputted. This change replaces the autocomplete logic that accepts an array of suggestions with an architecture that uses a callback function to populate suggestions in real time as the user provides input. The first commit adds a test class covering all methods of the `Question` object, while the second commit modifies the `Question` object to accept and store a callback function. The existing `[gs]etAutocompleterValues()` methods are preserved, but instead of being referenced directly from the `QuestionHelper`, they create and call their own callbacks to emulate the current behaviour. There is one edge case that is changed, as documented in the test: when a `Traversable` object is passed to `setAutocompleterValues()`, the return value of `getAutocompleterValues()` will be the unpacked (array) form of that object rather than the object itself. The unpacking is done lazily and cached on the callback function. Commits ------- caad562 [Console] Add callback support to Console\Question autocompleter
javiereguiluz
added a commit
to symfony/symfony-docs
that referenced
this pull request
Apr 9, 2019
This PR was merged into the master branch. Discussion ---------- Add description of autocompleter callback Documented feature added by symfony/symfony#30997. Commits ------- 5cfc67e Add description of autocompleter callback
fabpot
added a commit
that referenced
this pull request
Apr 10, 2019
This PR was merged into the 4.3-dev branch. Discussion ---------- Improve test coverage from #30997 | Q | A | ------------- | --- | Branch? | master | Bug fix? | yes (test enhancement against change on master) | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | enhancement for #30997 | License | MIT | Doc PR | N/A Test coverage added in #30997 did a good job of validating previous behaviour, but didn't adequately cover the new callback logic. Added coverage for new methods on the Question object. Commits ------- 4693422 Improve test coverage from #30997
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Autocompletion is a useful feature, but it's not always possible to anticipate every input the user could provide in advance. For instance, if we're allowing the user to input a path to a file, it's not practical to populate an array with every file and directory in the filesystem, but we can easily build a callback function that populates its suggestions based on the path already inputted.
This change replaces the autocomplete logic that accepts an array of suggestions with an architecture that uses a callback function to populate suggestions in real time as the user provides input.
The first commit adds a test class covering all methods of the
Questionobject, while the second commit modifies theQuestionobject to accept and store a callback function. The existing[gs]etAutocompleterValues()methods are preserved, but instead of being referenced directly from theQuestionHelper, they create and call their own callbacks to emulate the current behaviour.There is one edge case that is changed, as documented in the test: when a
Traversableobject is passed tosetAutocompleterValues(), the return value ofgetAutocompleterValues()will be the unpacked (array) form of that object rather than the object itself. The unpacking is done lazily and cached on the callback function.