@@ -13,6 +13,7 @@ use lsp_types::Url;
1313
1414use crate :: test:: lsp:: lsp_interaction:: object_model:: InitializeSettings ;
1515use crate :: test:: lsp:: lsp_interaction:: object_model:: LspInteraction ;
16+ use crate :: test:: lsp:: lsp_interaction:: object_model:: ValidationResult ;
1617use crate :: test:: lsp:: lsp_interaction:: util:: get_test_files_root;
1718
1819#[ test]
@@ -188,65 +189,86 @@ fn test_version_support_publish_diagnostics() {
188189 ..Default :: default ( )
189190 } ) ;
190191
192+ let gen_validator = |expected_version : i64 | {
193+ let actual_uri = uri. as_str ( ) ;
194+ move |msg : & Message | {
195+ let Message :: Notification ( Notification { method, params } ) = msg else {
196+ return ValidationResult :: Skip ;
197+ } ;
198+ let Some ( uri_val) = params. get ( "uri" ) else {
199+ return ValidationResult :: Skip ;
200+ } ;
201+ let Some ( expected_uri) = uri_val. as_str ( ) else {
202+ return ValidationResult :: Skip ;
203+ } ;
204+ if expected_uri == actual_uri && method == "textDocument/publishDiagnostics" {
205+ if let Some ( actual_version) = params. get ( "version" ) {
206+ if let Some ( actual_version) = actual_version. as_i64 ( ) {
207+ assert ! (
208+ actual_version <= expected_version,
209+ "expected version: {}, actual version: {}" ,
210+ expected_version,
211+ actual_version
212+ ) ;
213+ return match actual_version. cmp ( & expected_version) {
214+ std:: cmp:: Ordering :: Less => ValidationResult :: Skip ,
215+ std:: cmp:: Ordering :: Equal => ValidationResult :: Pass ,
216+ std:: cmp:: Ordering :: Greater => ValidationResult :: Fail ,
217+ } ;
218+ }
219+ }
220+ }
221+ ValidationResult :: Skip
222+ }
223+ } ;
224+
191225 interaction. server . did_open ( "text_document.py" ) ;
192- interaction. server . diagnostic ( "text_document.py" ) ;
193226
194- interaction
195- . client
196- . expect_message ( lsp_server:: Message :: Notification (
197- lsp_server:: Notification {
198- method : "textDocument/publishDiagnostics" . to_owned ( ) ,
199- params : serde_json:: json! { {
200- "uri" : uri,
201- "diagnostics" : [ ] ,
202- "version" : 1
203- } } ,
204- } ,
205- ) ) ;
227+ let version = 1 ;
206228
207- interaction. server . did_change ( "text_document.py" , "# test" ) ;
208- interaction. server . diagnostic ( "text_document.py" ) ;
229+ interaction. client . expect_message_helper (
230+ gen_validator ( version) ,
231+ & format ! (
232+ "publishDiagnostics notification with version {} for file: {}" ,
233+ version,
234+ uri. as_str( )
235+ ) ,
236+ ) ;
209237
210- // I don't understand why this version is still 1
211- interaction
212- . client
213- . expect_message ( lsp_server:: Message :: Notification (
214- lsp_server:: Notification {
215- method : "textDocument/publishDiagnostics" . to_owned ( ) ,
216- params : serde_json:: json! { {
217- "uri" : uri,
218- "diagnostics" : [ ] ,
219- "version" : 2
220- } } ,
221- } ,
222- ) ) ;
238+ interaction. server . did_change ( "text_document.py" , "a = b" ) ;
239+
240+ let version = 2 ;
241+ interaction. client . expect_message_helper (
242+ gen_validator ( version) ,
243+ & format ! (
244+ "publishDiagnostics notification with version {} for file: {}" ,
245+ version,
246+ uri. as_str( )
247+ ) ,
248+ ) ;
223249
224250 interaction
225251 . server
226252 . send_message ( Message :: Notification ( Notification {
227253 method : "textDocument/didClose" . to_owned ( ) ,
228254 params : serde_json:: json!( {
229255 "textDocument" : {
230- "uri" : uri. to_string ( ) ,
256+ "uri" : uri. as_str ( ) ,
231257 "languageId" : "python" ,
232258 "version" : 3
233259 } ,
234260 } ) ,
235261 } ) ) ;
236- interaction. server . diagnostic ( "text_document.py" ) ;
237262
238- interaction
239- . client
240- . expect_message ( lsp_server:: Message :: Notification (
241- lsp_server:: Notification {
242- method : "textDocument/publishDiagnostics" . to_owned ( ) ,
243- params : serde_json:: json! { {
244- "uri" : uri,
245- "diagnostics" : [ ] ,
246- "version" : 3
247- } } ,
248- } ,
249- ) ) ;
263+ let version = 3 ;
264+ interaction. client . expect_message_helper (
265+ gen_validator ( version) ,
266+ & format ! (
267+ "publishDiagnostics notification with version {} for file: {}" ,
268+ version,
269+ uri. as_str( )
270+ ) ,
271+ ) ;
250272
251273 interaction. shutdown ( ) ;
252274}
0 commit comments