aboutsummaryrefslogtreecommitdiff
path: root/crates/syntax
diff options
context:
space:
mode:
Diffstat (limited to 'crates/syntax')
-rw-r--r--crates/syntax/src/ast/edit_in_place.rs54
1 files changed, 44 insertions, 10 deletions
diff --git a/crates/syntax/src/ast/edit_in_place.rs b/crates/syntax/src/ast/edit_in_place.rs
index 06cde591d..1788f2a40 100644
--- a/crates/syntax/src/ast/edit_in_place.rs
+++ b/crates/syntax/src/ast/edit_in_place.rs
@@ -27,7 +27,7 @@ impl GenericParamsOwnerEdit for ast::Fn {
27 } else { 27 } else {
28 Position::last_child_of(self.syntax().clone()) 28 Position::last_child_of(self.syntax().clone())
29 }; 29 };
30 create_where_clause(position) 30 create_where_clause(position, true)
31 } 31 }
32 self.where_clause().unwrap() 32 self.where_clause().unwrap()
33 } 33 }
@@ -36,16 +36,31 @@ impl GenericParamsOwnerEdit for ast::Fn {
36impl GenericParamsOwnerEdit for ast::Impl { 36impl GenericParamsOwnerEdit for ast::Impl {
37 fn get_or_create_where_clause(&self) -> WhereClause { 37 fn get_or_create_where_clause(&self) -> WhereClause {
38 if self.where_clause().is_none() { 38 if self.where_clause().is_none() {
39 let position = if let Some(ty) = self.self_ty() { 39 let position = if let Some(items) = self.assoc_item_list() {
40 Position::after(ty.syntax().clone()) 40 Position::before(items.syntax().clone())
41 } else { 41 } else {
42 Position::last_child_of(self.syntax().clone()) 42 Position::last_child_of(self.syntax().clone())
43 }; 43 };
44 create_where_clause(position) 44 create_where_clause(position, false)
45 } 45 }
46 self.where_clause().unwrap() 46 self.where_clause().unwrap()
47 } 47 }
48} 48}
49
50impl GenericParamsOwnerEdit for ast::Trait {
51 fn get_or_create_where_clause(&self) -> WhereClause {
52 if self.where_clause().is_none() {
53 let position = if let Some(items) = self.assoc_item_list() {
54 Position::before(items.syntax().clone())
55 } else {
56 Position::last_child_of(self.syntax().clone())
57 };
58 create_where_clause(position, false)
59 }
60 self.where_clause().unwrap()
61 }
62}
63
49impl GenericParamsOwnerEdit for ast::Struct { 64impl GenericParamsOwnerEdit for ast::Struct {
50 fn get_or_create_where_clause(&self) -> WhereClause { 65 fn get_or_create_where_clause(&self) -> WhereClause {
51 if self.where_clause().is_none() { 66 if self.where_clause().is_none() {
@@ -62,17 +77,36 @@ impl GenericParamsOwnerEdit for ast::Struct {
62 } else { 77 } else {
63 Position::last_child_of(self.syntax().clone()) 78 Position::last_child_of(self.syntax().clone())
64 }; 79 };
65 create_where_clause(position) 80 create_where_clause(position, true)
81 }
82 self.where_clause().unwrap()
83 }
84}
85
86impl GenericParamsOwnerEdit for ast::Enum {
87 fn get_or_create_where_clause(&self) -> WhereClause {
88 if self.where_clause().is_none() {
89 let position = if let Some(gpl) = self.generic_param_list() {
90 Position::after(gpl.syntax().clone())
91 } else if let Some(name) = self.name() {
92 Position::after(name.syntax().clone())
93 } else {
94 Position::last_child_of(self.syntax().clone())
95 };
96 create_where_clause(position, true)
66 } 97 }
67 self.where_clause().unwrap() 98 self.where_clause().unwrap()
68 } 99 }
69} 100}
70 101
71fn create_where_clause(position: Position) { 102fn create_where_clause(position: Position, after: bool) {
72 let elements = vec![ 103 let mut elements = vec![make::where_clause(empty()).clone_for_update().syntax().clone().into()];
73 make::tokens::single_space().into(), 104 let ws = make::tokens::single_space().into();
74 make::where_clause(empty()).clone_for_update().syntax().clone().into(), 105 if after {
75 ]; 106 elements.insert(0, ws)
107 } else {
108 elements.push(ws)
109 }
76 ted::insert_all(position, elements); 110 ted::insert_all(position, elements);
77} 111}
78 112