diff --git a/crates/ra_assists/src/handlers/merge_imports.rs b/crates/ra_assists/src/handlers/merge_imports.rs index 0958f52f1f7b..ef0ce058617a 100644 --- a/crates/ra_assists/src/handlers/merge_imports.rs +++ b/crates/ra_assists/src/handlers/merge_imports.rs @@ -1,7 +1,7 @@ use std::iter::successors; use ra_syntax::{ - algo::{neighbor, SyntaxRewriter}, + algo::{neighbor, skip_trivia_token, SyntaxRewriter}, ast::{self, edit::AstNodeEdit, make}, AstNode, Direction, InsertPosition, SyntaxElement, T, }; @@ -72,9 +72,18 @@ fn try_merge_trees(old: &ast::UseTree, new: &ast::UseTree) -> Option = Vec::new(); - to_insert.push(make::token(T![,]).into()); - to_insert.push(make::tokens::single_space().into()); + if should_insert_comma { + to_insert.push(make::token(T![,]).into()); + to_insert.push(make::tokens::single_space().into()); + } to_insert.extend( rhs.use_tree_list()? .syntax() @@ -247,4 +256,22 @@ use { ", ); } + + #[test] + fn test_double_comma() { + check_assist( + merge_imports, + r" +use foo::bar::baz; +use foo::<|>{ + FooBar, +}; +", + r" +use foo::{<|> + FooBar, +bar::baz}; +", + ) + } }