Skip to content

Commit 3ca4f0a

Browse files
authored
Merge pull request #187 from krassowski/fix/didSaveHandler
Do not raise on missing contentChanges in didSave
2 parents fe8bbe2 + e765629 commit 3ca4f0a

File tree

5 files changed

+44
-3
lines changed

5 files changed

+44
-3
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# CHANGELOG
22

3+
## `jupyter-lsp 0.7.0`
4+
5+
- bugfixes
6+
- didSave no longer causes unwanted messages in logs (
7+
[#187](https://github.com/krassowski/jupyterlab-lsp/pull/187)
8+
)
9+
310
## `@krassowski/jupyterlab-lsp 0.7.1`
411

512
- features

azure-pipelines.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ variables:
1313
ATEST_RETRIES: 3
1414
YARN_CACHE_FOLDER: $(Pipeline.Workspace)/.yarn
1515

16-
PY_JLSP_VERSION: 0.7.0b0
16+
PY_JLSP_VERSION: 0.7.0
1717
JS_JLLSP_VERSION: 0.7.1
1818

1919
FIRST_PARTY_LABEXTENSIONS: >-

py_src/jupyter_lsp/_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
""" single source of truth for jupyter_lsp version
22
"""
3-
__version__ = "0.7.0b0"
3+
__version__ = "0.7.0"

py_src/jupyter_lsp/tests/test_virtual_documents_shadow.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,17 @@ def did_change(uri, changes: List):
6060
}
6161

6262

63+
def did_save_with_text(uri, text):
64+
return {
65+
"method": "textDocument/didSave",
66+
"params": {"textDocument": {"uri": uri, "text": text}},
67+
}
68+
69+
70+
def did_save_without_text(uri):
71+
return {"method": "textDocument/didSave", "params": {"textDocument": {"uri": uri}}}
72+
73+
6374
@pytest.fixture
6475
def shadow_path(tmpdir):
6576
return str(tmpdir.mkdir(".virtual_documents"))
@@ -71,6 +82,7 @@ def shadow_path(tmpdir):
7182
[
7283
[did_open, "content\nof\nopened\nfile", "content\nof\nopened\nfile"],
7384
[did_change, [{"text": "content after change"}], "content after change"],
85+
[did_save_with_text, "content at save", "content at save"],
7486
],
7587
)
7688
async def test_shadow(shadow_path, message_func, content, expected_content):
@@ -89,6 +101,7 @@ async def test_shadow(shadow_path, message_func, content, expected_content):
89101
async def test_shadow_failures(shadow_path):
90102

91103
shadow = setup_shadow_filesystem(Path(shadow_path).as_uri())
104+
ok_file_uri = (Path(shadow_path) / "test.py").as_uri()
92105

93106
def run_shadow(message):
94107
return shadow("client", message, ["python"], None)
@@ -110,3 +123,16 @@ def run_shadow(message):
110123
# should NOT intercept (nor shadow) files from location other than shadow_path
111124
result = await run_shadow(did_open("file:///other/path.py", "content"))
112125
assert result is None
126+
127+
# should fail silently on missing text in didSave
128+
result = await run_shadow(did_save_without_text(ok_file_uri))
129+
assert result is None
130+
131+
# should raise on missing changes in didChange
132+
with pytest.raises(ShadowFilesystemError, match=".* is missing contentChanges"):
133+
await run_shadow(
134+
{
135+
"method": "textDocument/didChange",
136+
"params": {"textDocument": {"uri": ok_file_uri}},
137+
}
138+
)

py_src/jupyter_lsp/virtual_documents_shadow.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,13 +130,21 @@ async def shadow_virtual_documents(scope, message, languages, manager):
130130
text = extract_or_none(document, ["text"])
131131

132132
if text is not None:
133+
# didOpen and didSave may provide text within the document
133134
changes = [{"text": text}]
134135
else:
136+
# didChange is the only one which can also provide it in params (as contentChanges)
137+
if message["method"] != "textDocument/didChange":
138+
return
139+
if "contentChanges" not in message["params"]:
140+
raise ShadowFilesystemError(
141+
"textDocument/didChange is missing contentChanges"
142+
)
135143
changes = message["params"]["contentChanges"]
136144

137145
if len(changes) > 1:
138146
manager.log.warn( # pragma: no cover
139-
"LSP warning: up to one change" " supported for textDocument/didChange"
147+
"LSP warning: up to one change supported for textDocument/didChange"
140148
)
141149

142150
for change in changes[:1]:

0 commit comments

Comments
 (0)