openlawlibrary / pygls

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

DocumentSymbol implementation results in 'mappingproxy' object has no attribute '__dict__' #79

Closed dinvlad closed 5 years ago

dinvlad commented 5 years ago

Hi folks,

When I implement @server.feature(DOCUMENT_SYMBOL), which returns a List[DocumentSymbol], the server crashes with

ERROR:pygls.protocol:Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/pygls/protocol.py", line 364, in _send_data
    body = json.dumps(data, default=lambda o: o.__dict__)
  File "/usr/local/Cellar/python/3.7.4/Frameworks/Python.framework/Versions/3.7/lib/python3.7/json/__init__.py", line 238, in dumps
    **kw).encode(obj)
  File "/usr/local/Cellar/python/3.7.4/Frameworks/Python.framework/Versions/3.7/lib/python3.7/json/encoder.py", line 199, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "/usr/local/Cellar/python/3.7.4/Frameworks/Python.framework/Versions/3.7/lib/python3.7/json/encoder.py", line 257, in iterencode
    return _iterencode(o, 0)
  File "/usr/local/lib/python3.7/site-packages/pygls/protocol.py", line 364, in <lambda>
    body = json.dumps(data, default=lambda o: o.__dict__)
AttributeError: 'mappingproxy' object has no attribute '__dict__'

What needs to be done to fix this error?

Thanks!

dinvlad commented 5 years ago

Sorry, that was an unrelated error - I tried to set name=type(node) for DocumentSymbol. Instead, name must be a string, i.e. name=type(node).__name__.