@@ -60,6 +60,17 @@ def did_change(uri, changes: List):
60
60
}
61
61
62
62
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
+
63
74
@pytest .fixture
64
75
def shadow_path (tmpdir ):
65
76
return str (tmpdir .mkdir (".virtual_documents" ))
@@ -71,6 +82,7 @@ def shadow_path(tmpdir):
71
82
[
72
83
[did_open , "content\n of\n opened\n file" , "content\n of\n opened\n file" ],
73
84
[did_change , [{"text" : "content after change" }], "content after change" ],
85
+ [did_save_with_text , "content at save" , "content at save" ],
74
86
],
75
87
)
76
88
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):
89
101
async def test_shadow_failures (shadow_path ):
90
102
91
103
shadow = setup_shadow_filesystem (Path (shadow_path ).as_uri ())
104
+ ok_file_uri = (Path (shadow_path ) / "test.py" ).as_uri ()
92
105
93
106
def run_shadow (message ):
94
107
return shadow ("client" , message , ["python" ], None )
@@ -110,3 +123,16 @@ def run_shadow(message):
110
123
# should NOT intercept (nor shadow) files from location other than shadow_path
111
124
result = await run_shadow (did_open ("file:///other/path.py" , "content" ))
112
125
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
+ )
0 commit comments