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

[Python] Cannot structure WorkspaceSymbolResponse with unresolved symbols #308

Closed
0xJonas opened this issue Dec 1, 2023 · 0 comments · Fixed by #311
Closed

[Python] Cannot structure WorkspaceSymbolResponse with unresolved symbols #308

0xJonas opened this issue Dec 1, 2023 · 0 comments · Fixed by #311

Comments

@0xJonas
Copy link
Contributor

0xJonas commented Dec 1, 2023

The workspace/symbol request can include WorkspaceSymbol instances where the location field only contains a uri but not a range. The spec models this incomplete Location as a distinct type: https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#workspaceSymbol. However, when attempting to structure such a response, an exception is raised:

>>> from lsprotocol import types, converters
>>> converter = converters.get_converter()
>>> converter.structure({"id": 1, "result": [{"name": "test", "kind": 1, "location": {"uri": "test"}}], "jsonrpc": "2.0"}, types.WorkspaceSymbolResponse)
  + Exception Group Traceback (most recent call last):
  |   File "<stdin>", line 1, in <module>
  |   File "C:\Users\Jonas\Documents\quickP\LSPScript\.venv\lib\site-packages\cattrs\converters.py", line 332, in structure
  |     return self._structure_func.dispatch(cl)(obj, cl)
  |   File "<cattrs generated structure lsprotocol.types.WorkspaceSymbolResponse>", line 21, in structure_WorkspaceSymbolResponse    
  |     if errors: raise __c_cve('While structuring ' + 'WorkspaceSymbolResponse', errors, __cl)
  | cattrs.errors.ClassValidationError: While structuring WorkspaceSymbolResponse (1 sub-exception)
  +-+---------------- 1 ----------------
    | Exception Group Traceback (most recent call last):
    |   File "<cattrs generated structure lsprotocol.types.WorkspaceSymbolResponse>", line 11, in structure_WorkspaceSymbolResponse  
    |     res['result'] = __c_structure_result(o['result'], __c_type_result)
    |   File "C:\Users\Jonas\Documents\quickP\LSPScript\.venv\lib\site-packages\cattrs\converters.py", line 632, in _structure_union 
    |     return handler(obj, union)
    |   File "C:\Users\Jonas\Documents\quickP\LSPScript\.venv\lib\site-packages\lsprotocol\_hooks.py", line 693, in _symbol_list_hook
    |     return [
    |   File "C:\Users\Jonas\Documents\quickP\LSPScript\.venv\lib\site-packages\lsprotocol\_hooks.py", line 694, in <listcomp>       
    |     converter.structure(item, lsp_types.SymbolInformation)
    |   File "C:\Users\Jonas\Documents\quickP\LSPScript\.venv\lib\site-packages\cattrs\converters.py", line 332, in structure        
    |     return self._structure_func.dispatch(cl)(obj, cl)
    |   File "<cattrs generated structure lsprotocol.types.SymbolInformation>", line 37, in structure_SymbolInformation
    |     if errors: raise __c_cve('While structuring ' + 'SymbolInformation', errors, __cl)
    | cattrs.errors.ClassValidationError: While structuring SymbolInformation (1 sub-exception)
    | Structuring class WorkspaceSymbolResponse @ attribute result
    +-+---------------- 1 ----------------
      | Exception Group Traceback (most recent call last):
      |   File "<cattrs generated structure lsprotocol.types.SymbolInformation>", line 5, in structure_SymbolInformation
      |     res['location'] = __c_structure_location(o['location'], __c_type_location)
      |   File "<cattrs generated structure lsprotocol.types.Location>", line 14, in structure_Location
      |     if errors: raise __c_cve('While structuring ' + 'Location', errors, __cl)
      | cattrs.errors.ClassValidationError: While structuring Location (1 sub-exception)
      | Structuring class SymbolInformation @ attribute location
      +-+---------------- 1 ----------------
        | Traceback (most recent call last):
        |   File "<cattrs generated structure lsprotocol.types.Location>", line 10, in structure_Location
        |     res['range'] = __c_structure_range(o['range'], __c_type_range)
        | KeyError: 'range'
        | Structuring class Location @ attribute range
        +------------------------------------

It appears that cattrs tries to interpret the data as a SymbolInformation which, unlike WorkspaceSymbol, requires both uri and range to be present in the location.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant