diff options
Diffstat (limited to 'crates/ra_syntax/src')
-rw-r--r-- | crates/ra_syntax/src/ast/edit.rs | 29 | ||||
-rw-r--r-- | crates/ra_syntax/src/parsing/text_tree_sink.rs | 13 |
2 files changed, 32 insertions, 10 deletions
diff --git a/crates/ra_syntax/src/ast/edit.rs b/crates/ra_syntax/src/ast/edit.rs index 3d023f189..b69cae234 100644 --- a/crates/ra_syntax/src/ast/edit.rs +++ b/crates/ra_syntax/src/ast/edit.rs | |||
@@ -369,22 +369,33 @@ impl ast::MatchArmList { | |||
369 | 369 | ||
370 | #[must_use] | 370 | #[must_use] |
371 | pub fn remove_placeholder(&self) -> ast::MatchArmList { | 371 | pub fn remove_placeholder(&self) -> ast::MatchArmList { |
372 | let placeholder = self.arms().find(|arm| { | 372 | let placeholder = |
373 | if let Some(ast::Pat::PlaceholderPat(_)) = arm.pat() { | 373 | self.arms().find(|arm| matches!(arm.pat(), Some(ast::Pat::PlaceholderPat(_)))); |
374 | return true; | ||
375 | } | ||
376 | false | ||
377 | }); | ||
378 | if let Some(placeholder) = placeholder { | 374 | if let Some(placeholder) = placeholder { |
379 | let s: SyntaxElement = placeholder.syntax().clone().into(); | 375 | self.remove_arm(&placeholder) |
380 | let e = s.clone(); | ||
381 | self.replace_children(s..=e, &mut iter::empty()) | ||
382 | } else { | 376 | } else { |
383 | self.clone() | 377 | self.clone() |
384 | } | 378 | } |
385 | } | 379 | } |
386 | 380 | ||
387 | #[must_use] | 381 | #[must_use] |
382 | fn remove_arm(&self, arm: &ast::MatchArm) -> ast::MatchArmList { | ||
383 | let start = arm.syntax().clone(); | ||
384 | let end = if let Some(comma) = start | ||
385 | .siblings_with_tokens(Direction::Next) | ||
386 | .skip(1) | ||
387 | .skip_while(|it| it.kind().is_trivia()) | ||
388 | .next() | ||
389 | .filter(|it| it.kind() == T![,]) | ||
390 | { | ||
391 | comma | ||
392 | } else { | ||
393 | start.clone().into() | ||
394 | }; | ||
395 | self.replace_children(start.into()..=end, None) | ||
396 | } | ||
397 | |||
398 | #[must_use] | ||
388 | pub fn append_arm(&self, item: ast::MatchArm) -> ast::MatchArmList { | 399 | pub fn append_arm(&self, item: ast::MatchArm) -> ast::MatchArmList { |
389 | let r_curly = match self.syntax().children_with_tokens().find(|it| it.kind() == T!['}']) { | 400 | let r_curly = match self.syntax().children_with_tokens().find(|it| it.kind() == T!['}']) { |
390 | Some(t) => t, | 401 | Some(t) => t, |
diff --git a/crates/ra_syntax/src/parsing/text_tree_sink.rs b/crates/ra_syntax/src/parsing/text_tree_sink.rs index dd202601d..87bb21cd9 100644 --- a/crates/ra_syntax/src/parsing/text_tree_sink.rs +++ b/crates/ra_syntax/src/parsing/text_tree_sink.rs | |||
@@ -149,10 +149,21 @@ fn n_attached_trivias<'a>( | |||
149 | MACRO_CALL | CONST_DEF | TYPE_ALIAS_DEF | STRUCT_DEF | ENUM_DEF | ENUM_VARIANT | FN_DEF | 149 | MACRO_CALL | CONST_DEF | TYPE_ALIAS_DEF | STRUCT_DEF | ENUM_DEF | ENUM_VARIANT | FN_DEF |
150 | | TRAIT_DEF | MODULE | RECORD_FIELD_DEF | STATIC_DEF => { | 150 | | TRAIT_DEF | MODULE | RECORD_FIELD_DEF | STATIC_DEF => { |
151 | let mut res = 0; | 151 | let mut res = 0; |
152 | for (i, (kind, text)) in trivias.enumerate() { | 152 | let mut trivias = trivias.enumerate().peekable(); |
153 | |||
154 | while let Some((i, (kind, text))) = trivias.next() { | ||
153 | match kind { | 155 | match kind { |
154 | WHITESPACE => { | 156 | WHITESPACE => { |
155 | if text.contains("\n\n") { | 157 | if text.contains("\n\n") { |
158 | // we check whether the next token is a doc-comment | ||
159 | // and skip the whitespace in this case | ||
160 | if let Some((peek_kind, peek_text)) = | ||
161 | trivias.peek().map(|(_, pair)| pair) | ||
162 | { | ||
163 | if *peek_kind == COMMENT && peek_text.starts_with("///") { | ||
164 | continue; | ||
165 | } | ||
166 | } | ||
156 | break; | 167 | break; |
157 | } | 168 | } |
158 | } | 169 | } |