@@ -29,7 +29,11 @@ pub enum Severity {
2929 WeakWarning ,
3030}
3131
32- pub ( crate ) fn diagnostics ( db : & RootDatabase , file_id : FileId ) -> Vec < Diagnostic > {
32+ pub ( crate ) fn diagnostics (
33+ db : & RootDatabase ,
34+ file_id : FileId ,
35+ enable_experimental : bool ,
36+ ) -> Vec < Diagnostic > {
3337 let _p = profile ( "diagnostics" ) ;
3438 let sema = Semantics :: new ( db) ;
3539 let parse = db. parse ( file_id) ;
@@ -116,6 +120,9 @@ pub(crate) fn diagnostics(db: &RootDatabase, file_id: FileId) -> Vec<Diagnostic>
116120 fix : missing_struct_field_fix ( & sema, file_id, d) ,
117121 } )
118122 } )
123+ // Only collect experimental diagnostics when they're enabled.
124+ . filter ( |diag| !diag. is_experimental ( ) || enable_experimental)
125+ // Diagnostics not handled above get no fix and default treatment.
119126 . build ( |d| {
120127 res. borrow_mut ( ) . push ( Diagnostic {
121128 message : d. message ( ) ,
@@ -301,7 +308,7 @@ mod tests {
301308 let after = trim_indent ( ra_fixture_after) ;
302309
303310 let ( analysis, file_position) = analysis_and_position ( ra_fixture_before) ;
304- let diagnostic = analysis. diagnostics ( file_position. file_id ) . unwrap ( ) . pop ( ) . unwrap ( ) ;
311+ let diagnostic = analysis. diagnostics ( file_position. file_id , true ) . unwrap ( ) . pop ( ) . unwrap ( ) ;
305312 let mut fix = diagnostic. fix . unwrap ( ) ;
306313 let edit = fix. source_change . source_file_edits . pop ( ) . unwrap ( ) . edit ;
307314 let target_file_contents = analysis. file_text ( file_position. file_id ) . unwrap ( ) ;
@@ -327,7 +334,7 @@ mod tests {
327334 let ra_fixture_after = & trim_indent ( ra_fixture_after) ;
328335 let ( analysis, file_pos) = analysis_and_position ( ra_fixture_before) ;
329336 let current_file_id = file_pos. file_id ;
330- let diagnostic = analysis. diagnostics ( current_file_id) . unwrap ( ) . pop ( ) . unwrap ( ) ;
337+ let diagnostic = analysis. diagnostics ( current_file_id, true ) . unwrap ( ) . pop ( ) . unwrap ( ) ;
331338 let mut fix = diagnostic. fix . unwrap ( ) ;
332339 let edit = fix. source_change . source_file_edits . pop ( ) . unwrap ( ) ;
333340 let changed_file_id = edit. file_id ;
@@ -348,14 +355,14 @@ mod tests {
348355 let analysis = mock. analysis ( ) ;
349356 let diagnostics = files
350357 . into_iter ( )
351- . flat_map ( |file_id| analysis. diagnostics ( file_id) . unwrap ( ) )
358+ . flat_map ( |file_id| analysis. diagnostics ( file_id, true ) . unwrap ( ) )
352359 . collect :: < Vec < _ > > ( ) ;
353360 assert_eq ! ( diagnostics. len( ) , 0 , "unexpected diagnostics:\n {:#?}" , diagnostics) ;
354361 }
355362
356363 fn check_expect ( ra_fixture : & str , expect : Expect ) {
357364 let ( analysis, file_id) = single_file ( ra_fixture) ;
358- let diagnostics = analysis. diagnostics ( file_id) . unwrap ( ) ;
365+ let diagnostics = analysis. diagnostics ( file_id, true ) . unwrap ( ) ;
359366 expect. assert_debug_eq ( & diagnostics)
360367 }
361368
0 commit comments