Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion crates/ide_db/src/helpers/insert_use.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use syntax::{
ast::{
self,
edit::{AstNodeEdit, IndentLevel},
make, AstNode, PathSegmentKind, VisibilityOwner,
make, AstNode, AttrsOwner, PathSegmentKind, VisibilityOwner,
},
AstToken, InsertPosition, NodeOrToken, SyntaxElement, SyntaxNode, SyntaxToken,
};
Expand Down Expand Up @@ -180,6 +180,15 @@ fn eq_visibility(vis0: Option<ast::Visibility>, vis1: Option<ast::Visibility>) -
}
}

fn eq_attrs(
attrs0: impl Iterator<Item = ast::Attr>,
attrs1: impl Iterator<Item = ast::Attr>,
) -> bool {
let attrs0 = attrs0.map(|attr| attr.to_string());
let attrs1 = attrs1.map(|attr| attr.to_string());
attrs0.eq(attrs1)
}

pub fn try_merge_imports(
lhs: &ast::Use,
rhs: &ast::Use,
Expand All @@ -189,6 +198,10 @@ pub fn try_merge_imports(
if !eq_visibility(lhs.visibility(), rhs.visibility()) {
return None;
}
if !eq_attrs(lhs.attrs(), rhs.attrs()) {
return None;
}

let lhs_tree = lhs.use_tree()?;
let rhs_tree = rhs.use_tree()?;
let merged = try_merge_trees(&lhs_tree, &rhs_tree, merge_behavior)?;
Expand Down
14 changes: 14 additions & 0 deletions crates/ide_db/src/helpers/insert_use/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,20 @@ use std::io;",
)
}

#[test]
fn merge_groups_skip_attributed() {
check_full(
"std::io",
r#"
#[cfg(feature = "gated")] use std::fmt::{Result, Display};
"#,
r#"
#[cfg(feature = "gated")] use std::fmt::{Result, Display};
use std::io;
"#,
)
}

#[test]
#[ignore] // FIXME: Support this
fn split_out_merge() {
Expand Down