diff --git a/packages/python/lsprotocol/_hooks.py b/packages/python/lsprotocol/_hooks.py index b4beb82..2a6a44d 100644 --- a/packages/python/lsprotocol/_hooks.py +++ b/packages/python/lsprotocol/_hooks.py @@ -614,6 +614,21 @@ def _watch_kind_hook( return object_ return converter.structure(object_, lsp_types.WatchKind) + def _notebook_sync_option_selector_hook( + object_: Any, _: type + ) -> Union[ + lsp_types.NotebookDocumentSyncOptionsNotebookSelectorType1, + lsp_types.NotebookDocumentSyncOptionsNotebookSelectorType2, + ]: + if "notebook" in object_: + return converter.structure( + object_, lsp_types.NotebookDocumentSyncOptionsNotebookSelectorType1 + ) + else: + return converter.structure( + object_, lsp_types.NotebookDocumentSyncOptionsNotebookSelectorType2 + ) + structure_hooks = [ ( Optional[ @@ -904,6 +919,13 @@ def _watch_kind_hook( Optional[Union[lsp_types.WatchKind, int]], _watch_kind_hook, ), + ( + Union[ + lsp_types.NotebookDocumentSyncOptionsNotebookSelectorType1, + lsp_types.NotebookDocumentSyncOptionsNotebookSelectorType2, + ], + _notebook_sync_option_selector_hook, + ), ] for type_, hook in structure_hooks: converter.register_structure_hook(type_, hook) diff --git a/tests/python/test_cattrs_special_cases.py b/tests/python/test_cattrs_special_cases.py index 7a83bfd..ac52650 100644 --- a/tests/python/test_cattrs_special_cases.py +++ b/tests/python/test_cattrs_special_cases.py @@ -262,3 +262,15 @@ def test_notebook_change_event(): converter.unstructure(obj, lsp.DidOpenNotebookDocumentParams), hamcrest.is_(data), ) + + +def test_notebook_sync_options(): + data = {"notebookSelector": [{"cells": [{"language": "python"}]}]} + + converter = cv.get_converter() + obj = converter.structure(data, lsp.NotebookDocumentSyncOptions) + hamcrest.assert_that(obj, hamcrest.instance_of(lsp.NotebookDocumentSyncOptions)) + hamcrest.assert_that( + converter.unstructure(obj, lsp.NotebookDocumentSyncOptions), + hamcrest.is_(data), + )