diff options
Diffstat (limited to 'crates/ide_db/src')
-rw-r--r-- | crates/ide_db/src/helpers/insert_use.rs | 15 | ||||
-rw-r--r-- | crates/ide_db/src/helpers/insert_use/tests.rs | 14 |
2 files changed, 28 insertions, 1 deletions
diff --git a/crates/ide_db/src/helpers/insert_use.rs b/crates/ide_db/src/helpers/insert_use.rs index 9be36d59b..d6b498be3 100644 --- a/crates/ide_db/src/helpers/insert_use.rs +++ b/crates/ide_db/src/helpers/insert_use.rs | |||
@@ -9,7 +9,7 @@ use syntax::{ | |||
9 | ast::{ | 9 | ast::{ |
10 | self, | 10 | self, |
11 | edit::{AstNodeEdit, IndentLevel}, | 11 | edit::{AstNodeEdit, IndentLevel}, |
12 | make, AstNode, PathSegmentKind, VisibilityOwner, | 12 | make, AstNode, AttrsOwner, PathSegmentKind, VisibilityOwner, |
13 | }, | 13 | }, |
14 | AstToken, InsertPosition, NodeOrToken, SyntaxElement, SyntaxNode, SyntaxToken, | 14 | AstToken, InsertPosition, NodeOrToken, SyntaxElement, SyntaxNode, SyntaxToken, |
15 | }; | 15 | }; |
@@ -180,6 +180,15 @@ fn eq_visibility(vis0: Option<ast::Visibility>, vis1: Option<ast::Visibility>) - | |||
180 | } | 180 | } |
181 | } | 181 | } |
182 | 182 | ||
183 | fn eq_attrs( | ||
184 | attrs0: impl Iterator<Item = ast::Attr>, | ||
185 | attrs1: impl Iterator<Item = ast::Attr>, | ||
186 | ) -> bool { | ||
187 | let attrs0 = attrs0.map(|attr| attr.to_string()); | ||
188 | let attrs1 = attrs1.map(|attr| attr.to_string()); | ||
189 | attrs0.eq(attrs1) | ||
190 | } | ||
191 | |||
183 | pub fn try_merge_imports( | 192 | pub fn try_merge_imports( |
184 | lhs: &ast::Use, | 193 | lhs: &ast::Use, |
185 | rhs: &ast::Use, | 194 | rhs: &ast::Use, |
@@ -189,6 +198,10 @@ pub fn try_merge_imports( | |||
189 | if !eq_visibility(lhs.visibility(), rhs.visibility()) { | 198 | if !eq_visibility(lhs.visibility(), rhs.visibility()) { |
190 | return None; | 199 | return None; |
191 | } | 200 | } |
201 | if !eq_attrs(lhs.attrs(), rhs.attrs()) { | ||
202 | return None; | ||
203 | } | ||
204 | |||
192 | let lhs_tree = lhs.use_tree()?; | 205 | let lhs_tree = lhs.use_tree()?; |
193 | let rhs_tree = rhs.use_tree()?; | 206 | let rhs_tree = rhs.use_tree()?; |
194 | let merged = try_merge_trees(&lhs_tree, &rhs_tree, merge_behavior)?; | 207 | let merged = try_merge_trees(&lhs_tree, &rhs_tree, merge_behavior)?; |
diff --git a/crates/ide_db/src/helpers/insert_use/tests.rs b/crates/ide_db/src/helpers/insert_use/tests.rs index 9e194354e..a603fe87f 100644 --- a/crates/ide_db/src/helpers/insert_use/tests.rs +++ b/crates/ide_db/src/helpers/insert_use/tests.rs | |||
@@ -448,6 +448,20 @@ use std::io;", | |||
448 | } | 448 | } |
449 | 449 | ||
450 | #[test] | 450 | #[test] |
451 | fn merge_groups_skip_attributed() { | ||
452 | check_full( | ||
453 | "std::io", | ||
454 | r#" | ||
455 | #[cfg(feature = "gated")] use std::fmt::{Result, Display}; | ||
456 | "#, | ||
457 | r#" | ||
458 | #[cfg(feature = "gated")] use std::fmt::{Result, Display}; | ||
459 | use std::io; | ||
460 | "#, | ||
461 | ) | ||
462 | } | ||
463 | |||
464 | #[test] | ||
451 | #[ignore] // FIXME: Support this | 465 | #[ignore] // FIXME: Support this |
452 | fn split_out_merge() { | 466 | fn split_out_merge() { |
453 | check_last( | 467 | check_last( |