@@ -21,7 +21,7 @@ use ra_syntax::{
21
21
} ;
22
22
use ra_text_edit:: { TextEdit , TextEditBuilder } ;
23
23
24
- use crate :: { Diagnostic , FileId , FileSystemEdit , SourceChange , SourceFileEdit } ;
24
+ use crate :: { Diagnostic , FileId , FileSystemEdit , Fix , SourceChange , SourceFileEdit } ;
25
25
26
26
#[ derive( Debug , Copy , Clone ) ]
27
27
pub enum Severity {
@@ -63,8 +63,8 @@ pub(crate) fn diagnostics(db: &RootDatabase, file_id: FileId) -> Vec<Diagnostic>
63
63
. parent ( )
64
64
. unwrap_or_else ( || RelativePath :: new ( "" ) )
65
65
. join ( & d. candidate ) ;
66
- let create_file = FileSystemEdit :: CreateFile { source_root , path } ;
67
- let fix = SourceChange :: file_system_edit ( "Create module" , create_file ) ;
66
+ let fix =
67
+ Fix :: new ( "Create module" , FileSystemEdit :: CreateFile { source_root , path } . into ( ) ) ;
68
68
res. borrow_mut ( ) . push ( Diagnostic {
69
69
range : sema. diagnostics_range ( d) . range ,
70
70
message : d. message ( ) ,
@@ -88,14 +88,12 @@ pub(crate) fn diagnostics(db: &RootDatabase, file_id: FileId) -> Vec<Diagnostic>
88
88
field_list = field_list. append_field ( & field) ;
89
89
}
90
90
91
- let mut builder = TextEditBuilder :: default ( ) ;
92
- algo:: diff ( & d. ast ( db) . syntax ( ) , & field_list. syntax ( ) ) . into_text_edit ( & mut builder) ;
93
-
94
- Some ( SourceChange :: source_file_edit_from (
95
- "Fill struct fields" ,
96
- file_id,
97
- builder. finish ( ) ,
98
- ) )
91
+ let edit = {
92
+ let mut builder = TextEditBuilder :: default ( ) ;
93
+ algo:: diff ( & d. ast ( db) . syntax ( ) , & field_list. syntax ( ) ) . into_text_edit ( & mut builder) ;
94
+ builder. finish ( )
95
+ } ;
96
+ Some ( Fix :: new ( "Fill struct fields" , SourceFileEdit { file_id, edit } . into ( ) ) )
99
97
} ;
100
98
101
99
res. borrow_mut ( ) . push ( Diagnostic {
@@ -117,7 +115,8 @@ pub(crate) fn diagnostics(db: &RootDatabase, file_id: FileId) -> Vec<Diagnostic>
117
115
let node = d. ast ( db) ;
118
116
let replacement = format ! ( "Ok({})" , node. syntax( ) ) ;
119
117
let edit = TextEdit :: replace ( node. syntax ( ) . text_range ( ) , replacement) ;
120
- let fix = SourceChange :: source_file_edit_from ( "Wrap with ok" , file_id, edit) ;
118
+ let source_change = SourceChange :: source_file_edit_from ( file_id, edit) ;
119
+ let fix = Fix :: new ( "Wrap with ok" , source_change) ;
121
120
res. borrow_mut ( ) . push ( Diagnostic {
122
121
range : sema. diagnostics_range ( d) . range ,
123
122
message : d. message ( ) ,
@@ -154,9 +153,9 @@ fn check_unnecessary_braces_in_use_statement(
154
153
range,
155
154
message : "Unnecessary braces in use statement" . to_string ( ) ,
156
155
severity : Severity :: WeakWarning ,
157
- fix : Some ( SourceChange :: source_file_edit (
156
+ fix : Some ( Fix :: new (
158
157
"Remove unnecessary braces" ,
159
- SourceFileEdit { file_id, edit } ,
158
+ SourceFileEdit { file_id, edit } . into ( ) ,
160
159
) ) ,
161
160
} ) ;
162
161
}
@@ -198,9 +197,9 @@ fn check_struct_shorthand_initialization(
198
197
range : record_field. syntax ( ) . text_range ( ) ,
199
198
message : "Shorthand struct initialization" . to_string ( ) ,
200
199
severity : Severity :: WeakWarning ,
201
- fix : Some ( SourceChange :: source_file_edit (
200
+ fix : Some ( Fix :: new (
202
201
"Use struct shorthand initialization" ,
203
- SourceFileEdit { file_id, edit } ,
202
+ SourceFileEdit { file_id, edit } . into ( ) ,
204
203
) ) ,
205
204
} ) ;
206
205
}
@@ -240,7 +239,7 @@ mod tests {
240
239
let diagnostic =
241
240
diagnostics. pop ( ) . unwrap_or_else ( || panic ! ( "no diagnostics for:\n {}\n " , before) ) ;
242
241
let mut fix = diagnostic. fix . unwrap ( ) ;
243
- let edit = fix. source_file_edits . pop ( ) . unwrap ( ) . edit ;
242
+ let edit = fix. source_change . source_file_edits . pop ( ) . unwrap ( ) . edit ;
244
243
let actual = {
245
244
let mut actual = before. to_string ( ) ;
246
245
edit. apply ( & mut actual) ;
@@ -258,7 +257,7 @@ mod tests {
258
257
let ( analysis, file_position) = analysis_and_position ( fixture) ;
259
258
let diagnostic = analysis. diagnostics ( file_position. file_id ) . unwrap ( ) . pop ( ) . unwrap ( ) ;
260
259
let mut fix = diagnostic. fix . unwrap ( ) ;
261
- let edit = fix. source_file_edits . pop ( ) . unwrap ( ) . edit ;
260
+ let edit = fix. source_change . source_file_edits . pop ( ) . unwrap ( ) . edit ;
262
261
let target_file_contents = analysis. file_text ( file_position. file_id ) . unwrap ( ) ;
263
262
let actual = {
264
263
let mut actual = target_file_contents. to_string ( ) ;
@@ -295,7 +294,7 @@ mod tests {
295
294
let ( analysis, file_id) = single_file ( before) ;
296
295
let diagnostic = analysis. diagnostics ( file_id) . unwrap ( ) . pop ( ) . unwrap ( ) ;
297
296
let mut fix = diagnostic. fix . unwrap ( ) ;
298
- let edit = fix. source_file_edits . pop ( ) . unwrap ( ) . edit ;
297
+ let edit = fix. source_change . source_file_edits . pop ( ) . unwrap ( ) . edit ;
299
298
let actual = {
300
299
let mut actual = before. to_string ( ) ;
301
300
edit. apply ( & mut actual) ;
@@ -616,22 +615,24 @@ mod tests {
616
615
Diagnostic {
617
616
message: "unresolved module",
618
617
range: 0..8,
618
+ severity: Error,
619
619
fix: Some(
620
- SourceChange {
620
+ Fix {
621
621
label: "Create module",
622
- source_file_edits: [],
623
- file_system_edits: [
624
- CreateFile {
625
- source_root: SourceRootId(
626
- 0,
627
- ),
628
- path: "foo.rs",
629
- },
630
- ],
631
- is_snippet: false,
622
+ source_change: SourceChange {
623
+ source_file_edits: [],
624
+ file_system_edits: [
625
+ CreateFile {
626
+ source_root: SourceRootId(
627
+ 0,
628
+ ),
629
+ path: "foo.rs",
630
+ },
631
+ ],
632
+ is_snippet: false,
633
+ },
632
634
},
633
635
),
634
- severity: Error,
635
636
},
636
637
]
637
638
"### ) ;
@@ -665,29 +666,31 @@ mod tests {
665
666
Diagnostic {
666
667
message: "Missing structure fields:\n- b",
667
668
range: 224..233,
669
+ severity: Error,
668
670
fix: Some(
669
- SourceChange {
671
+ Fix {
670
672
label: "Fill struct fields",
671
- source_file_edits: [
672
- SourceFileEdit {
673
- file_id: FileId(
674
- 1,
675
- ),
676
- edit: TextEdit {
677
- indels: [
678
- Indel {
679
- insert: "{a:42, b: ()}",
680
- delete: 3..9,
681
- },
682
- ],
673
+ source_change: SourceChange {
674
+ source_file_edits: [
675
+ SourceFileEdit {
676
+ file_id: FileId(
677
+ 1,
678
+ ),
679
+ edit: TextEdit {
680
+ indels: [
681
+ Indel {
682
+ insert: "{a:42, b: ()}",
683
+ delete: 3..9,
684
+ },
685
+ ],
686
+ },
683
687
},
684
- } ,
685
- ],
686
- file_system_edits: [] ,
687
- is_snippet: false ,
688
+ ] ,
689
+ file_system_edits: [ ],
690
+ is_snippet: false ,
691
+ } ,
688
692
},
689
693
),
690
- severity: Error,
691
694
},
692
695
]
693
696
"### ) ;
0 commit comments