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
2 changes: 1 addition & 1 deletion pygls/workspace/workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ def update_notebook_document(self, params: types.DidChangeNotebookDocumentParams
notebook = self._notebook_documents[unquote(uri)]
notebook.version = params.notebook_document.version

if params.change.metadata:
if params.change.metadata is not None:
notebook.metadata = params.change.metadata

cell_changes = params.change.cells
Expand Down
37 changes: 37 additions & 0 deletions tests/test_workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,43 @@ def test_update_notebook_metadata(workspace):
assert notebook.metadata == {"custom": "metadata"}


@pytest.mark.parametrize(
"metadata,expected",
[
({}, {}),
(None, {"custom": "metadata"}),
({"replacement": True}, {"replacement": True}),
],
)
def test_replace_notebook_metadata(workspace, metadata, expected):
"""An empty metadata object clears old values; omission preserves them."""
notebook = types.NotebookDocument(
uri=NOTEBOOK.uri,
notebook_type=NOTEBOOK.notebook_type,
version=0,
cells=[],
metadata={"custom": "metadata"},
)
workspace.put_notebook_document(
types.DidOpenNotebookDocumentParams(
notebook_document=notebook, cell_text_documents=[]
)
)

workspace.update_notebook_document(
types.DidChangeNotebookDocumentParams(
notebook_document=types.VersionedNotebookDocumentIdentifier(
uri=notebook.uri, version=1
),
change=types.NotebookDocumentChangeEvent(metadata=metadata),
)
)

updated = workspace.get_notebook_document(notebook_uri=notebook.uri)
assert updated.version == 1
assert updated.metadata == expected


def test_update_notebook_cell_data(workspace):
"""Ensure we can update a notebook correctly when cell data changes."""
params = types.DidOpenNotebookDocumentParams(
Expand Down
Loading