Skip to content
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

Entirely use lsprotocol types for serialization and deserialization. #1

Closed

Conversation

karthiknadig
Copy link

This is a draft, and just test lsprotocol itself and see how it fairs when pygls fully relies on it.

Switched the serialization/de-serialization of request, response and notification to use lsprotocol.
I updated the tests as well. skiped some of the protocol tests in test_protocol.py since they relied on JsonRPC* classes which i removed. and skiped 3 command tests, they were flaky.

image

alcarney and others added 8 commits August 20, 2022 18:34
The `lsprotocol.types` module is re-exported through the
`pygls.lsp.types` module hopefully minimsing the number of broken
imports.

This also drops pygls' `LSP_METHODS_MAP` in favour of the
`METHOD_TO_TYPES` map provided by `lsprotocol`. The
`get_method_xxx_type` functions have been adjusted to use the new
mapping.

As far as I can tell `lsprotocol` doesn't provide generic JSON RPC
message types (except for `ResponseErrorMessage`) so the old
`JsonRPCNotification`, `JsonRPCResponseMessage` and
`JsonRPCRequestMessage` types have been preserved and converted to
`attrs`.
The machine readable version of the LSP spec (and therefore
`lsprotocol`) provides a mapping from an LSP method's name to its
`RegistrationOptions` type, which is an extension of the method's
`Options` type used when computing a server's capabilities.

This means the `RegistrationOptions` type includes additional fields
that are not valid within the `ServerCapabilities` response.

This commit introduces a new `get_method_options_type` function that
returns the correct `Options` type for a given method, automatically
deriving the type name from the result of the existing
`get_method_registration_options_type` function when appropriate.
There seems to be a mismatch with how pygls and lsprotocol want to work.

pygls says to the user "give me you params/result/error fields and I'll
put them in the correct JSON RPC structure for you. This meant that
pygls' `LSP_METHODS_MAP` returned types representing just the
params/result fields of messages.

However, lsprotocol's `METHOD_TO_TYPES` map is set up to return types
representing the full JSON RPC message bodies which seems to complicate
the serialization/deserialization code a bit.

I think I've managed to work around the differences, but this could
probably be done in a nicer way.
The timeouts can get in the way when trying to debug the code under
test. This commit makes it possible to disable the timeout by running
the testsuite with the `DISABLE_TIMEOUT` environment variable set e.g.

   $ DISABLE_TIMEOUT=1 pytest -x tests/
Nothing too interesting in this one, just updating imports, class names
etc to align `pygls` to the definitions in `lsprotocol`
@alcarney
Copy link
Owner

alcarney commented Oct 4, 2022

Thanks for this!

Is this PR something you're looking to get merged, or is it meant more as a guide for the next round of refinements? (I don't mind either way, just figuring out what I need to do next to keep things moving)

These cattrs hooks you mention, are they something pygls has to worry about or are they purely something internal to lsprotocol?

Finally, I assume I'd need the next version of lsprotocol to get this all to work?

@karthiknadig
Copy link
Author

This was just for reference, not for merging. The cattrs hooks are purely internal to lsprotocol. You will need the next version of lsprotocol I will publish one this thursday.

@karthiknadig
Copy link
Author

published a new release of lsprotocol with all the required cattrs hooks.

@alcarney alcarney force-pushed the lsprotocol branch 3 times, most recently from 58adfd5 to b7373e7 Compare October 14, 2022 17:57
@karthiknadig karthiknadig deleted the preserve_result branch August 6, 2024 22:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants