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

Unable to structure NotebookDocumentSyncOptions #259

Closed
alcarney opened this issue Aug 4, 2023 · 2 comments · Fixed by #260
Closed

Unable to structure NotebookDocumentSyncOptions #259

alcarney opened this issue Aug 4, 2023 · 2 comments · Fixed by #260

Comments

@alcarney
Copy link
Contributor

alcarney commented Aug 4, 2023

>>> 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"
    }
}
@karthiknadig
Copy link
Member

@alcarney This means that it needs a hook that selects one of various options, here is an example:

def _code_action_hook(
object_: Any, _: type
) -> Union[lsp_types.Command, lsp_types.CodeAction]:
if "command" in object_:
return converter.structure(object_, lsp_types.Command)
else:
return converter.structure(object_, lsp_types.CodeAction)

@alcarney
Copy link
Contributor Author

alcarney commented Aug 4, 2023

Thanks for the quick fix!

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.

2 participants