@@ -42,55 +42,50 @@ pub(crate) fn add_new(acc: &mut Assists, ctx: &AssistContext) -> Option<()> {
4242 let impl_def = find_struct_impl ( & ctx, & strukt) ?;
4343
4444 let target = strukt. syntax ( ) . text_range ( ) ;
45- acc. add (
46- AssistId ( "add_new" , AssistKind :: Refactor ) ,
47- "Add default constructor" ,
48- target,
49- |builder| {
50- let mut buf = String :: with_capacity ( 512 ) ;
51-
52- if impl_def. is_some ( ) {
53- buf. push ( '\n' ) ;
54- }
45+ acc. add ( AssistId ( "add_new" , AssistKind :: None ) , "Add default constructor" , target, |builder| {
46+ let mut buf = String :: with_capacity ( 512 ) ;
5547
56- let vis = strukt. visibility ( ) . map_or ( String :: new ( ) , |v| format ! ( "{} " , v) ) ;
57-
58- let params = field_list
59- . fields ( )
60- . filter_map ( |f| {
61- Some ( format ! ( "{}: {}" , f. name( ) ?. syntax( ) , f. ascribed_type( ) ?. syntax( ) ) )
62- } )
63- . sep_by ( ", " ) ;
64- let fields = field_list. fields ( ) . filter_map ( |f| f. name ( ) ) . sep_by ( ", " ) ;
65-
66- format_to ! ( buf, " {}fn new({}) -> Self {{ Self {{ {} }} }}" , vis, params, fields) ;
67-
68- let start_offset = impl_def
69- . and_then ( |impl_def| {
70- buf. push ( '\n' ) ;
71- let start = impl_def
72- . syntax ( )
73- . descendants_with_tokens ( )
74- . find ( |t| t. kind ( ) == T ! [ '{' ] ) ?
75- . text_range ( )
76- . end ( ) ;
77-
78- Some ( start)
79- } )
80- . unwrap_or_else ( || {
81- buf = generate_impl_text ( & strukt, & buf) ;
82- strukt. syntax ( ) . text_range ( ) . end ( )
83- } ) ;
84-
85- match ctx. config . snippet_cap {
86- None => builder. insert ( start_offset, buf) ,
87- Some ( cap) => {
88- buf = buf. replace ( "fn new" , "fn $0new" ) ;
89- builder. insert_snippet ( cap, start_offset, buf) ;
90- }
48+ if impl_def. is_some ( ) {
49+ buf. push ( '\n' ) ;
50+ }
51+
52+ let vis = strukt. visibility ( ) . map_or ( String :: new ( ) , |v| format ! ( "{} " , v) ) ;
53+
54+ let params = field_list
55+ . fields ( )
56+ . filter_map ( |f| {
57+ Some ( format ! ( "{}: {}" , f. name( ) ?. syntax( ) , f. ascribed_type( ) ?. syntax( ) ) )
58+ } )
59+ . sep_by ( ", " ) ;
60+ let fields = field_list. fields ( ) . filter_map ( |f| f. name ( ) ) . sep_by ( ", " ) ;
61+
62+ format_to ! ( buf, " {}fn new({}) -> Self {{ Self {{ {} }} }}" , vis, params, fields) ;
63+
64+ let start_offset = impl_def
65+ . and_then ( |impl_def| {
66+ buf. push ( '\n' ) ;
67+ let start = impl_def
68+ . syntax ( )
69+ . descendants_with_tokens ( )
70+ . find ( |t| t. kind ( ) == T ! [ '{' ] ) ?
71+ . text_range ( )
72+ . end ( ) ;
73+
74+ Some ( start)
75+ } )
76+ . unwrap_or_else ( || {
77+ buf = generate_impl_text ( & strukt, & buf) ;
78+ strukt. syntax ( ) . text_range ( ) . end ( )
79+ } ) ;
80+
81+ match ctx. config . snippet_cap {
82+ None => builder. insert ( start_offset, buf) ,
83+ Some ( cap) => {
84+ buf = buf. replace ( "fn new" , "fn $0new" ) ;
85+ builder. insert_snippet ( cap, start_offset, buf) ;
9186 }
92- } ,
93- )
87+ }
88+ } )
9489}
9590
9691// Generates the surrounding `impl Type { <code> }` including type and lifetime
0 commit comments