Skip to content

Commit ed67311

Browse files
alanzmeta-codesync[bot]
authored andcommitted
4/n: include: do not report W0057 if it is already reported by the erlang service
Summary: As title. Reviewed By: TD5 Differential Revision: D86963332 fbshipit-source-id: ffb3020fbfd6b09a273d4e34cb28f353fa12deab
1 parent 42ef1d1 commit ed67311

File tree

4 files changed

+56
-10
lines changed

4 files changed

+56
-10
lines changed

crates/elp/src/resources/test/buck_tests_2/resolves_generated_includes.stdout

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ Diagnostics reported in 5 modules:
99
0:8-0:18::[WeakWarning] [W0046] The module is not documented.
1010
eqwalizer: 1
1111
1:8-1:17::[WeakWarning] [W0046] The module is not documented.
12-
top_includer: 3
13-
12:4-12:10::[Warning] [W0057] undefined macro 'THIRD/2'
12+
top_includer: 2
1413
0:8-0:20::[WeakWarning] [W0046] The module is not documented.
1514
12:4-12:10::[Error] [E1508] undefined macro 'THIRD/2'
1615
wa_buck2_module_search: 6
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
module specified: main_app
22
Diagnostics reported in 1 modules:
3-
main_app: 6
3+
main_app: 5
44
4:13-4:55::[Error] [E1516] can't find include lib "external_app/include/external_header.hrl"
55
11:0-11:42::[Warning] [W0020] Unused file: stdlib/include/assert.hrl
66
14:9-14:21::[Hint] [W0037] Unspecific include.
77
16:9-16:24::[Error] [L1227] function test_function/0 undefined
8-
23:4-23:19::[Warning] [W0057] undefined macro 'EXTERNAL_MACRO'
98
23:4-23:19::[Error] [E1507] undefined macro 'EXTERNAL_MACRO'
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
55
14:9-14:21::[Error] [E1516] can't find include file "assert.hrl"
66
16:9-16:24::[Error] [L1227] function test_function/0 undefined
7-
20:4-20:25::[Warning] [W0057] undefined macro 'normalDepAssertEqual/2'
87
20:4-20:25::[Error] [E1508] undefined macro 'normalDepAssertEqual/2'

crates/ide/src/diagnostics.rs

Lines changed: 53 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2817,10 +2817,59 @@ pub fn attach_related_diagnostics(
28172817
.filter(|(k, _)| !undefineds_to_remove.contains(k))
28182818
.flat_map(|(_, v)| v);
28192819

2820-
native
2821-
.normal
2822-
.into_iter()
2823-
.chain(erlang_service.normal)
2820+
// Step 4.
2821+
// Split erlang service normal diagnostics into undefined macro diagnostics (E1507/E1508),
2822+
// and other diagnostics
2823+
let mut erlang_service_undefined_macros = Vec::new();
2824+
let mut erlang_service_other = Vec::new();
2825+
2826+
for d in erlang_service.normal {
2827+
match &d.code {
2828+
DiagnosticCode::ErlangService(code) if code == "E1507" || code == "E1508" => {
2829+
erlang_service_undefined_macros.push(d);
2830+
}
2831+
_ => {
2832+
erlang_service_other.push(d);
2833+
}
2834+
}
2835+
}
2836+
2837+
// Collect E1507/E1508 from labeled_undefined_errors for filtering
2838+
let undefined_macros_from_labeled: Vec<_> = erlang_service_undefined_not_related
2839+
.clone()
2840+
.filter(|d| {
2841+
matches!(&d.code, DiagnosticCode::ErlangService(code) if code == "E1507" || code == "E1508")
2842+
})
2843+
.cloned()
2844+
.collect();
2845+
2846+
// Combine all E1507/E1508 diagnostics for filtering (clone to avoid borrow issues)
2847+
let all_undefined_macros: Vec<_> = erlang_service_undefined_macros
2848+
.iter()
2849+
.cloned()
2850+
.chain(undefined_macros_from_labeled)
2851+
.collect();
2852+
2853+
// Step 5.
2854+
// Filter out W0056 diagnostics if there's a matching E1507/E1508 for the same macro
2855+
let filtered_native_normal = native.normal.into_iter().filter(|d| {
2856+
if d.code != DiagnosticCode::HirUnresolvedMacro {
2857+
return true; // Keep non-W0056 diagnostics
2858+
}
2859+
2860+
// Check if there's a matching E1507/E1508 diagnostic
2861+
let has_matching_erlang_service = all_undefined_macros.iter().any(|es_diag| {
2862+
// Check if ranges overlap
2863+
d.range.intersect(es_diag.range).is_some()
2864+
});
2865+
2866+
// Keep W0056 only if there's no matching E1507/E1508
2867+
!has_matching_erlang_service
2868+
});
2869+
2870+
filtered_native_normal
2871+
.chain(erlang_service_other)
2872+
.chain(erlang_service_undefined_macros)
28242873
.chain(syntax_errors_with_related)
28252874
.chain(erlang_service_undefined_not_related.cloned())
28262875
// TODO:AZ: consider returning an iterator

0 commit comments

Comments
 (0)