@@ -149,8 +149,35 @@ pub(crate) fn generate_new(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option
149
149
. clone_for_update ( ) ;
150
150
fn_. indent ( 1 . into ( ) ) ;
151
151
152
- // Add a tabstop before the name
153
152
if let Some ( cap) = ctx. config . snippet_cap {
153
+ match strukt. kind ( ) {
154
+ StructKind :: Tuple ( _) => {
155
+ let struct_args = fn_
156
+ . body ( )
157
+ . unwrap ( )
158
+ . syntax ( )
159
+ . descendants ( )
160
+ . filter ( |it| syntax:: ast:: ArgList :: can_cast ( it. kind ( ) ) )
161
+ . flat_map ( |args| args. children ( ) )
162
+ . filter ( |it| syntax:: ast:: PathExpr :: can_cast ( it. kind ( ) ) )
163
+ . enumerate ( )
164
+ . filter_map ( |( i, node) | {
165
+ if trivial_constructors[ i] . is_none ( ) { Some ( node) } else { None }
166
+ } ) ;
167
+ if let Some ( fn_params) = fn_. param_list ( ) {
168
+ for ( struct_arg, fn_param) in struct_args. zip ( fn_params. params ( ) ) {
169
+ if let Some ( fn_pat) = fn_param. pat ( ) {
170
+ let fn_pat = fn_pat. syntax ( ) . clone ( ) ;
171
+ builder
172
+ . add_placeholder_snippet_group ( cap, vec ! [ struct_arg, fn_pat] ) ;
173
+ }
174
+ }
175
+ }
176
+ }
177
+ _ => { }
178
+ }
179
+
180
+ // Add a tabstop before the name
154
181
if let Some ( name) = fn_. name ( ) {
155
182
builder. add_tabstop_before ( cap, name) ;
156
183
}
@@ -765,8 +792,8 @@ struct Empty;
765
792
struct Foo(String, Empty);
766
793
767
794
impl Foo {
768
- fn $0new(_0 : String) -> Self {
769
- Self(_0 , Empty)
795
+ fn $0new(${1:_0} : String) -> Self {
796
+ Self(${1:_0} , Empty)
770
797
}
771
798
}
772
799
"# ,
@@ -805,8 +832,8 @@ struct Empty {}
805
832
struct Foo(Empty);
806
833
807
834
impl Foo {
808
- fn $0new(_0 : Empty) -> Self {
809
- Self(_0 )
835
+ fn $0new(${1:empty} : Empty) -> Self {
836
+ Self(${1:empty} )
810
837
}
811
838
}
812
839
"# ,
@@ -824,8 +851,8 @@ enum Empty { Bar {} }
824
851
struct Foo(Empty);
825
852
826
853
impl Foo {
827
- fn $0new(_0 : Empty) -> Self {
828
- Self(_0 )
854
+ fn $0new(${1:empty} : Empty) -> Self {
855
+ Self(${1:empty} )
829
856
}
830
857
}
831
858
"# ,
@@ -888,23 +915,25 @@ struct Foo(String$0);
888
915
struct Foo(String);
889
916
890
917
impl Foo {
891
- fn $0new(_0 : String) -> Self {
892
- Self(_0 )
918
+ fn $0new(${1:_0} : String) -> Self {
919
+ Self(${1:_0} )
893
920
}
894
921
}
895
922
"# ,
896
923
) ;
897
924
check_assist (
898
925
generate_new,
899
926
r#"
927
+ struct Vec<T> { };
900
928
struct Foo(String, Vec<i32>$0);
901
929
"# ,
902
930
r#"
931
+ struct Vec<T> { };
903
932
struct Foo(String, Vec<i32>);
904
933
905
934
impl Foo {
906
- fn $0new(_0 : String, _1 : Vec<i32>) -> Self {
907
- Self(_0, _1 )
935
+ fn $0new(${1:_0} : String, ${2:items} : Vec<i32>) -> Self {
936
+ Self(${1:_0}, ${2:items} )
908
937
}
909
938
}
910
939
"# ,
@@ -916,14 +945,16 @@ impl Foo {
916
945
check_assist (
917
946
generate_new,
918
947
r#"
948
+ struct Vec<T> { };
919
949
struct Foo(pub String, pub Vec<i32>$0);
920
950
"# ,
921
951
r#"
952
+ struct Vec<T> { };
922
953
struct Foo(pub String, pub Vec<i32>);
923
954
924
955
impl Foo {
925
- fn $0new(_0 : String, _1 : Vec<i32>) -> Self {
926
- Self(_0, _1 )
956
+ fn $0new(${1:_0} : String, ${2:items} : Vec<i32>) -> Self {
957
+ Self(${1:_0}, ${2:items} )
927
958
}
928
959
}
929
960
"# ,
@@ -1013,8 +1044,8 @@ impl<N: AstNode> AstId<N> {
1013
1044
pub struct Source<T>(pub HirFileId, pub T);
1014
1045
1015
1046
impl<T> Source<T> {
1016
- pub fn $0new(_0 : HirFileId, _1 : T) -> Self {
1017
- Self(_0, _1 )
1047
+ pub fn $0new(${1:_0} : HirFileId, ${2:_1} : T) -> Self {
1048
+ Self(${1:_0}, ${2:_1} )
1018
1049
}
1019
1050
1020
1051
pub fn map<F: FnOnce(T) -> U, U>(self, f: F) -> Source<U> {
0 commit comments