Skip to content

Commit 8796124

Browse files
authored
Fix for missing notebook selector hook (#260)
Fixes #259
1 parent 75abc4f commit 8796124

2 files changed

Lines changed: 34 additions & 0 deletions

File tree

packages/python/lsprotocol/_hooks.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -614,6 +614,21 @@ def _watch_kind_hook(
614614
return object_
615615
return converter.structure(object_, lsp_types.WatchKind)
616616

617+
def _notebook_sync_option_selector_hook(
618+
object_: Any, _: type
619+
) -> Union[
620+
lsp_types.NotebookDocumentSyncOptionsNotebookSelectorType1,
621+
lsp_types.NotebookDocumentSyncOptionsNotebookSelectorType2,
622+
]:
623+
if "notebook" in object_:
624+
return converter.structure(
625+
object_, lsp_types.NotebookDocumentSyncOptionsNotebookSelectorType1
626+
)
627+
else:
628+
return converter.structure(
629+
object_, lsp_types.NotebookDocumentSyncOptionsNotebookSelectorType2
630+
)
631+
617632
structure_hooks = [
618633
(
619634
Optional[
@@ -904,6 +919,13 @@ def _watch_kind_hook(
904919
Optional[Union[lsp_types.WatchKind, int]],
905920
_watch_kind_hook,
906921
),
922+
(
923+
Union[
924+
lsp_types.NotebookDocumentSyncOptionsNotebookSelectorType1,
925+
lsp_types.NotebookDocumentSyncOptionsNotebookSelectorType2,
926+
],
927+
_notebook_sync_option_selector_hook,
928+
),
907929
]
908930
for type_, hook in structure_hooks:
909931
converter.register_structure_hook(type_, hook)

tests/python/test_cattrs_special_cases.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,3 +262,15 @@ def test_notebook_change_event():
262262
converter.unstructure(obj, lsp.DidOpenNotebookDocumentParams),
263263
hamcrest.is_(data),
264264
)
265+
266+
267+
def test_notebook_sync_options():
268+
data = {"notebookSelector": [{"cells": [{"language": "python"}]}]}
269+
270+
converter = cv.get_converter()
271+
obj = converter.structure(data, lsp.NotebookDocumentSyncOptions)
272+
hamcrest.assert_that(obj, hamcrest.instance_of(lsp.NotebookDocumentSyncOptions))
273+
hamcrest.assert_that(
274+
converter.unstructure(obj, lsp.NotebookDocumentSyncOptions),
275+
hamcrest.is_(data),
276+
)

0 commit comments

Comments
 (0)