@@ -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]
@@ -264,65 +265,85 @@ fn test_version_support_publish_diagnostics() {
264265 ..Default :: default ( )
265266 } ) ;
266267
268+ let gen_validator = |expected_version : i64 | {
269+ let actual_uri = uri. as_str ( ) ;
270+ move |msg : & Message | {
271+ let Message :: Notification ( Notification { method, params } ) = msg else {
272+ return ValidationResult :: Skip ;
273+ } ;
274+ let Some ( uri_val) = params. get ( "uri" ) else {
275+ return ValidationResult :: Skip ;
276+ } ;
277+ let Some ( expected_uri) = uri_val. as_str ( ) else {
278+ return ValidationResult :: Skip ;
279+ } ;
280+ if expected_uri == actual_uri && method == "textDocument/publishDiagnostics" {
281+ if let Some ( actual_version) = params. get ( "version" ) {
282+ if let Some ( actual_version) = actual_version. as_i64 ( ) {
283+ assert ! (
284+ actual_version <= expected_version,
285+ "expected version: {}, actual version: {}" ,
286+ expected_version,
287+ actual_version
288+ ) ;
289+ return match actual_version. cmp ( & expected_version) {
290+ std:: cmp:: Ordering :: Less => ValidationResult :: Skip ,
291+ std:: cmp:: Ordering :: Equal => ValidationResult :: Pass ,
292+ std:: cmp:: Ordering :: Greater => ValidationResult :: Fail ,
293+ } ;
294+ }
295+ }
296+ }
297+ ValidationResult :: Skip
298+ }
299+ } ;
300+
267301 interaction. server . did_open ( "text_document.py" ) ;
268- interaction. server . diagnostic ( "text_document.py" ) ;
269302
270- interaction
271- . client
272- . expect_message ( lsp_server:: Message :: Notification (
273- lsp_server:: Notification {
274- method : "textDocument/publishDiagnostics" . to_owned ( ) ,
275- params : serde_json:: json! { {
276- "uri" : uri,
277- "diagnostics" : [ ] ,
278- "version" : 1
279- } } ,
280- } ,
281- ) ) ;
303+ let version = 1 ;
304+ interaction. client . expect_message_helper (
305+ gen_validator ( version) ,
306+ & format ! (
307+ "publishDiagnostics notification with version {} for file: {}" ,
308+ version,
309+ uri. as_str( )
310+ ) ,
311+ ) ;
282312
283- interaction. server . did_change ( "text_document.py" , "# test" ) ;
284- interaction. server . diagnostic ( "text_document.py" ) ;
313+ interaction. server . did_change ( "text_document.py" , "a = b" ) ;
285314
286- // I don't understand why this version is still 1
287- interaction
288- . client
289- . expect_message ( lsp_server:: Message :: Notification (
290- lsp_server:: Notification {
291- method : "textDocument/publishDiagnostics" . to_owned ( ) ,
292- params : serde_json:: json! { {
293- "uri" : uri,
294- "diagnostics" : [ ] ,
295- "version" : 2
296- } } ,
297- } ,
298- ) ) ;
315+ let version = 2 ;
316+ interaction. client . expect_message_helper (
317+ gen_validator ( version) ,
318+ & format ! (
319+ "publishDiagnostics notification with version {} for file: {}" ,
320+ version,
321+ uri. as_str( )
322+ ) ,
323+ ) ;
299324
300325 interaction
301326 . server
302327 . send_message ( Message :: Notification ( Notification {
303328 method : "textDocument/didClose" . to_owned ( ) ,
304329 params : serde_json:: json!( {
305330 "textDocument" : {
306- "uri" : uri. to_string ( ) ,
331+ "uri" : uri. as_str ( ) ,
307332 "languageId" : "python" ,
308333 "version" : 3
309334 } ,
310335 } ) ,
311336 } ) ) ;
312- interaction. server . diagnostic ( "text_document.py" ) ;
313337
314- interaction
315- . client
316- . expect_message ( lsp_server:: Message :: Notification (
317- lsp_server:: Notification {
318- method : "textDocument/publishDiagnostics" . to_owned ( ) ,
319- params : serde_json:: json! { {
320- "uri" : uri,
321- "diagnostics" : [ ] ,
322- "version" : 3
323- } } ,
324- } ,
325- ) ) ;
338+ let version = 3 ;
339+ interaction. client . expect_message_helper (
340+ gen_validator ( version) ,
341+ & format ! (
342+ "publishDiagnostics notification with version {} for file: {}" ,
343+ version,
344+ uri. as_str( )
345+ ) ,
346+ ) ;
326347
327348 interaction. shutdown ( ) ;
328349}
0 commit comments