Skip to content

Commit ddb9cc4

Browse files
committed
Tidy up insertion position logic
1 parent b8b271d commit ddb9cc4

File tree

1 file changed

+6
-20
lines changed

1 file changed

+6
-20
lines changed

crates/ra_syntax/src/ast/edit.rs

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -390,26 +390,12 @@ impl ast::MatchArmList {
390390
Some(t) => t,
391391
None => return self.clone(),
392392
};
393-
let mut sib = r_curly.prev_sibling_or_token();
394-
while let Some(s) = sib.clone() {
395-
if let Some(tok) = s.as_token() {
396-
if tok.kind() != WHITESPACE {
397-
break;
398-
}
399-
sib = s.prev_sibling_or_token();
400-
} else {
401-
break;
402-
}
403-
}
404-
let indent = " ".to_string() + &leading_indent(self.syntax()).unwrap_or_default();
405-
let sib = match sib {
406-
Some(s) => s,
407-
None => return self.clone(),
408-
};
409-
let position = InsertPosition::After(sib.into());
410-
let ws = tokens::WsBuilder::new(&format!("\n{}", indent));
411-
let to_insert: ArrayVec<[SyntaxElement; 2]> =
412-
[ws.ws().into(), item.syntax().clone().into()].into();
393+
let position = InsertPosition::Before(r_curly.into());
394+
let arm_ws = tokens::WsBuilder::new(" ");
395+
let match_indent = &leading_indent(self.syntax()).unwrap_or_default();
396+
let match_ws = tokens::WsBuilder::new(&format!("\n{}", match_indent));
397+
let to_insert: ArrayVec<[SyntaxElement; 3]> =
398+
[arm_ws.ws().into(), item.syntax().clone().into(), match_ws.ws().into()].into();
413399
self.insert_children(position, to_insert)
414400
}
415401
}

0 commit comments

Comments
 (0)