@@ -40,7 +40,10 @@ pub(crate) fn inactive_code(
4040
4141#[ cfg( test) ]
4242mod tests {
43- use crate :: { DiagnosticsConfig , tests:: check_diagnostics_with_config} ;
43+ use ide_db:: RootDatabase ;
44+ use test_fixture:: WithFixture ;
45+
46+ use crate :: { DiagnosticCode , DiagnosticsConfig , tests:: check_diagnostics_with_config} ;
4447
4548 #[ track_caller]
4649 pub ( crate ) fn check ( #[ rust_analyzer:: rust_fixture] ra_fixture : & str ) {
@@ -212,4 +215,41 @@ union FooBar {
212215"# ,
213216 ) ;
214217 }
218+
219+ #[ test]
220+ fn inactive_crate ( ) {
221+ let db = RootDatabase :: with_files (
222+ r#"
223+ #![cfg(false)]
224+
225+ fn foo() {}
226+ "# ,
227+ ) ;
228+ let file_id = db. test_crate ( ) . root_file_id ( & db) ;
229+ let diagnostics = hir:: attach_db ( & db, || {
230+ crate :: full_diagnostics (
231+ & db,
232+ & DiagnosticsConfig :: test_sample ( ) ,
233+ & ide_db:: assists:: AssistResolveStrategy :: All ,
234+ file_id. file_id ( & db) ,
235+ )
236+ } ) ;
237+ let [ inactive_code] = & * diagnostics else {
238+ panic ! ( "expected one inactive_code diagnostic, found {diagnostics:#?}" ) ;
239+ } ;
240+ assert_eq ! (
241+ inactive_code. code,
242+ DiagnosticCode :: Ra ( "inactive-code" , ide_db:: Severity :: WeakWarning )
243+ ) ;
244+ assert_eq ! (
245+ inactive_code. message,
246+ "code is inactive due to #[cfg] directives: false is disabled" ,
247+ ) ;
248+ assert ! ( inactive_code. fixes. is_none( ) ) ;
249+ let full_file_range = file_id. parse ( & db) . syntax_node ( ) . text_range ( ) ;
250+ assert_eq ! (
251+ inactive_code. range,
252+ ide_db:: FileRange { file_id: file_id. file_id( & db) , range: full_file_range } ,
253+ ) ;
254+ }
215255}
0 commit comments