Skip to content

Commit 77eb1c0

Browse files
committed
add test for publish diagnostics version support
1 parent 20245bd commit 77eb1c0

File tree

2 files changed

+88
-0
lines changed

2 files changed

+88
-0
lines changed

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

Lines changed: 74 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,76 @@ 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.server.did_close("text_document.py");
223+
interaction.server.diagnostic("text_document.py");
224+
225+
interaction
226+
.client
227+
.expect_message(lsp_server::Message::Notification(
228+
lsp_server::Notification {
229+
method: "textDocument/publishDiagnostics".to_owned(),
230+
params: serde_json::json! {{
231+
"uri": uri,
232+
"diagnostics": [],
233+
"version": 3
234+
}},
235+
},
236+
));
237+
238+
interaction.shutdown();
239+
}

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,20 @@ impl TestServer {
201201
}));
202202
}
203203

204+
pub fn did_close(&self, file: &'static str) {
205+
let path = self.get_root_or_panic().join(file);
206+
self.send_message(Message::Notification(Notification {
207+
method: "textDocument/didClose".to_owned(),
208+
params: serde_json::json!({
209+
"textDocument": {
210+
"uri": Url::from_file_path(&path).unwrap().to_string(),
211+
"languageId": "python",
212+
"version": 3
213+
},
214+
}),
215+
}));
216+
}
217+
204218
pub fn did_change_configuration(&self) {
205219
self.send_message(Message::Notification(Notification {
206220
method: lsp_types::notification::DidChangeConfiguration::METHOD.to_owned(),

0 commit comments

Comments
 (0)