|
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; |
| 11 | +use lsp_server::Response; |
| 12 | +use lsp_types::Url; |
9 | 13 | use lsp_types::request::DocumentDiagnosticRequest; |
10 | 14 | use pyrefly_config::environment::environment::PythonEnvironment; |
11 | 15 | use serde_json::json; |
@@ -760,3 +764,87 @@ fn test_shows_stdlib_errors_when_explicitly_included_in_project_includes() { |
760 | 764 |
|
761 | 765 | interaction.shutdown(); |
762 | 766 | } |
| 767 | + |
| 768 | +#[test] |
| 769 | +fn test_version_support_publish_diagnostics() { |
| 770 | + let test_files_root = get_test_files_root(); |
| 771 | + let root = test_files_root.path().to_path_buf(); |
| 772 | + let mut file = root.clone(); |
| 773 | + file.push("text_document.py"); |
| 774 | + let uri = Url::from_file_path(file).unwrap(); |
| 775 | + let mut interaction = LspInteraction::new(); |
| 776 | + interaction.set_root(root); |
| 777 | + interaction.initialize(InitializeSettings { |
| 778 | + configuration: Some(None), |
| 779 | + capabilities: Some(serde_json::json!({ |
| 780 | + "textDocument": { |
| 781 | + "publishDiagnostics": { |
| 782 | + "versionSupport": true, |
| 783 | + }, |
| 784 | + }, |
| 785 | + })), |
| 786 | + ..Default::default() |
| 787 | + }); |
| 788 | + |
| 789 | + interaction.server.did_open("text_document.py"); |
| 790 | + interaction.server.diagnostic("text_document.py"); |
| 791 | + |
| 792 | + interaction |
| 793 | + .client |
| 794 | + .expect_message(lsp_server::Message::Notification( |
| 795 | + lsp_server::Notification { |
| 796 | + method: "textDocument/publishDiagnostics".to_owned(), |
| 797 | + params: serde_json::json! {{ |
| 798 | + "uri": uri, |
| 799 | + "diagnostics": [], |
| 800 | + "version": 1 |
| 801 | + }}, |
| 802 | + }, |
| 803 | + )); |
| 804 | + |
| 805 | + interaction.server.did_change("text_document.py", "# test"); |
| 806 | + interaction.server.diagnostic("text_document.py"); |
| 807 | + |
| 808 | + // I don't understand why this version is still 1 |
| 809 | + interaction |
| 810 | + .client |
| 811 | + .expect_message(lsp_server::Message::Notification( |
| 812 | + lsp_server::Notification { |
| 813 | + method: "textDocument/publishDiagnostics".to_owned(), |
| 814 | + params: serde_json::json! {{ |
| 815 | + "uri": uri, |
| 816 | + "diagnostics": [], |
| 817 | + "version": 2 |
| 818 | + }}, |
| 819 | + }, |
| 820 | + )); |
| 821 | + |
| 822 | + interaction |
| 823 | + .server |
| 824 | + .send_message(Message::Notification(Notification { |
| 825 | + method: "textDocument/didClose".to_owned(), |
| 826 | + params: serde_json::json!({ |
| 827 | + "textDocument": { |
| 828 | + "uri": uri.to_string(), |
| 829 | + "languageId": "python", |
| 830 | + "version": 3 |
| 831 | + }, |
| 832 | + }), |
| 833 | + })); |
| 834 | + interaction.server.diagnostic("text_document.py"); |
| 835 | + |
| 836 | + interaction |
| 837 | + .client |
| 838 | + .expect_message(lsp_server::Message::Notification( |
| 839 | + lsp_server::Notification { |
| 840 | + method: "textDocument/publishDiagnostics".to_owned(), |
| 841 | + params: serde_json::json! {{ |
| 842 | + "uri": uri, |
| 843 | + "diagnostics": [], |
| 844 | + "version": 3 |
| 845 | + }}, |
| 846 | + }, |
| 847 | + )); |
| 848 | + |
| 849 | + interaction.shutdown(); |
| 850 | +} |
0 commit comments