Skip to content

Commit ed0eedb

Browse files
committed
Fix PR
1 parent 2e279ca commit ed0eedb

File tree

1 file changed

+8
-14
lines changed

1 file changed

+8
-14
lines changed

crates/ra_assists/src/handlers/merge_imports.rs

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
use std::iter::successors;
22

33
use ra_syntax::{
4-
algo::{neighbor, SyntaxRewriter},
4+
algo::{neighbor, skip_trivia_token, SyntaxRewriter},
55
ast::{self, edit::AstNodeEdit, make},
6-
AstNode, Direction, InsertPosition, NodeOrToken, SyntaxElement, T,
6+
AstNode, Direction, InsertPosition, SyntaxElement, T,
77
};
88

99
use crate::{Assist, AssistCtx, AssistId};
@@ -72,18 +72,12 @@ fn try_merge_trees(old: &ast::UseTree, new: &ast::UseTree) -> Option<ast::UseTre
7272
let lhs = old.split_prefix(&lhs_prefix);
7373
let rhs = new.split_prefix(&rhs_prefix);
7474

75-
let mut should_insert_comma = true;
76-
77-
lhs.syntax()
78-
.last_child()
79-
.and_then(|child| child.children().last())
80-
.and_then(|last| last.next_sibling_or_token())
81-
.map(|next_sibling| {
82-
// FIXME: there's probably a better way to check if it's a COMMA
83-
if let NodeOrToken::Token(maybe_comma) = next_sibling {
84-
should_insert_comma = maybe_comma.to_string() != ",";
85-
}
86-
});
75+
let should_insert_comma = lhs
76+
.use_tree_list()?
77+
.r_curly_token()
78+
.and_then(|it| skip_trivia_token(it.prev_token()?, Direction::Prev))
79+
.map(|it| it.kind() != T![,])
80+
.unwrap_or(true);
8781

8882
let mut to_insert: Vec<SyntaxElement> = Vec::new();
8983
if should_insert_comma {

0 commit comments

Comments
 (0)