Skip to content

Unable to structure NotebookDocumentSyncOptions #259

Closed

Description

@alcarney
>>> 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"
    }
}

Activity

  1. karthiknadig commented on Aug 4, 2023

    @karthiknadig
    Member

    Alex Carney (@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)

  2. alcarney commented on Aug 4, 2023

    @alcarney
    ContributorAuthor

    Thanks for the quick fix!

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions