|
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 | use pyrefly_config::environment::environment::PythonEnvironment; |
11 | 14 |
|
12 | 15 | use crate::test::lsp::lsp_interaction::object_model::InitializeSettings; |
@@ -638,3 +641,87 @@ fn test_shows_stdlib_errors_when_explicitly_included_in_project_includes() { |
638 | 641 |
|
639 | 642 | interaction.shutdown(); |
640 | 643 | } |
| 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