Skip to content

Commit 276297e

Browse files
alanzmeta-codesync[bot]
authored andcommitted
6/n: include: do not report W0058 if is is already reported by the erlang service
Summary: In a properly configured buck2 project, W0058 and E1516 will always be reported at the same time. So do not report W0058 if there is already a E1516. Reviewed By: TD5 Differential Revision: D86963330 fbshipit-source-id: fe1aaaa71330da059ed697d187542e3cb470e965
1 parent a8bb2de commit 276297e

File tree

4 files changed

+44
-16
lines changed

4 files changed

+44
-16
lines changed
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
module specified: app_b
22
Diagnostics reported in 1 modules:
3-
app_b: 2
4-
2:13-2:38::[Warning] [W0058] can't find include lib "app_a/include/app_b.hrl"
3+
app_b: 1
54
2:13-2:38::[Error] [E1516] can't find include lib "app_a/include/app_b.hrl"

crates/elp/src/resources/test/include_lib_dependency_test/include_lib_non_dependency_fails.stdout

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
module specified: main_app
22
Diagnostics reported in 1 modules:
3-
main_app: 6
4-
4:13-4:55::[Warning] [W0058] can't find include lib "external_app/include/external_header.hrl"
3+
main_app: 5
54
4:13-4:55::[Error] [E1516] can't find include lib "external_app/include/external_header.hrl"
65
11:0-11:42::[Warning] [W0020] Unused file: stdlib/include/assert.hrl
76
14:9-14:21::[Hint] [W0037] Unspecific include.
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
module specified: main_app
22
Diagnostics reported in 1 modules:
3-
main_app: 5
3+
main_app: 4
44
11:0-11:42::[Warning] [W0020] Unused file: stdlib/include/assert.hrl
5-
14:9-14:21::[Warning] [W0058] can't find include file "assert.hrl"
65
14:9-14:21::[Error] [E1516] can't find include file "assert.hrl"
76
16:9-16:24::[Error] [L1227] function test_function/0 undefined
87
20:4-20:25::[Error] [E1508] undefined macro 'normalDepAssertEqual/2'

crates/ide/src/diagnostics.rs

Lines changed: 41 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)