mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-25 04:23:25 +00:00
format
This commit is contained in:
parent
38e3088a56
commit
a565a42f46
1 changed files with 9 additions and 13 deletions
|
@ -119,27 +119,23 @@ impl ast::AssocItemList {
|
|||
|
||||
/// Remove extra whitespace between last item and closing curly brace.
|
||||
fn fixup_trailing_whitespace(&self) -> Option<ast::AssocItemList> {
|
||||
let first_token_after_items = self
|
||||
.assoc_items()
|
||||
.last()?
|
||||
.syntax()
|
||||
.next_sibling_or_token()?;
|
||||
let last_token_before_curly = self
|
||||
.r_curly_token()?
|
||||
.prev_sibling_or_token()?;
|
||||
let first_token_after_items =
|
||||
self.assoc_items().last()?.syntax().next_sibling_or_token()?;
|
||||
let last_token_before_curly = self.r_curly_token()?.prev_sibling_or_token()?;
|
||||
if last_token_before_curly != first_token_after_items {
|
||||
// there is something more between last item and
|
||||
// right curly than just whitespace - bail out
|
||||
return None;
|
||||
}
|
||||
let whitespace = last_token_before_curly
|
||||
.clone()
|
||||
.into_token()
|
||||
.and_then(ast::Whitespace::cast)?;
|
||||
let whitespace =
|
||||
last_token_before_curly.clone().into_token().and_then(ast::Whitespace::cast)?;
|
||||
let text = whitespace.syntax().text();
|
||||
let newline = text.rfind("\n")?;
|
||||
let keep = tokens::WsBuilder::new(&text[newline..]);
|
||||
Some(self.replace_children(first_token_after_items..=last_token_before_curly, std::iter::once(keep.ws().into())))
|
||||
Some(self.replace_children(
|
||||
first_token_after_items..=last_token_before_curly,
|
||||
std::iter::once(keep.ws().into()),
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue