|
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; |
@@ -211,3 +214,87 @@ fn test_unreachable_branch_diagnostic() { |
211 | 214 |
|
212 | 215 | interaction.shutdown(); |
213 | 216 | } |
| 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