Skip to content

Commit aeabe98

Browse files
committed
add test for publish diagnostics version support
1 parent fb468c9 commit aeabe98

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
use pyrefly_config::environment::environment::PythonEnvironment;
1114

1215
use crate::test::lsp::lsp_interaction::object_model::InitializeSettings;
@@ -638,3 +641,87 @@ fn test_shows_stdlib_errors_when_explicitly_included_in_project_includes() {
638641

639642
interaction.shutdown();
640643
}
644+
645+
#[test]
646+
fn test_version_support_publish_diagnostics() {
647+
let test_files_root = get_test_files_root();
648+
let root = test_files_root.path().to_path_buf();
649+
let mut file = root.clone();
650+
file.push("text_document.py");
651+
let uri = Url::from_file_path(file).unwrap();
652+
let mut interaction = LspInteraction::new();
653+
interaction.set_root(root);
654+
interaction.initialize(InitializeSettings {
655+
configuration: Some(None),
656+
capabilities: Some(serde_json::json!({
657+
"textDocument": {
658+
"publishDiagnostics": {
659+
"versionSupport": true,
660+
},
661+
},
662+
})),
663+
..Default::default()
664+
});
665+
666+
interaction.server.did_open("text_document.py");
667+
interaction.server.diagnostic("text_document.py");
668+
669+
interaction
670+
.client
671+
.expect_message(lsp_server::Message::Notification(
672+
lsp_server::Notification {
673+
method: "textDocument/publishDiagnostics".to_owned(),
674+
params: serde_json::json! {{
675+
"uri": uri,
676+
"diagnostics": [],
677+
"version": 1
678+
}},
679+
},
680+
));
681+
682+
interaction.server.did_change("text_document.py", "# test");
683+
interaction.server.diagnostic("text_document.py");
684+
685+
// I don't understand why this version is still 1
686+
interaction
687+
.client
688+
.expect_message(lsp_server::Message::Notification(
689+
lsp_server::Notification {
690+
method: "textDocument/publishDiagnostics".to_owned(),
691+
params: serde_json::json! {{
692+
"uri": uri,
693+
"diagnostics": [],
694+
"version": 2
695+
}},
696+
},
697+
));
698+
699+
interaction
700+
.server
701+
.send_message(Message::Notification(Notification {
702+
method: "textDocument/didClose".to_owned(),
703+
params: serde_json::json!({
704+
"textDocument": {
705+
"uri": uri.to_string(),
706+
"languageId": "python",
707+
"version": 3
708+
},
709+
}),
710+
}));
711+
interaction.server.diagnostic("text_document.py");
712+
713+
interaction
714+
.client
715+
.expect_message(lsp_server::Message::Notification(
716+
lsp_server::Notification {
717+
method: "textDocument/publishDiagnostics".to_owned(),
718+
params: serde_json::json! {{
719+
"uri": uri,
720+
"diagnostics": [],
721+
"version": 3
722+
}},
723+
},
724+
));
725+
726+
interaction.shutdown();
727+
}

0 commit comments

Comments
 (0)