Tidy up insertion position logic
This commit is contained in:
@@ -390,26 +390,12 @@ impl ast::MatchArmList {
|
|||||||
Some(t) => t,
|
Some(t) => t,
|
||||||
None => return self.clone(),
|
None => return self.clone(),
|
||||||
};
|
};
|
||||||
let mut sib = r_curly.prev_sibling_or_token();
|
let position = InsertPosition::Before(r_curly.into());
|
||||||
while let Some(s) = sib.clone() {
|
let arm_ws = tokens::WsBuilder::new(" ");
|
||||||
if let Some(tok) = s.as_token() {
|
let match_indent = &leading_indent(self.syntax()).unwrap_or_default();
|
||||||
if tok.kind() != WHITESPACE {
|
let match_ws = tokens::WsBuilder::new(&format!("\n{}", match_indent));
|
||||||
break;
|
let to_insert: ArrayVec<[SyntaxElement; 3]> =
|
||||||
}
|
[arm_ws.ws().into(), item.syntax().clone().into(), match_ws.ws().into()].into();
|
||||||
sib = s.prev_sibling_or_token();
|
|
||||||
} else {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
let indent = " ".to_string() + &leading_indent(self.syntax()).unwrap_or_default();
|
|
||||||
let sib = match sib {
|
|
||||||
Some(s) => s,
|
|
||||||
None => return self.clone(),
|
|
||||||
};
|
|
||||||
let position = InsertPosition::After(sib.into());
|
|
||||||
let ws = tokens::WsBuilder::new(&format!("\n{}", indent));
|
|
||||||
let to_insert: ArrayVec<[SyntaxElement; 2]> =
|
|
||||||
[ws.ws().into(), item.syntax().clone().into()].into();
|
|
||||||
self.insert_children(position, to_insert)
|
self.insert_children(position, to_insert)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user