@@ -2858,15 +2858,19 @@ pub fn attach_related_diagnostics(
28582858
28592859 // Step 4.
28602860 // Split erlang service normal diagnostics into undefined macro diagnostics (E1507/E1508),
2861- // and other diagnostics
2861+ // unresolved include diagnostics (E1516), and other diagnostics in a single pass
28622862 let mut erlang_service_undefined_macros = Vec :: new ( ) ;
2863+ let mut erlang_service_unresolved_includes = Vec :: new ( ) ;
28632864 let mut erlang_service_other = Vec :: new ( ) ;
28642865
28652866 for d in erlang_service. normal {
28662867 match & d. code {
28672868 DiagnosticCode :: ErlangService ( code) if code == "E1507" || code == "E1508" => {
28682869 erlang_service_undefined_macros. push ( d) ;
28692870 }
2871+ DiagnosticCode :: ErlangService ( code) if code == "E1516" => {
2872+ erlang_service_unresolved_includes. push ( d) ;
2873+ }
28702874 _ => {
28712875 erlang_service_other. push ( d) ;
28722876 }
@@ -2882,33 +2886,60 @@ pub fn attach_related_diagnostics(
28822886 . cloned ( )
28832887 . collect ( ) ;
28842888
2889+ // Collect E1516 from labeled_undefined_errors for filtering
2890+ let unresolved_includes_from_labeled: Vec < _ > = erlang_service_undefined_not_related
2891+ . clone ( )
2892+ . filter ( |d| matches ! ( & d. code, DiagnosticCode :: ErlangService ( code) if code == "E1516" ) )
2893+ . cloned ( )
2894+ . collect ( ) ;
2895+
28852896 // Combine all E1507/E1508 diagnostics for filtering (clone to avoid borrow issues)
28862897 let all_undefined_macros: Vec < _ > = erlang_service_undefined_macros
28872898 . iter ( )
28882899 . cloned ( )
28892900 . chain ( undefined_macros_from_labeled)
28902901 . collect ( ) ;
28912902
2903+ // Combine all E1516 diagnostics for filtering
2904+ let all_unresolved_includes: Vec < _ > = erlang_service_unresolved_includes
2905+ . iter ( )
2906+ . cloned ( )
2907+ . chain ( unresolved_includes_from_labeled)
2908+ . collect ( ) ;
2909+
28922910 // Step 5.
28932911 // Filter out W0056 diagnostics if there's a matching E1507/E1508 for the same macro
2912+ // Filter out W0057 diagnostics if there's a matching E1516 for the same include
28942913 let filtered_native_normal = native. normal . into_iter ( ) . filter ( |d| {
2895- if d. code != DiagnosticCode :: HirUnresolvedMacro {
2896- return true ; // Keep non-W0056 diagnostics
2914+ if d. code == DiagnosticCode :: HirUnresolvedMacro {
2915+ // Check if there's a matching E1507/E1508 diagnostic
2916+ let has_matching_erlang_service = all_undefined_macros. iter ( ) . any ( |es_diag| {
2917+ // Check if ranges overlap
2918+ d. range . intersect ( es_diag. range ) . is_some ( )
2919+ } ) ;
2920+
2921+ // Keep W0056 only if there's no matching E1507/E1508
2922+ return !has_matching_erlang_service;
28972923 }
28982924
2899- // Check if there's a matching E1507/E1508 diagnostic
2900- let has_matching_erlang_service = all_undefined_macros. iter ( ) . any ( |es_diag| {
2901- // Check if ranges overlap
2902- d. range . intersect ( es_diag. range ) . is_some ( )
2903- } ) ;
2925+ if d. code == DiagnosticCode :: HirUnresolvedInclude {
2926+ // Check if there's a matching E1516 diagnostic
2927+ let has_matching_erlang_service = all_unresolved_includes. iter ( ) . any ( |es_diag| {
2928+ // Check if ranges overlap
2929+ d. range . intersect ( es_diag. range ) . is_some ( )
2930+ } ) ;
2931+
2932+ // Keep W0057 only if there's no matching E1516
2933+ return !has_matching_erlang_service;
2934+ }
29042935
2905- // Keep W0056 only if there's no matching E1507/E1508
2906- !has_matching_erlang_service
2936+ true // Keep all other diagnostics
29072937 } ) ;
29082938
29092939 filtered_native_normal
29102940 . chain ( erlang_service_other)
29112941 . chain ( erlang_service_undefined_macros)
2942+ . chain ( erlang_service_unresolved_includes)
29122943 . chain ( syntax_errors_with_related)
29132944 . chain ( erlang_service_undefined_not_related. cloned ( ) )
29142945 // TODO:AZ: consider returning an iterator
0 commit comments