@@ -16,6 +16,7 @@ use serde_json::json;
1616
1717use crate :: test:: lsp:: lsp_interaction:: object_model:: InitializeSettings ;
1818use crate :: test:: lsp:: lsp_interaction:: object_model:: LspInteraction ;
19+ use crate :: test:: lsp:: lsp_interaction:: object_model:: ValidationResult ;
1920use crate :: test:: lsp:: lsp_interaction:: util:: get_test_files_root;
2021
2122#[ test]
@@ -786,65 +787,85 @@ fn test_version_support_publish_diagnostics() {
786787 ..Default :: default ( )
787788 } ) ;
788789
790+ let gen_validator = |expected_version : i64 | {
791+ let actual_uri = uri. as_str ( ) ;
792+ move |msg : & Message | {
793+ let Message :: Notification ( Notification { method, params } ) = msg else {
794+ return ValidationResult :: Skip ;
795+ } ;
796+ let Some ( uri_val) = params. get ( "uri" ) else {
797+ return ValidationResult :: Skip ;
798+ } ;
799+ let Some ( expected_uri) = uri_val. as_str ( ) else {
800+ return ValidationResult :: Skip ;
801+ } ;
802+ if expected_uri == actual_uri && method == "textDocument/publishDiagnostics" {
803+ if let Some ( actual_version) = params. get ( "version" ) {
804+ if let Some ( actual_version) = actual_version. as_i64 ( ) {
805+ assert ! (
806+ actual_version <= expected_version,
807+ "expected version: {}, actual version: {}" ,
808+ expected_version,
809+ actual_version
810+ ) ;
811+ return match actual_version. cmp ( & expected_version) {
812+ std:: cmp:: Ordering :: Less => ValidationResult :: Skip ,
813+ std:: cmp:: Ordering :: Equal => ValidationResult :: Pass ,
814+ std:: cmp:: Ordering :: Greater => ValidationResult :: Fail ,
815+ } ;
816+ }
817+ }
818+ }
819+ ValidationResult :: Skip
820+ }
821+ } ;
822+
789823 interaction. server . did_open ( "text_document.py" ) ;
790- interaction. server . diagnostic ( "text_document.py" ) ;
791824
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- ) ) ;
825+ let version = 1 ;
826+ interaction. client . expect_message_helper (
827+ gen_validator ( version) ,
828+ & format ! (
829+ "publishDiagnostics notification with version {} for file: {}" ,
830+ version,
831+ uri. as_str( )
832+ ) ,
833+ ) ;
804834
805- interaction. server . did_change ( "text_document.py" , "# test" ) ;
806- interaction. server . diagnostic ( "text_document.py" ) ;
835+ interaction. server . did_change ( "text_document.py" , "a = b" ) ;
807836
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- ) ) ;
837+ let version = 2 ;
838+ interaction. client . expect_message_helper (
839+ gen_validator ( version) ,
840+ & format ! (
841+ "publishDiagnostics notification with version {} for file: {}" ,
842+ version,
843+ uri. as_str( )
844+ ) ,
845+ ) ;
821846
822847 interaction
823848 . server
824849 . send_message ( Message :: Notification ( Notification {
825850 method : "textDocument/didClose" . to_owned ( ) ,
826851 params : serde_json:: json!( {
827852 "textDocument" : {
828- "uri" : uri. to_string ( ) ,
853+ "uri" : uri. as_str ( ) ,
829854 "languageId" : "python" ,
830855 "version" : 3
831856 } ,
832857 } ) ,
833858 } ) ) ;
834- interaction. server . diagnostic ( "text_document.py" ) ;
835859
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- ) ) ;
860+ let version = 3 ;
861+ interaction. client . expect_message_helper (
862+ gen_validator ( version) ,
863+ & format ! (
864+ "publishDiagnostics notification with version {} for file: {}" ,
865+ version,
866+ uri. as_str( )
867+ ) ,
868+ ) ;
848869
849870 interaction. shutdown ( ) ;
850871}
0 commit comments