@@ -23,7 +23,7 @@ use ra_ide_db::RootDatabase;
2323use ra_syntax:: { TextRange , TextSize } ;
2424use ra_text_edit:: TextEdit ;
2525
26- pub ( crate ) use crate :: assist_ctx:: { Assist , AssistCtx , AssistHandler } ;
26+ pub ( crate ) use crate :: assist_ctx:: { Assist , AssistCtx } ;
2727
2828/// Unique identifier of the assist, should not be shown to the user
2929/// directly.
@@ -109,7 +109,9 @@ pub fn resolved_assists(db: &RootDatabase, range: FileRange) -> Vec<ResolvedAssi
109109}
110110
111111mod handlers {
112- use crate :: AssistHandler ;
112+ use crate :: { Assist , AssistCtx } ;
113+
114+ pub ( crate ) type Handler = fn ( AssistCtx ) -> Option < Assist > ;
113115
114116 mod add_custom_impl;
115117 mod add_derive;
@@ -145,12 +147,13 @@ mod handlers {
145147 mod reorder_fields;
146148 mod unwrap_block;
147149
148- pub ( crate ) fn all ( ) -> & ' static [ AssistHandler ] {
150+ pub ( crate ) fn all ( ) -> & ' static [ Handler ] {
149151 & [
150152 // These are alphabetic for the foolish consistency
151153 add_custom_impl:: add_custom_impl,
152154 add_derive:: add_derive,
153155 add_explicit_type:: add_explicit_type,
156+ add_from_impl_for_enum:: add_from_impl_for_enum,
154157 add_function:: add_function,
155158 add_impl:: add_impl,
156159 add_new:: add_new,
@@ -176,17 +179,18 @@ mod handlers {
176179 raw_string:: remove_hash,
177180 remove_dbg:: remove_dbg,
178181 remove_mut:: remove_mut,
182+ reorder_fields:: reorder_fields,
179183 replace_if_let_with_match:: replace_if_let_with_match,
180184 replace_let_with_if_let:: replace_let_with_if_let,
181185 replace_qualified_name_with_use:: replace_qualified_name_with_use,
182186 replace_unwrap_with_match:: replace_unwrap_with_match,
183187 split_import:: split_import,
184- add_from_impl_for_enum:: add_from_impl_for_enum,
185188 unwrap_block:: unwrap_block,
186189 // These are manually sorted for better priorities
187190 add_missing_impl_members:: add_missing_impl_members,
188191 add_missing_impl_members:: add_missing_default_members,
189- reorder_fields:: reorder_fields,
192+ // Are you sure you want to add new assist here, and not to the
193+ // sorted list above?
190194 ]
191195 }
192196}
@@ -195,12 +199,12 @@ mod handlers {
195199mod helpers {
196200 use std:: sync:: Arc ;
197201
202+ use hir:: Semantics ;
198203 use ra_db:: { fixture:: WithFixture , FileId , FileRange , SourceDatabaseExt } ;
199204 use ra_ide_db:: { symbol_index:: SymbolsDatabase , RootDatabase } ;
200205 use test_utils:: { add_cursor, assert_eq_text, extract_range_or_offset, RangeOrOffset } ;
201206
202- use crate :: { AssistCtx , AssistFile , AssistHandler } ;
203- use hir:: Semantics ;
207+ use crate :: { handlers:: Handler , AssistCtx , AssistFile } ;
204208
205209 pub ( crate ) fn with_single_file ( text : & str ) -> ( RootDatabase , FileId ) {
206210 let ( mut db, file_id) = RootDatabase :: with_single_file ( text) ;
@@ -210,22 +214,18 @@ mod helpers {
210214 ( db, file_id)
211215 }
212216
213- pub ( crate ) fn check_assist (
214- assist : AssistHandler ,
215- ra_fixture_before : & str ,
216- ra_fixture_after : & str ,
217- ) {
217+ pub ( crate ) fn check_assist ( assist : Handler , ra_fixture_before : & str , ra_fixture_after : & str ) {
218218 check ( assist, ra_fixture_before, ExpectedResult :: After ( ra_fixture_after) ) ;
219219 }
220220
221221 // FIXME: instead of having a separate function here, maybe use
222222 // `extract_ranges` and mark the target as `<target> </target>` in the
223223 // fixuture?
224- pub ( crate ) fn check_assist_target ( assist : AssistHandler , ra_fixture : & str , target : & str ) {
224+ pub ( crate ) fn check_assist_target ( assist : Handler , ra_fixture : & str , target : & str ) {
225225 check ( assist, ra_fixture, ExpectedResult :: Target ( target) ) ;
226226 }
227227
228- pub ( crate ) fn check_assist_not_applicable ( assist : AssistHandler , ra_fixture : & str ) {
228+ pub ( crate ) fn check_assist_not_applicable ( assist : Handler , ra_fixture : & str ) {
229229 check ( assist, ra_fixture, ExpectedResult :: NotApplicable ) ;
230230 }
231231
@@ -235,7 +235,7 @@ mod helpers {
235235 Target ( & ' a str ) ,
236236 }
237237
238- fn check ( assist : AssistHandler , before : & str , expected : ExpectedResult ) {
238+ fn check ( assist : Handler , before : & str , expected : ExpectedResult ) {
239239 let ( text_without_caret, file_with_caret_id, range_or_offset, db) =
240240 if before. contains ( "//-" ) {
241241 let ( mut db, position) = RootDatabase :: with_position ( before) ;
@@ -261,13 +261,13 @@ mod helpers {
261261 ( Some ( assist) , ExpectedResult :: After ( after) ) => {
262262 let action = assist. 0 [ 0 ] . action . clone ( ) . unwrap ( ) ;
263263
264- let assisted_file_text = if let AssistFile :: TargetFile ( file_id) = action. file {
264+ let mut actual = if let AssistFile :: TargetFile ( file_id) = action. file {
265265 db. file_text ( file_id) . as_ref ( ) . to_owned ( )
266266 } else {
267267 text_without_caret
268268 } ;
269+ action. edit . apply ( & mut actual) ;
269270
270- let mut actual = action. edit . apply ( & assisted_file_text) ;
271271 match action. cursor_position {
272272 None => {
273273 if let RangeOrOffset :: Offset ( before_cursor_pos) = range_or_offset {
0 commit comments