Skip to content

Commit 2795f6c

Browse files
committed
add test for publish diagnostics version support
1 parent 8bd9f52 commit 2795f6c

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;
@@ -211,3 +214,87 @@ fn test_unreachable_branch_diagnostic() {
211214

212215
interaction.shutdown();
213216
}
217+
218+
#[test]
219+
fn test_version_support_publish_diagnostics() {
220+
let test_files_root = get_test_files_root();
221+
let root = test_files_root.path().to_path_buf();
222+
let mut file = root.clone();
223+
file.push("text_document.py");
224+
let uri = Url::from_file_path(file).unwrap();
225+
let mut interaction = LspInteraction::new();
226+
interaction.set_root(root);
227+
interaction.initialize(InitializeSettings {
228+
configuration: Some(None),
229+
capabilities: Some(serde_json::json!({
230+
"textDocument": {
231+
"publishDiagnostics": {
232+
"versionSupport": true,
233+
},
234+
},
235+
})),
236+
..Default::default()
237+
});
238+
239+
interaction.server.did_open("text_document.py");
240+
interaction.server.diagnostic("text_document.py");
241+
242+
interaction
243+
.client
244+
.expect_message(lsp_server::Message::Notification(
245+
lsp_server::Notification {
246+
method: "textDocument/publishDiagnostics".to_owned(),
247+
params: serde_json::json! {{
248+
"uri": uri,
249+
"diagnostics": [],
250+
"version": 1
251+
}},
252+
},
253+
));
254+
255+
interaction.server.did_change("text_document.py", "# test");
256+
interaction.server.diagnostic("text_document.py");
257+
258+
// I don't understand why this version is still 1
259+
interaction
260+
.client
261+
.expect_message(lsp_server::Message::Notification(
262+
lsp_server::Notification {
263+
method: "textDocument/publishDiagnostics".to_owned(),
264+
params: serde_json::json! {{
265+
"uri": uri,
266+
"diagnostics": [],
267+
"version": 2
268+
}},
269+
},
270+
));
271+
272+
interaction
273+
.server
274+
.send_message(Message::Notification(Notification {
275+
method: "textDocument/didClose".to_owned(),
276+
params: serde_json::json!({
277+
"textDocument": {
278+
"uri": uri.to_string(),
279+
"languageId": "python",
280+
"version": 3
281+
},
282+
}),
283+
}));
284+
interaction.server.diagnostic("text_document.py");
285+
286+
interaction
287+
.client
288+
.expect_message(lsp_server::Message::Notification(
289+
lsp_server::Notification {
290+
method: "textDocument/publishDiagnostics".to_owned(),
291+
params: serde_json::json! {{
292+
"uri": uri,
293+
"diagnostics": [],
294+
"version": 3
295+
}},
296+
},
297+
));
298+
299+
interaction.shutdown();
300+
}

0 commit comments

Comments
 (0)