fn create_where_clause(position: Position) {
let where_clause: SyntaxElement =
make::where_clause(empty()).clone_for_update().syntax().clone().into();
- ted::insert_ws(position, where_clause);
+ ted::insert(position, where_clause);
}
impl ast::WhereClause {
pub fn add_predicate(&self, predicate: ast::WherePred) {
if let Some(pred) = self.predicates().last() {
if !pred.syntax().siblings_with_tokens(Direction::Next).any(|it| it.kind() == T![,]) {
- ted::append_child(self.syntax().clone(), make::token(T![,]));
+ ted::append_child_raw(self.syntax().clone(), make::token(T![,]));
}
}
- ted::append_child_ws(self.syntax().clone(), predicate.syntax().clone())
+ ted::append_child(self.syntax().clone(), predicate.syntax().clone())
}
}
-//! Primitive tree editor, ed for trees
+//! Primitive tree editor, ed for trees.
+//!
+//! The `_raw`-suffixed functions insert elements as is, unsuffixed versions fix
+//! up elements around the edges.
use std::ops::RangeInclusive;
use parser::T;
}
}
-pub fn insert_ws(position: Position, elem: impl Into<SyntaxElement>) {
- insert_all_ws(position, vec![elem.into()])
-}
pub fn insert(position: Position, elem: impl Into<SyntaxElement>) {
insert_all(position, vec![elem.into()])
}
-pub fn insert_all_ws(position: Position, mut elements: Vec<SyntaxElement>) {
+pub fn insert_raw(position: Position, elem: impl Into<SyntaxElement>) {
+ insert_all_raw(position, vec![elem.into()])
+}
+pub fn insert_all(position: Position, mut elements: Vec<SyntaxElement>) {
if let Some(first) = elements.first() {
if let Some(ws) = ws_before(&position, first) {
elements.insert(0, ws.into())
elements.push(ws.into())
}
}
- insert_all(position, elements)
+ insert_all_raw(position, elements)
}
-pub fn insert_all(position: Position, elements: Vec<SyntaxElement>) {
+pub fn insert_all_raw(position: Position, elements: Vec<SyntaxElement>) {
let (parent, index) = match position.repr {
PositionRepr::FirstChild(parent) => (parent, 0),
PositionRepr::After(child) => (child.parent().unwrap(), child.index() + 1),
parent.splice_children(start..end + 1, new)
}
-pub fn append_child_ws(node: impl Into<SyntaxNode>, child: impl Into<SyntaxElement>) {
- let position = Position::last_child_of(node);
- insert_ws(position, child)
-}
pub fn append_child(node: impl Into<SyntaxNode>, child: impl Into<SyntaxElement>) {
let position = Position::last_child_of(node);
insert(position, child)
}
+pub fn append_child_raw(node: impl Into<SyntaxNode>, child: impl Into<SyntaxElement>) {
+ let position = Position::last_child_of(node);
+ insert_raw(position, child)
+}
fn ws_before(position: &Position, new: &SyntaxElement) -> Option<SyntaxToken> {
let prev = match &position.repr {