[WIP] Refactor the definitions of RPC functions #63
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.
Thanks to @ejmr for this pull request (he's the author of this proposal)
IMPORTANT: This code is unfinished and needs a lot more testing.
Developers should not build off this commit because it is highly
likely we will rebase it once we address all problems.
We define a number of functions whose sole purpose is to invoke
Phpactor's RPC commands. The majority of these functions are the same.
That is, their only real difference is the name of the RPC command and
what we pass to our
phpactor--rpc
function. This patch refactorsthat code for multiple purposes.
We now only need to change one place to add support for a new
command: the 'phpactor--rpc-command-data' list. The exception to
this are the few RPC commands like "echo" which require additional
arguments. It seemed easier to leave those few functions as they
are instead of trying to shoe-horn support for a corner case into
our now macro.
The new 'phpactor-defrpc' macro automatically creates the functions
we previously wrote by hand. This both reduces bloat and decreases
chances for errors, since now our code for such functions is all in
one place: the macro definition itself.
We create a list of relevant data about the RPC commands which we
can loop over, apply our new macro to each. This lets us introduce
support for a new RPC command by modifying a single line in a list
as opposed to writing an entire function. (Again, the exception are
those few commands like "echo" which require additional arguments.)