@@ -84,6 +84,7 @@ pub struct DiagnosticsConfig {
84
84
pub ( crate ) fn diagnostics (
85
85
db : & RootDatabase ,
86
86
config : & DiagnosticsConfig ,
87
+ resolve : bool ,
87
88
file_id : FileId ,
88
89
) -> Vec < Diagnostic > {
89
90
let _p = profile:: span ( "diagnostics" ) ;
@@ -107,25 +108,25 @@ pub(crate) fn diagnostics(
107
108
let res = RefCell :: new ( res) ;
108
109
let sink_builder = DiagnosticSinkBuilder :: new ( )
109
110
. on :: < hir:: diagnostics:: UnresolvedModule , _ > ( |d| {
110
- res. borrow_mut ( ) . push ( diagnostic_with_fix ( d, & sema) ) ;
111
+ res. borrow_mut ( ) . push ( diagnostic_with_fix ( d, & sema, resolve ) ) ;
111
112
} )
112
113
. on :: < hir:: diagnostics:: MissingFields , _ > ( |d| {
113
- res. borrow_mut ( ) . push ( diagnostic_with_fix ( d, & sema) ) ;
114
+ res. borrow_mut ( ) . push ( diagnostic_with_fix ( d, & sema, resolve ) ) ;
114
115
} )
115
116
. on :: < hir:: diagnostics:: MissingOkOrSomeInTailExpr , _ > ( |d| {
116
- res. borrow_mut ( ) . push ( diagnostic_with_fix ( d, & sema) ) ;
117
+ res. borrow_mut ( ) . push ( diagnostic_with_fix ( d, & sema, resolve ) ) ;
117
118
} )
118
119
. on :: < hir:: diagnostics:: NoSuchField , _ > ( |d| {
119
- res. borrow_mut ( ) . push ( diagnostic_with_fix ( d, & sema) ) ;
120
+ res. borrow_mut ( ) . push ( diagnostic_with_fix ( d, & sema, resolve ) ) ;
120
121
} )
121
122
. on :: < hir:: diagnostics:: RemoveThisSemicolon , _ > ( |d| {
122
- res. borrow_mut ( ) . push ( diagnostic_with_fix ( d, & sema) ) ;
123
+ res. borrow_mut ( ) . push ( diagnostic_with_fix ( d, & sema, resolve ) ) ;
123
124
} )
124
125
. on :: < hir:: diagnostics:: IncorrectCase , _ > ( |d| {
125
- res. borrow_mut ( ) . push ( warning_with_fix ( d, & sema) ) ;
126
+ res. borrow_mut ( ) . push ( warning_with_fix ( d, & sema, resolve ) ) ;
126
127
} )
127
128
. on :: < hir:: diagnostics:: ReplaceFilterMapNextWithFindMap , _ > ( |d| {
128
- res. borrow_mut ( ) . push ( warning_with_fix ( d, & sema) ) ;
129
+ res. borrow_mut ( ) . push ( warning_with_fix ( d, & sema, resolve ) ) ;
129
130
} )
130
131
. on :: < hir:: diagnostics:: InactiveCode , _ > ( |d| {
131
132
// If there's inactive code somewhere in a macro, don't propagate to the call-site.
@@ -152,7 +153,7 @@ pub(crate) fn diagnostics(
152
153
// Override severity and mark as unused.
153
154
res. borrow_mut ( ) . push (
154
155
Diagnostic :: hint ( range, d. message ( ) )
155
- . with_fix ( d. fix ( & sema) )
156
+ . with_fix ( d. fix ( & sema, resolve ) )
156
157
. with_code ( Some ( d. code ( ) ) ) ,
157
158
) ;
158
159
} )
@@ -208,15 +209,23 @@ pub(crate) fn diagnostics(
208
209
res. into_inner ( )
209
210
}
210
211
211
- fn diagnostic_with_fix < D : DiagnosticWithFix > ( d : & D , sema : & Semantics < RootDatabase > ) -> Diagnostic {
212
+ fn diagnostic_with_fix < D : DiagnosticWithFix > (
213
+ d : & D ,
214
+ sema : & Semantics < RootDatabase > ,
215
+ resolve : bool ,
216
+ ) -> Diagnostic {
212
217
Diagnostic :: error ( sema. diagnostics_display_range ( d. display_source ( ) ) . range , d. message ( ) )
213
- . with_fix ( d. fix ( & sema) )
218
+ . with_fix ( d. fix ( & sema, resolve ) )
214
219
. with_code ( Some ( d. code ( ) ) )
215
220
}
216
221
217
- fn warning_with_fix < D : DiagnosticWithFix > ( d : & D , sema : & Semantics < RootDatabase > ) -> Diagnostic {
222
+ fn warning_with_fix < D : DiagnosticWithFix > (
223
+ d : & D ,
224
+ sema : & Semantics < RootDatabase > ,
225
+ resolve : bool ,
226
+ ) -> Diagnostic {
218
227
Diagnostic :: hint ( sema. diagnostics_display_range ( d. display_source ( ) ) . range , d. message ( ) )
219
- . with_fix ( d. fix ( & sema) )
228
+ . with_fix ( d. fix ( & sema, resolve ) )
220
229
. with_code ( Some ( d. code ( ) ) )
221
230
}
222
231
@@ -271,13 +280,19 @@ fn text_edit_for_remove_unnecessary_braces_with_self_in_use_statement(
271
280
}
272
281
273
282
fn fix ( id : & ' static str , label : & str , source_change : SourceChange , target : TextRange ) -> Assist {
283
+ let mut res = unresolved_fix ( id, label, target) ;
284
+ res. source_change = Some ( source_change) ;
285
+ res
286
+ }
287
+
288
+ fn unresolved_fix ( id : & ' static str , label : & str , target : TextRange ) -> Assist {
274
289
assert ! ( !id. contains( ' ' ) ) ;
275
290
Assist {
276
291
id : AssistId ( id, AssistKind :: QuickFix ) ,
277
292
label : Label :: new ( label) ,
278
293
group : None ,
279
294
target,
280
- source_change : Some ( source_change ) ,
295
+ source_change : None ,
281
296
}
282
297
}
283
298
@@ -299,7 +314,7 @@ mod tests {
299
314
300
315
let ( analysis, file_position) = fixture:: position ( ra_fixture_before) ;
301
316
let diagnostic = analysis
302
- . diagnostics ( & DiagnosticsConfig :: default ( ) , file_position. file_id )
317
+ . diagnostics ( & DiagnosticsConfig :: default ( ) , true , file_position. file_id )
303
318
. unwrap ( )
304
319
. pop ( )
305
320
. unwrap ( ) ;
@@ -328,7 +343,7 @@ mod tests {
328
343
fn check_no_fix ( ra_fixture : & str ) {
329
344
let ( analysis, file_position) = fixture:: position ( ra_fixture) ;
330
345
let diagnostic = analysis
331
- . diagnostics ( & DiagnosticsConfig :: default ( ) , file_position. file_id )
346
+ . diagnostics ( & DiagnosticsConfig :: default ( ) , true , file_position. file_id )
332
347
. unwrap ( )
333
348
. pop ( )
334
349
. unwrap ( ) ;
@@ -342,15 +357,16 @@ mod tests {
342
357
let diagnostics = files
343
358
. into_iter ( )
344
359
. flat_map ( |file_id| {
345
- analysis. diagnostics ( & DiagnosticsConfig :: default ( ) , file_id) . unwrap ( )
360
+ analysis. diagnostics ( & DiagnosticsConfig :: default ( ) , true , file_id) . unwrap ( )
346
361
} )
347
362
. collect :: < Vec < _ > > ( ) ;
348
363
assert_eq ! ( diagnostics. len( ) , 0 , "unexpected diagnostics:\n {:#?}" , diagnostics) ;
349
364
}
350
365
351
366
fn check_expect ( ra_fixture : & str , expect : Expect ) {
352
367
let ( analysis, file_id) = fixture:: file ( ra_fixture) ;
353
- let diagnostics = analysis. diagnostics ( & DiagnosticsConfig :: default ( ) , file_id) . unwrap ( ) ;
368
+ let diagnostics =
369
+ analysis. diagnostics ( & DiagnosticsConfig :: default ( ) , true , file_id) . unwrap ( ) ;
354
370
expect. assert_debug_eq ( & diagnostics)
355
371
}
356
372
@@ -895,10 +911,11 @@ struct Foo {
895
911
896
912
let ( analysis, file_id) = fixture:: file ( r#"mod foo;"# ) ;
897
913
898
- let diagnostics = analysis. diagnostics ( & config, file_id) . unwrap ( ) ;
914
+ let diagnostics = analysis. diagnostics ( & config, true , file_id) . unwrap ( ) ;
899
915
assert ! ( diagnostics. is_empty( ) ) ;
900
916
901
- let diagnostics = analysis. diagnostics ( & DiagnosticsConfig :: default ( ) , file_id) . unwrap ( ) ;
917
+ let diagnostics =
918
+ analysis. diagnostics ( & DiagnosticsConfig :: default ( ) , true , file_id) . unwrap ( ) ;
902
919
assert ! ( !diagnostics. is_empty( ) ) ;
903
920
}
904
921
@@ -1004,8 +1021,9 @@ impl TestStruct {
1004
1021
let expected = r#"fn foo() {}"# ;
1005
1022
1006
1023
let ( analysis, file_position) = fixture:: position ( input) ;
1007
- let diagnostics =
1008
- analysis. diagnostics ( & DiagnosticsConfig :: default ( ) , file_position. file_id ) . unwrap ( ) ;
1024
+ let diagnostics = analysis
1025
+ . diagnostics ( & DiagnosticsConfig :: default ( ) , true , file_position. file_id )
1026
+ . unwrap ( ) ;
1009
1027
assert_eq ! ( diagnostics. len( ) , 1 ) ;
1010
1028
1011
1029
check_fix ( input, expected) ;
0 commit comments