@@ -21,7 +21,7 @@ use ra_syntax::{
2121} ;
2222use ra_text_edit:: { TextEdit , TextEditBuilder } ;
2323
24- use crate :: { Diagnostic , FileId , FileSystemEdit , SourceChange , SourceFileEdit } ;
24+ use crate :: { Diagnostic , FileId , FileSystemEdit , Fix , SourceChange , SourceFileEdit } ;
2525
2626#[ derive( Debug , Copy , Clone ) ]
2727pub enum Severity {
@@ -63,8 +63,8 @@ pub(crate) fn diagnostics(db: &RootDatabase, file_id: FileId) -> Vec<Diagnostic>
6363 . parent ( )
6464 . unwrap_or_else ( || RelativePath :: new ( "" ) )
6565 . 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 ( ) ) ;
6868 res. borrow_mut ( ) . push ( Diagnostic {
6969 range : sema. diagnostics_range ( d) . range ,
7070 message : d. message ( ) ,
@@ -88,14 +88,12 @@ pub(crate) fn diagnostics(db: &RootDatabase, file_id: FileId) -> Vec<Diagnostic>
8888 field_list = field_list. append_field ( & field) ;
8989 }
9090
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 ( ) ) )
9997 } ;
10098
10199 res. borrow_mut ( ) . push ( Diagnostic {
@@ -117,7 +115,8 @@ pub(crate) fn diagnostics(db: &RootDatabase, file_id: FileId) -> Vec<Diagnostic>
117115 let node = d. ast ( db) ;
118116 let replacement = format ! ( "Ok({})" , node. syntax( ) ) ;
119117 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) ;
121120 res. borrow_mut ( ) . push ( Diagnostic {
122121 range : sema. diagnostics_range ( d) . range ,
123122 message : d. message ( ) ,
@@ -154,9 +153,9 @@ fn check_unnecessary_braces_in_use_statement(
154153 range,
155154 message : "Unnecessary braces in use statement" . to_string ( ) ,
156155 severity : Severity :: WeakWarning ,
157- fix : Some ( SourceChange :: source_file_edit (
156+ fix : Some ( Fix :: new (
158157 "Remove unnecessary braces" ,
159- SourceFileEdit { file_id, edit } ,
158+ SourceFileEdit { file_id, edit } . into ( ) ,
160159 ) ) ,
161160 } ) ;
162161 }
@@ -198,9 +197,9 @@ fn check_struct_shorthand_initialization(
198197 range : record_field. syntax ( ) . text_range ( ) ,
199198 message : "Shorthand struct initialization" . to_string ( ) ,
200199 severity : Severity :: WeakWarning ,
201- fix : Some ( SourceChange :: source_file_edit (
200+ fix : Some ( Fix :: new (
202201 "Use struct shorthand initialization" ,
203- SourceFileEdit { file_id, edit } ,
202+ SourceFileEdit { file_id, edit } . into ( ) ,
204203 ) ) ,
205204 } ) ;
206205 }
@@ -240,7 +239,7 @@ mod tests {
240239 let diagnostic =
241240 diagnostics. pop ( ) . unwrap_or_else ( || panic ! ( "no diagnostics for:\n {}\n " , before) ) ;
242241 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 ;
244243 let actual = {
245244 let mut actual = before. to_string ( ) ;
246245 edit. apply ( & mut actual) ;
@@ -258,7 +257,7 @@ mod tests {
258257 let ( analysis, file_position) = analysis_and_position ( fixture) ;
259258 let diagnostic = analysis. diagnostics ( file_position. file_id ) . unwrap ( ) . pop ( ) . unwrap ( ) ;
260259 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 ;
262261 let target_file_contents = analysis. file_text ( file_position. file_id ) . unwrap ( ) ;
263262 let actual = {
264263 let mut actual = target_file_contents. to_string ( ) ;
@@ -295,7 +294,7 @@ mod tests {
295294 let ( analysis, file_id) = single_file ( before) ;
296295 let diagnostic = analysis. diagnostics ( file_id) . unwrap ( ) . pop ( ) . unwrap ( ) ;
297296 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 ;
299298 let actual = {
300299 let mut actual = before. to_string ( ) ;
301300 edit. apply ( & mut actual) ;
@@ -616,22 +615,24 @@ mod tests {
616615 Diagnostic {
617616 message: "unresolved module",
618617 range: 0..8,
618+ severity: Error,
619619 fix: Some(
620- SourceChange {
620+ Fix {
621621 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+ },
632634 },
633635 ),
634- severity: Error,
635636 },
636637 ]
637638 "### ) ;
@@ -665,29 +666,31 @@ mod tests {
665666 Diagnostic {
666667 message: "Missing structure fields:\n- b",
667668 range: 224..233,
669+ severity: Error,
668670 fix: Some(
669- SourceChange {
671+ Fix {
670672 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+ },
683687 },
684- } ,
685- ],
686- file_system_edits: [] ,
687- is_snippet: false ,
688+ ] ,
689+ file_system_edits: [ ],
690+ is_snippet: false ,
691+ } ,
688692 },
689693 ),
690- severity: Error,
691694 },
692695 ]
693696 "### ) ;
0 commit comments