microsoft / lsprotocol

Code generator and generated types for Language Server Protocol.
MIT License
118 stars 21 forks source link

[python] Make the method fields of requests, responses and notifications literals #355

Closed svenberkvens closed 5 months ago

svenberkvens commented 5 months ago

This makes it possible for cattrs to build a disambiguation function based on this unique field, which allows one to do things like:

>>> from lsprotocol import types, converters
>>>
>>> converter = converters.get_converter()
>>> d = {"jsonrpc":"2.0","method":"window/logMessage","params":{"type":3,"message":"Server starting"}}
>>> converter.structure(d, types.NOTIFICATIONS | types.REQUESTS)
WindowLogMessageNotification(params=LogMessageParams(type=<MessageType.Info: 3>, message='Server starting'), method='window/logMessage', jsonrpc='2.0')
svenberkvens commented 5 months ago

@microsoft-github-policy-service agree