Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions packages/python/lsprotocol/_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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[
Expand Down Expand Up @@ -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)
Expand Down
12 changes: 12 additions & 0 deletions tests/python/test_cattrs_special_cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
)