@@ -18,14 +18,21 @@ pub mod diagnostics;
18
18
use diagnostics:: { Diagnostic , DiagnosticSpan } ;
19
19
mod replace;
20
20
21
+ #[ derive( Debug , Clone , Copy ) ]
22
+ pub enum Filter {
23
+ MachineApplicableOnly ,
24
+ Everything ,
25
+ }
26
+
21
27
pub fn get_suggestions_from_json < S : :: std:: hash:: BuildHasher > (
22
28
input : & str ,
23
29
only : & HashSet < String , S > ,
30
+ filter : Filter ,
24
31
) -> serde_json:: error:: Result < Vec < Suggestion > > {
25
32
let mut result = Vec :: new ( ) ;
26
33
for cargo_msg in serde_json:: Deserializer :: from_str ( input) . into_iter :: < Diagnostic > ( ) {
27
34
// One diagnostic line might have multiple suggestions
28
- result. extend ( collect_suggestions ( & cargo_msg?, only) ) ;
35
+ result. extend ( collect_suggestions ( & cargo_msg?, only, filter ) ) ;
29
36
}
30
37
Ok ( result)
31
38
}
@@ -142,6 +149,7 @@ fn collect_span(span: &DiagnosticSpan) -> Option<Replacement> {
142
149
pub fn collect_suggestions < S : :: std:: hash:: BuildHasher > (
143
150
diagnostic : & Diagnostic ,
144
151
only : & HashSet < String , S > ,
152
+ filter : Filter ,
145
153
) -> Option < Suggestion > {
146
154
if !only. is_empty ( ) {
147
155
if let Some ( ref code) = diagnostic. code {
@@ -165,7 +173,21 @@ pub fn collect_suggestions<S: ::std::hash::BuildHasher>(
165
173
. children
166
174
. iter ( )
167
175
. filter_map ( |child| {
168
- let replacements: Vec < _ > = child. spans . iter ( ) . filter_map ( collect_span) . collect ( ) ;
176
+ let replacements: Vec < _ > = child
177
+ . spans
178
+ . iter ( )
179
+ . filter ( |span| {
180
+ use Filter :: * ;
181
+ use diagnostics:: Applicability :: * ;
182
+
183
+ match ( filter, & span. suggestion_applicability ) {
184
+ ( MachineApplicableOnly , Some ( MachineApplicable ) ) => true ,
185
+ ( MachineApplicableOnly , _) => false ,
186
+ ( Everything , _) => true ,
187
+ }
188
+ } )
189
+ . filter_map ( collect_span)
190
+ . collect ( ) ;
169
191
if replacements. len ( ) == 1 {
170
192
Some ( Solution {
171
193
message : child. message . clone ( ) ,
0 commit comments