@@ -20,20 +20,21 @@ use syntax::{
2020} ;
2121use text_edit:: TextEdit ;
2222
23- use crate :: { diagnostics:: Fix , references:: rename:: rename_with_semantics, FilePosition } ;
23+ use crate :: { diagnostics:: fix , references:: rename:: rename_with_semantics, Assist , FilePosition } ;
2424
2525/// A [Diagnostic] that potentially has a fix available.
2626///
2727/// [Diagnostic]: hir::diagnostics::Diagnostic
2828pub ( crate ) trait DiagnosticWithFix : Diagnostic {
29- fn fix ( & self , sema : & Semantics < RootDatabase > ) -> Option < Fix > ;
29+ fn fix ( & self , sema : & Semantics < RootDatabase > ) -> Option < Assist > ;
3030}
3131
3232impl DiagnosticWithFix for UnresolvedModule {
33- fn fix ( & self , sema : & Semantics < RootDatabase > ) -> Option < Fix > {
33+ fn fix ( & self , sema : & Semantics < RootDatabase > ) -> Option < Assist > {
3434 let root = sema. db . parse_or_expand ( self . file ) ?;
3535 let unresolved_module = self . decl . to_node ( & root) ;
36- Some ( Fix :: new (
36+ Some ( fix (
37+ "create_module" ,
3738 "Create module" ,
3839 FileSystemEdit :: CreateFile {
3940 dst : AnchoredPathBuf {
@@ -49,7 +50,7 @@ impl DiagnosticWithFix for UnresolvedModule {
4950}
5051
5152impl DiagnosticWithFix for NoSuchField {
52- fn fix ( & self , sema : & Semantics < RootDatabase > ) -> Option < Fix > {
53+ fn fix ( & self , sema : & Semantics < RootDatabase > ) -> Option < Assist > {
5354 let root = sema. db . parse_or_expand ( self . file ) ?;
5455 missing_record_expr_field_fix (
5556 & sema,
@@ -60,7 +61,7 @@ impl DiagnosticWithFix for NoSuchField {
6061}
6162
6263impl DiagnosticWithFix for MissingFields {
63- fn fix ( & self , sema : & Semantics < RootDatabase > ) -> Option < Fix > {
64+ fn fix ( & self , sema : & Semantics < RootDatabase > ) -> Option < Assist > {
6465 // Note that although we could add a diagnostics to
6566 // fill the missing tuple field, e.g :
6667 // `struct A(usize);`
@@ -86,7 +87,8 @@ impl DiagnosticWithFix for MissingFields {
8687 . into_text_edit ( & mut builder) ;
8788 builder. finish ( )
8889 } ;
89- Some ( Fix :: new (
90+ Some ( fix (
91+ "fill_missing_fields" ,
9092 "Fill struct fields" ,
9193 SourceChange :: from_text_edit ( self . file . original_file ( sema. db ) , edit) ,
9294 sema. original_range ( & field_list_parent. syntax ( ) ) . range ,
@@ -95,20 +97,20 @@ impl DiagnosticWithFix for MissingFields {
9597}
9698
9799impl DiagnosticWithFix for MissingOkOrSomeInTailExpr {
98- fn fix ( & self , sema : & Semantics < RootDatabase > ) -> Option < Fix > {
100+ fn fix ( & self , sema : & Semantics < RootDatabase > ) -> Option < Assist > {
99101 let root = sema. db . parse_or_expand ( self . file ) ?;
100102 let tail_expr = self . expr . to_node ( & root) ;
101103 let tail_expr_range = tail_expr. syntax ( ) . text_range ( ) ;
102104 let replacement = format ! ( "{}({})" , self . required, tail_expr. syntax( ) ) ;
103105 let edit = TextEdit :: replace ( tail_expr_range, replacement) ;
104106 let source_change = SourceChange :: from_text_edit ( self . file . original_file ( sema. db ) , edit) ;
105107 let name = if self . required == "Ok" { "Wrap with Ok" } else { "Wrap with Some" } ;
106- Some ( Fix :: new ( name, source_change, tail_expr_range) )
108+ Some ( fix ( "wrap_tail_expr" , name, source_change, tail_expr_range) )
107109 }
108110}
109111
110112impl DiagnosticWithFix for RemoveThisSemicolon {
111- fn fix ( & self , sema : & Semantics < RootDatabase > ) -> Option < Fix > {
113+ fn fix ( & self , sema : & Semantics < RootDatabase > ) -> Option < Assist > {
112114 let root = sema. db . parse_or_expand ( self . file ) ?;
113115
114116 let semicolon = self
@@ -123,12 +125,12 @@ impl DiagnosticWithFix for RemoveThisSemicolon {
123125 let edit = TextEdit :: delete ( semicolon) ;
124126 let source_change = SourceChange :: from_text_edit ( self . file . original_file ( sema. db ) , edit) ;
125127
126- Some ( Fix :: new ( "Remove this semicolon" , source_change, semicolon) )
128+ Some ( fix ( "remove_semicolon" , "Remove this semicolon" , source_change, semicolon) )
127129 }
128130}
129131
130132impl DiagnosticWithFix for IncorrectCase {
131- fn fix ( & self , sema : & Semantics < RootDatabase > ) -> Option < Fix > {
133+ fn fix ( & self , sema : & Semantics < RootDatabase > ) -> Option < Assist > {
132134 let root = sema. db . parse_or_expand ( self . file ) ?;
133135 let name_node = self . ident . to_node ( & root) ;
134136
@@ -140,12 +142,12 @@ impl DiagnosticWithFix for IncorrectCase {
140142 rename_with_semantics ( sema, file_position, & self . suggested_text ) . ok ( ) ?;
141143
142144 let label = format ! ( "Rename to {}" , self . suggested_text) ;
143- Some ( Fix :: new ( & label, rename_changes, frange. range ) )
145+ Some ( fix ( "change_case" , & label, rename_changes, frange. range ) )
144146 }
145147}
146148
147149impl DiagnosticWithFix for ReplaceFilterMapNextWithFindMap {
148- fn fix ( & self , sema : & Semantics < RootDatabase > ) -> Option < Fix > {
150+ fn fix ( & self , sema : & Semantics < RootDatabase > ) -> Option < Assist > {
149151 let root = sema. db . parse_or_expand ( self . file ) ?;
150152 let next_expr = self . next_expr . to_node ( & root) ;
151153 let next_call = ast:: MethodCallExpr :: cast ( next_expr. syntax ( ) . clone ( ) ) ?;
@@ -163,7 +165,8 @@ impl DiagnosticWithFix for ReplaceFilterMapNextWithFindMap {
163165
164166 let source_change = SourceChange :: from_text_edit ( self . file . original_file ( sema. db ) , edit) ;
165167
166- Some ( Fix :: new (
168+ Some ( fix (
169+ "replace_with_find_map" ,
167170 "Replace filter_map(..).next() with find_map()" ,
168171 source_change,
169172 trigger_range,
@@ -175,7 +178,7 @@ fn missing_record_expr_field_fix(
175178 sema : & Semantics < RootDatabase > ,
176179 usage_file_id : FileId ,
177180 record_expr_field : & ast:: RecordExprField ,
178- ) -> Option < Fix > {
181+ ) -> Option < Assist > {
179182 let record_lit = ast:: RecordExpr :: cast ( record_expr_field. syntax ( ) . parent ( ) ?. parent ( ) ?) ?;
180183 let def_id = sema. resolve_variant ( record_lit) ?;
181184 let module;
@@ -233,7 +236,12 @@ fn missing_record_expr_field_fix(
233236 def_file_id,
234237 TextEdit :: insert ( last_field_syntax. text_range ( ) . end ( ) , new_field) ,
235238 ) ;
236- return Some ( Fix :: new ( "Create field" , source_change, record_expr_field. syntax ( ) . text_range ( ) ) ) ;
239+ return Some ( fix (
240+ "create_field" ,
241+ "Create field" ,
242+ source_change,
243+ record_expr_field. syntax ( ) . text_range ( ) ,
244+ ) ) ;
237245
238246 fn record_field_list ( field_def_list : ast:: FieldList ) -> Option < ast:: RecordFieldList > {
239247 match field_def_list {
0 commit comments