diff options
Diffstat (limited to 'crates/syntax')
-rw-r--r-- | crates/syntax/src/ast/edit.rs | 22 |
1 files changed, 9 insertions, 13 deletions
diff --git a/crates/syntax/src/ast/edit.rs b/crates/syntax/src/ast/edit.rs index b295b5bc6..060b20966 100644 --- a/crates/syntax/src/ast/edit.rs +++ b/crates/syntax/src/ast/edit.rs | |||
@@ -119,27 +119,23 @@ impl ast::AssocItemList { | |||
119 | 119 | ||
120 | /// Remove extra whitespace between last item and closing curly brace. | 120 | /// Remove extra whitespace between last item and closing curly brace. |
121 | fn fixup_trailing_whitespace(&self) -> Option<ast::AssocItemList> { | 121 | fn fixup_trailing_whitespace(&self) -> Option<ast::AssocItemList> { |
122 | let first_token_after_items = self | 122 | let first_token_after_items = |
123 | .assoc_items() | 123 | self.assoc_items().last()?.syntax().next_sibling_or_token()?; |
124 | .last()? | 124 | let last_token_before_curly = self.r_curly_token()?.prev_sibling_or_token()?; |
125 | .syntax() | ||
126 | .next_sibling_or_token()?; | ||
127 | let last_token_before_curly = self | ||
128 | .r_curly_token()? | ||
129 | .prev_sibling_or_token()?; | ||
130 | if last_token_before_curly != first_token_after_items { | 125 | if last_token_before_curly != first_token_after_items { |
131 | // there is something more between last item and | 126 | // there is something more between last item and |
132 | // right curly than just whitespace - bail out | 127 | // right curly than just whitespace - bail out |
133 | return None; | 128 | return None; |
134 | } | 129 | } |
135 | let whitespace = last_token_before_curly | 130 | let whitespace = |
136 | .clone() | 131 | last_token_before_curly.clone().into_token().and_then(ast::Whitespace::cast)?; |
137 | .into_token() | ||
138 | .and_then(ast::Whitespace::cast)?; | ||
139 | let text = whitespace.syntax().text(); | 132 | let text = whitespace.syntax().text(); |
140 | let newline = text.rfind("\n")?; | 133 | let newline = text.rfind("\n")?; |
141 | let keep = tokens::WsBuilder::new(&text[newline..]); | 134 | let keep = tokens::WsBuilder::new(&text[newline..]); |
142 | Some(self.replace_children(first_token_after_items..=last_token_before_curly, std::iter::once(keep.ws().into()))) | 135 | Some(self.replace_children( |
136 | first_token_after_items..=last_token_before_curly, | ||
137 | std::iter::once(keep.ws().into()), | ||
138 | )) | ||
143 | } | 139 | } |
144 | } | 140 | } |
145 | 141 | ||