@@ -2,7 +2,7 @@ use either::Either;
2
2
use ide_db:: defs:: { Definition , NameRefClass } ;
3
3
use syntax:: {
4
4
ast:: { self , AstNode , HasGenericParams , HasVisibility } ,
5
- match_ast, SyntaxNode ,
5
+ match_ast, SyntaxKind , SyntaxNode ,
6
6
} ;
7
7
8
8
use crate :: { assist_context:: SourceChangeBuilder , AssistContext , AssistId , AssistKind , Assists } ;
@@ -100,7 +100,9 @@ fn edit_struct_def(
100
100
ast:: make:: tokens:: single_newline ( ) . text ( ) ,
101
101
) ;
102
102
edit. insert ( tuple_fields_text_range. start ( ) , w. syntax ( ) . text ( ) ) ;
103
- edit. insert ( tuple_fields_text_range. start ( ) , "," ) ;
103
+ if !w. syntax ( ) . last_token ( ) . is_some_and ( |t| t. kind ( ) == SyntaxKind :: COMMA ) {
104
+ edit. insert ( tuple_fields_text_range. start ( ) , "," ) ;
105
+ }
104
106
edit. insert (
105
107
tuple_fields_text_range. start ( ) ,
106
108
ast:: make:: tokens:: single_newline ( ) . text ( ) ,
@@ -879,6 +881,29 @@ use crate::{A::Variant, Inner};
879
881
fn f() {
880
882
let a = Variant { field1: Inner };
881
883
}
884
+ "# ,
885
+ ) ;
886
+ }
887
+
888
+ #[ test]
889
+ fn where_clause_with_trailing_comma ( ) {
890
+ check_assist (
891
+ convert_tuple_struct_to_named_struct,
892
+ r#"
893
+ trait Foo {}
894
+
895
+ struct Bar$0<T>(pub T)
896
+ where
897
+ T: Foo,;
898
+ "# ,
899
+ r#"
900
+ trait Foo {}
901
+
902
+ struct Bar<T>
903
+ where
904
+ T: Foo,
905
+ { pub field1: T }
906
+
882
907
"# ,
883
908
) ;
884
909
}
0 commit comments