|
5 | 5 | * LICENSE file in the root directory of this source tree. |
6 | 6 | */ |
7 | 7 |
|
| 8 | +use lsp_server::Message; |
| 9 | +use lsp_server::Notification; |
8 | 10 | use lsp_server::RequestId; |
9 | 11 | use lsp_server::Response; |
| 12 | +use lsp_types::Url; |
10 | 13 |
|
11 | 14 | use crate::test::lsp::lsp_interaction::object_model::InitializeSettings; |
12 | 15 | use crate::test::lsp::lsp_interaction::object_model::LspInteraction; |
@@ -239,3 +242,87 @@ fn test_publish_diagnostics_preserves_symlink_uri() { |
239 | 242 |
|
240 | 243 | interaction.shutdown(); |
241 | 244 | } |
| 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