aboutsummaryrefslogtreecommitdiff
path: root/crates/syntax/src/ast
diff options
context:
space:
mode:
Diffstat (limited to 'crates/syntax/src/ast')
-rw-r--r--crates/syntax/src/ast/edit_in_place.rs32
1 files changed, 11 insertions, 21 deletions
diff --git a/crates/syntax/src/ast/edit_in_place.rs b/crates/syntax/src/ast/edit_in_place.rs
index 1788f2a40..7adfe5e16 100644
--- a/crates/syntax/src/ast/edit_in_place.rs
+++ b/crates/syntax/src/ast/edit_in_place.rs
@@ -8,7 +8,7 @@ use parser::T;
8use crate::{ 8use crate::{
9 ast, 9 ast,
10 ted::{self, Position}, 10 ted::{self, Position},
11 AstNode, Direction, SyntaxKind, 11 AstNode, Direction, SyntaxElement,
12}; 12};
13 13
14use super::NameOwner; 14use super::NameOwner;
@@ -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, true) 30 create_where_clause(position)
31 } 31 }
32 self.where_clause().unwrap() 32 self.where_clause().unwrap()
33 } 33 }
@@ -41,7 +41,7 @@ impl GenericParamsOwnerEdit for ast::Impl {
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, false) 44 create_where_clause(position)
45 } 45 }
46 self.where_clause().unwrap() 46 self.where_clause().unwrap()
47 } 47 }
@@ -55,7 +55,7 @@ impl GenericParamsOwnerEdit for ast::Trait {
55 } else { 55 } else {
56 Position::last_child_of(self.syntax().clone()) 56 Position::last_child_of(self.syntax().clone())
57 }; 57 };
58 create_where_clause(position, false) 58 create_where_clause(position)
59 } 59 }
60 self.where_clause().unwrap() 60 self.where_clause().unwrap()
61 } 61 }
@@ -77,7 +77,7 @@ impl GenericParamsOwnerEdit for ast::Struct {
77 } else { 77 } else {
78 Position::last_child_of(self.syntax().clone()) 78 Position::last_child_of(self.syntax().clone())
79 }; 79 };
80 create_where_clause(position, true) 80 create_where_clause(position)
81 } 81 }
82 self.where_clause().unwrap() 82 self.where_clause().unwrap()
83 } 83 }
@@ -93,21 +93,16 @@ impl GenericParamsOwnerEdit for ast::Enum {
93 } else { 93 } else {
94 Position::last_child_of(self.syntax().clone()) 94 Position::last_child_of(self.syntax().clone())
95 }; 95 };
96 create_where_clause(position, true) 96 create_where_clause(position)
97 } 97 }
98 self.where_clause().unwrap() 98 self.where_clause().unwrap()
99 } 99 }
100} 100}
101 101
102fn create_where_clause(position: Position, after: bool) { 102fn create_where_clause(position: Position) {
103 let mut elements = vec![make::where_clause(empty()).clone_for_update().syntax().clone().into()]; 103 let where_clause: SyntaxElement =
104 let ws = make::tokens::single_space().into(); 104 make::where_clause(empty()).clone_for_update().syntax().clone().into();
105 if after { 105 ted::insert_ws(position, where_clause);
106 elements.insert(0, ws)
107 } else {
108 elements.push(ws)
109 }
110 ted::insert_all(position, elements);
111} 106}
112 107
113impl ast::WhereClause { 108impl ast::WhereClause {
@@ -117,12 +112,7 @@ impl ast::WhereClause {
117 ted::append_child(self.syntax().clone(), make::token(T![,])); 112 ted::append_child(self.syntax().clone(), make::token(T![,]));
118 } 113 }
119 } 114 }
120 if self.syntax().children_with_tokens().last().map(|it| it.kind()) 115 ted::append_child_ws(self.syntax().clone(), predicate.syntax().clone())
121 != Some(SyntaxKind::WHITESPACE)
122 {
123 ted::append_child(self.syntax().clone(), make::tokens::single_space());
124 }
125 ted::append_child(self.syntax().clone(), predicate.syntax().clone())
126 } 116 }
127} 117}
128 118