@@ -154,6 +154,65 @@ pub(crate) fn check_diagnostics_with_config(config: DiagnosticsConfig, ra_fixtur
154
154
}
155
155
}
156
156
157
+ #[ track_caller]
158
+ pub ( crate ) fn check_diagnostics_ignore_syntax_error ( ra_fixture : & str ) {
159
+ let ( db, files) = RootDatabase :: with_many_files ( ra_fixture) ;
160
+ let mut config = DiagnosticsConfig :: test_sample ( ) ;
161
+ config. disabled . insert ( "inactive-code" . to_string ( ) ) ;
162
+ for file_id in files {
163
+ let line_index = db. line_index ( file_id) ;
164
+ let diagnostics = super :: diagnostics ( & db, & config, & AssistResolveStrategy :: All , file_id) ;
165
+
166
+ let expected = extract_annotations ( & db. file_text ( file_id) ) ;
167
+ let mut actual = diagnostics
168
+ . into_iter ( )
169
+ . filter_map ( |d| {
170
+ if d. message . contains ( "Syntax Error: " ) {
171
+ return None ;
172
+ }
173
+ let mut annotation = String :: new ( ) ;
174
+ if let Some ( fixes) = & d. fixes {
175
+ assert ! ( !fixes. is_empty( ) ) ;
176
+ annotation. push_str ( "💡 " )
177
+ }
178
+ annotation. push_str ( match d. severity {
179
+ Severity :: Error => "error" ,
180
+ Severity :: WeakWarning => "weak" ,
181
+ Severity :: Warning => "warn" ,
182
+ Severity :: Allow => "allow" ,
183
+ } ) ;
184
+ annotation. push_str ( ": " ) ;
185
+ annotation. push_str ( & d. message ) ;
186
+ Some ( ( d. range , annotation) )
187
+ } )
188
+ . collect :: < Vec < _ > > ( ) ;
189
+ actual. sort_by_key ( |( range, _) | range. start ( ) ) ;
190
+ if expected. is_empty ( ) {
191
+ // makes minicore smoke test debugable
192
+ for ( e, _) in & actual {
193
+ eprintln ! (
194
+ "Code in range {e:?} = {}" ,
195
+ & db. file_text( file_id) [ usize :: from( e. start( ) ) ..usize :: from( e. end( ) ) ]
196
+ )
197
+ }
198
+ }
199
+ if expected != actual {
200
+ let fneg = expected
201
+ . iter ( )
202
+ . filter ( |x| !actual. contains ( x) )
203
+ . map ( |( range, s) | ( line_index. line_col ( range. start ( ) ) , range, s) )
204
+ . collect :: < Vec < _ > > ( ) ;
205
+ let fpos = actual
206
+ . iter ( )
207
+ . filter ( |x| !expected. contains ( x) )
208
+ . map ( |( range, s) | ( line_index. line_col ( range. start ( ) ) , range, s) )
209
+ . collect :: < Vec < _ > > ( ) ;
210
+
211
+ panic ! ( "Diagnostic test failed.\n False negatives: {fneg:?}\n False positives: {fpos:?}" ) ;
212
+ }
213
+ }
214
+ }
215
+
157
216
#[ test]
158
217
fn test_disabled_diagnostics ( ) {
159
218
let mut config = DiagnosticsConfig :: test_sample ( ) ;
0 commit comments