Allow command predicates to manage parameters, allow overwriting commands #1098
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.
Command predicates can now return more values after the command "validity" boolean. Those parameters are then passed to the actual commands.
Command predicates now also receive the parameters passed to
command.perform
.This allows command predicates to manipulate or create from scratch the parameters that are passed to the actual commands.
This also has the advantage of allowing to do heavy computations that are needed both by the predicate and the actual command only once.
If a command predicate doesn't return any additional parameters, the original ones are passed through to the actual command.
Now string and table predicates also return the active view. Additional parameters are also passed through.
Now when
command.get_all_valid
is called, each predicate is memoized to avoid recomputing it for each command that uses it.This could be an important optimization for predicates that need heavy computations that are also used for multiple commands.
It's now possible to overwrite commands without errors.
While the assertion might have been useful to debug erroneous command overwrites, it also caused issues when saving the user module with commands defined inside it, as it resulted in the user-defined commands trying to overwrite themselves and failing.
As I changed many commands to use the new parameter passing, testing is needed as I might have missed something.