Skip to content

Commit 0a3ac7a

Browse files
bors[bot]Veykril
andauthored
Merge #9728
9728: fix: Attach comma token to MATCH_ARM instead of MATCH_ARM_LIST r=Veykril a=Veykril bors r+ Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2 parents 956e205 + 82c1e61 commit 0a3ac7a

18 files changed

+299
-313
lines changed

crates/ide/src/join_lines.rs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@ use std::convert::TryFrom;
33
use ide_assists::utils::extract_trivial_expression;
44
use itertools::Itertools;
55
use syntax::{
6-
algo::non_trivia_sibling,
76
ast::{self, AstNode, AstToken, IsString},
8-
Direction, NodeOrToken, SourceFile, SyntaxElement,
7+
NodeOrToken, SourceFile, SyntaxElement,
98
SyntaxKind::{self, USE_TREE, WHITESPACE},
10-
SyntaxNode, SyntaxToken, TextRange, TextSize, T,
9+
SyntaxToken, TextRange, TextSize, T,
1110
};
1211

1312
use text_edit::{TextEdit, TextEditBuilder};
@@ -204,13 +203,6 @@ fn remove_newline(
204203
edit.replace(token.text_range(), compute_ws(prev.kind(), next.kind()).to_string());
205204
}
206205

207-
fn has_comma_after(node: &SyntaxNode) -> bool {
208-
match non_trivia_sibling(node.clone().into(), Direction::Next) {
209-
Some(n) => n.kind() == T![,],
210-
_ => false,
211-
}
212-
}
213-
214206
fn join_single_expr_block(edit: &mut TextEditBuilder, token: &SyntaxToken) -> Option<()> {
215207
let block_expr = ast::BlockExpr::cast(token.parent()?)?;
216208
if !block_expr.is_standalone() {
@@ -223,7 +215,7 @@ fn join_single_expr_block(edit: &mut TextEditBuilder, token: &SyntaxToken) -> Op
223215

224216
// Match block needs to have a comma after the block
225217
if let Some(match_arm) = block_expr.syntax().parent().and_then(ast::MatchArm::cast) {
226-
if !has_comma_after(match_arm.syntax()) {
218+
if match_arm.comma_token().is_none() {
227219
buf.push(',');
228220
}
229221
}

0 commit comments

Comments
 (0)