Unable to structure `NotebookDocumentSyncOptions`
alcarney opened this issue · comments
Alex Carney commented
>>> options = {'notebookSelector': [{'cells': [{'language': 'python'}]}]}
>>> converter.structure(options, NotebookDocumentSyncOptions)
+ Exception Group Traceback (most recent call last):
| File "<stdin>", line 1, in <module>
| File "/var/home/alex/Projects/pygls/.env/lib64/python3.11/site-packages/cattrs/converters.py", line 309, in structure
| return self._structure_func.dispatch(cl)(obj, cl)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| File "<cattrs generated structure lsprotocol.types.NotebookDocumentSyncOptions>", line 15, in structure_NotebookDocumentSyncOptions
| cattrs.errors.ClassValidationError: While structuring NotebookDocumentSyncOptions (1 sub-exception)
+-+---------------- 1 ----------------
| Traceback (most recent call last):
| File "<cattrs generated structure lsprotocol.types.NotebookDocumentSyncOptions>", line 5, in structure_NotebookDocumentSyncOptions
| File "/var/home/alex/Projects/pygls/.env/lib64/python3.11/site-packages/cattrs/converters.py", line 495, in _structure_list
| handler = self._structure_func.dispatch(elem_type)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| File "/var/home/alex/Projects/pygls/.env/lib64/python3.11/site-packages/cattrs/dispatch.py", line 49, in _dispatch
| return self._function_dispatch.dispatch(cl)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| File "/var/home/alex/Projects/pygls/.env/lib64/python3.11/site-packages/cattrs/dispatch.py", line 131, in dispatch
| return handler(typ)
| ^^^^^^^^^^^^
| File "/var/home/alex/Projects/pygls/.env/lib64/python3.11/site-packages/cattrs/converters.py", line 390, in _gen_attrs_union_structure
| dis_fn = self._get_dis_func(cl)
| ^^^^^^^^^^^^^^^^^^^^^^
| File "/var/home/alex/Projects/pygls/.env/lib64/python3.11/site-packages/cattrs/converters.py", line 677, in _get_dis_func
| return create_uniq_field_dis_func(*union_types)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| File "/var/home/alex/Projects/pygls/.env/lib64/python3.11/site-packages/cattrs/disambiguators.py", line 39, in create_uniq_field_dis_func
| raise ValueError(m)
| ValueError: <class 'lsprotocol.types.NotebookDocumentSyncOptionsNotebookSelectorType1'> has no usable unique attributes.
| Structuring class NotebookDocumentSyncOptions @ attribute notebook_selector
+------------------------------------
>>>
This isn't the usual "missing structure hook" error - so not sure if I am missing something? 🤔
Although, that said this InitializeResult
instance is enough to get VSCode to switch on the notebook document sync messages
{
"capabilities": {
"textDocumentSync": {
"openClose": true,
"change": 2,
"willSave": false,
"willSaveWaitUntil": false,
"save": false
},
"notebookDocumentSync": {
"notebookSelector": [
{
"cells": [
{
"language": "python"
}
]
}
]
},
"executeCommandProvider": {
"commands": []
},
"inlayHintProvider": {
"resolveProvider": true
},
"workspace": {
"workspaceFolders": {
"supported": true,
"changeNotifications": true
},
"fileOperations": {}
}
},
"serverInfo": {
"name": "inlay-hint-server",
"version": "v0.1"
}
}
Karthik Nadig commented
@alcarney This means that it needs a hook that selects one of various options, here is an example:
lsprotocol/packages/python/lsprotocol/_hooks.py
Lines 419 to 425 in 75abc4f
Alex Carney commented
Thanks for the quick fix!