[WIP] Introduce support for generator feature handlers #516
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.
This isn't quite ready to be merged just yet, but I may as well open it now for some initial feedback. It started out as an attempt to fix #433, but this approach should also allow us to also implement #381 (just needs some more testing).
This PR unifies all handler execution under a common pattern and adds support for a new feature handler type - generator functions.
These generators may
yield
a newhandler
function plus theargs
andkwargs
to call it with. The yielded handler function is executed via pygls' (now standardised) execution framework meaning it can be sync, async, threaded or even another generator! Once complete the result of the yielded handler is sent back into the generator so it may continue. (JsonRPCProtocol._run_generator
)This PR also re-implements all of pygls' built-in feature handlers as generator functions -
removing the need for the
LSPMeta
metaclass and associatedcall_user_feature
wrapper.While this does mean every built-in handler must explicitly
yield
to the user's handler function, it does mean the built-in handlers get fine grained control over exactly when the user's handler is called - depending on what makes the most sense.Before
After
During
Other details
JsonRPCProtocol._execute_handler
) their differences are handled by the callback passed to the future.ContextVar
(JsonRPCProtocol.msg_id
)Code review checklist (for code reviewer to complete)
Automated linters
You can run the lints that are run on CI locally with: