Skip to content

Commit f412f5b

Browse files
committed
add test for publish diagnostics version support
1 parent f20e4b9 commit f412f5b

File tree

1 file changed

+87
-0
lines changed

1 file changed

+87
-0
lines changed

pyrefly/lib/test/lsp/lsp_interaction/diagnostic.rs

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@
55
* LICENSE file in the root directory of this source tree.
66
*/
77

8+
use lsp_server::Message;
9+
use lsp_server::Notification;
810
use lsp_server::RequestId;
911
use lsp_server::Response;
12+
use lsp_types::Url;
1013

1114
use crate::test::lsp::lsp_interaction::object_model::InitializeSettings;
1215
use crate::test::lsp::lsp_interaction::object_model::LspInteraction;
@@ -239,3 +242,87 @@ fn test_publish_diagnostics_preserves_symlink_uri() {
239242

240243
interaction.shutdown();
241244
}
245+
246+
#[test]
247+
fn test_version_support_publish_diagnostics() {
248+
let test_files_root = get_test_files_root();
249+
let root = test_files_root.path().to_path_buf();
250+
let mut file = root.clone();
251+
file.push("text_document.py");
252+
let uri = Url::from_file_path(file).unwrap();
253+
let mut interaction = LspInteraction::new();
254+
interaction.set_root(root);
255+
interaction.initialize(InitializeSettings {
256+
configuration: Some(None),
257+
capabilities: Some(serde_json::json!({
258+
"textDocument": {
259+
"publishDiagnostics": {
260+
"versionSupport": true,
261+
},
262+
},
263+
})),
264+
..Default::default()
265+
});
266+
267+
interaction.server.did_open("text_document.py");
268+
interaction.server.diagnostic("text_document.py");
269+
270+
interaction
271+
.client
272+
.expect_message(lsp_server::Message::Notification(
273+
lsp_server::Notification {
274+
method: "textDocument/publishDiagnostics".to_owned(),
275+
params: serde_json::json! {{
276+
"uri": uri,
277+
"diagnostics": [],
278+
"version": 1
279+
}},
280+
},
281+
));
282+
283+
interaction.server.did_change("text_document.py", "# test");
284+
interaction.server.diagnostic("text_document.py");
285+
286+
// I don't understand why this version is still 1
287+
interaction
288+
.client
289+
.expect_message(lsp_server::Message::Notification(
290+
lsp_server::Notification {
291+
method: "textDocument/publishDiagnostics".to_owned(),
292+
params: serde_json::json! {{
293+
"uri": uri,
294+
"diagnostics": [],
295+
"version": 2
296+
}},
297+
},
298+
));
299+
300+
interaction
301+
.server
302+
.send_message(Message::Notification(Notification {
303+
method: "textDocument/didClose".to_owned(),
304+
params: serde_json::json!({
305+
"textDocument": {
306+
"uri": uri.to_string(),
307+
"languageId": "python",
308+
"version": 3
309+
},
310+
}),
311+
}));
312+
interaction.server.diagnostic("text_document.py");
313+
314+
interaction
315+
.client
316+
.expect_message(lsp_server::Message::Notification(
317+
lsp_server::Notification {
318+
method: "textDocument/publishDiagnostics".to_owned(),
319+
params: serde_json::json! {{
320+
"uri": uri,
321+
"diagnostics": [],
322+
"version": 3
323+
}},
324+
},
325+
));
326+
327+
interaction.shutdown();
328+
}

0 commit comments

Comments
 (0)