openlawlibrary / pygls

A pythonic generic language server
https://pygls.readthedocs.io/en/latest/
Apache License 2.0
588 stars 105 forks source link

Progress not functional because `kind` is missing #231

Closed perrinjerome closed 2 years ago

perrinjerome commented 2 years ago

The classes used for progress API all have a kind property which is used in the LSP protocol so that the client knows if it's a begin, progress or end message:

https://github.com/openlawlibrary/pygls/blob/4772250f8ede25aee8e457dae5bca394aeccdd2f/pygls/lsp/types/basic_structures.py#L442-L459

When these classes are used, usually the kind attribute is not set in the constructor, as we can see in the json example, it is: https://github.com/openlawlibrary/pygls/blob/4772250f8ede25aee8e457dae5bca394aeccdd2f/examples/json-extension/server/server.py#L205

and the kind is not passed explicitly like that:

    ls.progress.begin(token, WorkDoneProgressBegin(title='Indexing', percentage=0,         kind='begin'))

Because it is default value of the model, it's not needed to specify the kind and this is more elegant to not pass the kind.

The whole progress example stopped working after b84098cc05426877ba62dce75aeec2ba4fa45056 , more specifically this chunk which removes this code:

https://github.com/openlawlibrary/pygls/blob/ee17487e4f40f971e7ec6f7711fa8334c5b7b127/pygls/lsp/types/basic_structures.py#L57-L63

This block was responsible for serialising the kind attributes that are set as default values.

As we can see in log file, this message is serialised without kind.

INFO:pygls.protocol:Sending data: {"jsonrpc": "2.0", "method": "$/progress", "params": {"token": "6f82fd14-87e4-403c-9c33-0cdc92c54cbd", "value": {"title": "Indexing", "percentage": 0}}}

If we add back the __init__ method, then kind is properly serialised and the progress example works.

PS: very few of the protocol classes are using default values like this, maybe there is only the ones used for progress and also CreateFile DeleteFile and DeleteFile.

PPS: an easy workaround is to specify the kind explicitly

dimbleby commented 2 years ago

https://github.com/openlawlibrary/pygls/pull/198#issuecomment-1086864429

perrinjerome commented 2 years ago

Thanks @dimbleby the suggestion from https://github.com/openlawlibrary/pygls/pull/198#issuecomment-1086864429 would also solve the issue.

tombh commented 2 years ago

Fixed in #236