Skip to content

Commit 50c3750

Browse files
committed
add test for publish diagnostics version support
1 parent 20245bd commit 50c3750

File tree

1 file changed

+85
-0
lines changed

1 file changed

+85
-0
lines changed

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

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
use lsp_server::RequestId;
99
use lsp_server::Response;
10+
use lsp_types::Url;
1011

1112
use crate::test::lsp::lsp_interaction::object_model::InitializeSettings;
1213
use crate::test::lsp::lsp_interaction::object_model::LspInteraction;
@@ -163,3 +164,87 @@ fn test_error_documentation_links() {
163164

164165
interaction.shutdown();
165166
}
167+
168+
#[test]
169+
fn test_version_support_publish_diagnostics() {
170+
let test_files_root = get_test_files_root();
171+
let root = test_files_root.path().to_path_buf();
172+
let mut file = root.clone();
173+
file.push("text_document.py");
174+
let uri = Url::from_file_path(file).unwrap();
175+
let mut interaction = LspInteraction::new();
176+
interaction.set_root(root);
177+
interaction.initialize(InitializeSettings {
178+
configuration: Some(None),
179+
capabilities: Some(serde_json::json!({
180+
"textDocument": {
181+
"publishDiagnostics": {
182+
"versionSupport": true,
183+
},
184+
},
185+
})),
186+
..Default::default()
187+
});
188+
189+
interaction.server.did_open("text_document.py");
190+
interaction.server.diagnostic("text_document.py");
191+
192+
interaction
193+
.client
194+
.expect_message(lsp_server::Message::Notification(
195+
lsp_server::Notification {
196+
method: "textDocument/publishDiagnostics".to_owned(),
197+
params: serde_json::json! {{
198+
"uri": uri,
199+
"diagnostics": [],
200+
"version": 1
201+
}},
202+
},
203+
));
204+
205+
interaction.server.did_change("text_document.py", "# test");
206+
interaction.server.diagnostic("text_document.py");
207+
208+
// I don't understand why this version is still 1
209+
interaction
210+
.client
211+
.expect_message(lsp_server::Message::Notification(
212+
lsp_server::Notification {
213+
method: "textDocument/publishDiagnostics".to_owned(),
214+
params: serde_json::json! {{
215+
"uri": uri,
216+
"diagnostics": [],
217+
"version": 2
218+
}},
219+
},
220+
));
221+
222+
interaction
223+
.server
224+
.send_message(Message::Notification(Notification {
225+
method: "textDocument/didClose".to_owned(),
226+
params: serde_json::json!({
227+
"textDocument": {
228+
"uri": uri.to_string(),
229+
"languageId": "python",
230+
"version": 3
231+
},
232+
}),
233+
}));
234+
interaction.server.diagnostic("text_document.py");
235+
236+
interaction
237+
.client
238+
.expect_message(lsp_server::Message::Notification(
239+
lsp_server::Notification {
240+
method: "textDocument/publishDiagnostics".to_owned(),
241+
params: serde_json::json! {{
242+
"uri": uri,
243+
"diagnostics": [],
244+
"version": 3
245+
}},
246+
},
247+
));
248+
249+
interaction.shutdown();
250+
}

0 commit comments

Comments
 (0)