aboutsummaryrefslogtreecommitdiff
path: root/crates/ide_db
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ide_db')
-rw-r--r--crates/ide_db/src/helpers/insert_use.rs14
-rw-r--r--crates/ide_db/src/helpers/insert_use/tests.rs12
-rw-r--r--crates/ide_db/src/helpers/merge_imports.rs2
3 files changed, 21 insertions, 7 deletions
diff --git a/crates/ide_db/src/helpers/insert_use.rs b/crates/ide_db/src/helpers/insert_use.rs
index e7ae69302..aa61c5bcb 100644
--- a/crates/ide_db/src/helpers/insert_use.rs
+++ b/crates/ide_db/src/helpers/insert_use.rs
@@ -4,13 +4,13 @@ use std::cmp::Ordering;
4use hir::Semantics; 4use hir::Semantics;
5use syntax::{ 5use syntax::{
6 algo, 6 algo,
7 ast::{self, make, AstNode, ModuleItemOwner, PathSegmentKind, VisibilityOwner}, 7 ast::{self, make, AstNode, AttrsOwner, ModuleItemOwner, PathSegmentKind, VisibilityOwner},
8 ted, AstToken, Direction, NodeOrToken, SyntaxNode, SyntaxToken, 8 ted, AstToken, Direction, NodeOrToken, SyntaxNode, SyntaxToken,
9}; 9};
10 10
11use crate::{ 11use crate::{
12 helpers::merge_imports::{ 12 helpers::merge_imports::{
13 common_prefix, eq_visibility, try_merge_imports, use_tree_path_cmp, MergeBehavior, 13 common_prefix, eq_attrs, eq_visibility, try_merge_imports, use_tree_path_cmp, MergeBehavior,
14 }, 14 },
15 RootDatabase, 15 RootDatabase,
16}; 16};
@@ -88,7 +88,7 @@ impl ImportScope {
88 let use_stmt = |item| match item { 88 let use_stmt = |item| match item {
89 ast::Item::Use(use_) => { 89 ast::Item::Use(use_) => {
90 let use_tree = use_.use_tree()?; 90 let use_tree = use_.use_tree()?;
91 Some((use_tree, use_.visibility())) 91 Some((use_tree, use_.visibility(), use_.attrs()))
92 } 92 }
93 _ => None, 93 _ => None,
94 }; 94 };
@@ -98,7 +98,7 @@ impl ImportScope {
98 } 98 }
99 .filter_map(use_stmt); 99 .filter_map(use_stmt);
100 let mut res = ImportGranularityGuess::Unknown; 100 let mut res = ImportGranularityGuess::Unknown;
101 let (mut prev, mut prev_vis) = match use_stmts.next() { 101 let (mut prev, mut prev_vis, mut prev_attrs) = match use_stmts.next() {
102 Some(it) => it, 102 Some(it) => it,
103 None => return res, 103 None => return res,
104 }; 104 };
@@ -113,11 +113,12 @@ impl ImportScope {
113 } 113 }
114 } 114 }
115 115
116 let (curr, curr_vis) = match use_stmts.next() { 116 let (curr, curr_vis, curr_attrs) = match use_stmts.next() {
117 Some(it) => it, 117 Some(it) => it,
118 None => break res, 118 None => break res,
119 }; 119 };
120 if eq_visibility(prev_vis, curr_vis.clone()) { 120 if eq_visibility(prev_vis, curr_vis.clone()) && eq_attrs(prev_attrs, curr_attrs.clone())
121 {
121 if let Some((prev_path, curr_path)) = prev.path().zip(curr.path()) { 122 if let Some((prev_path, curr_path)) = prev.path().zip(curr.path()) {
122 if let Some(_) = common_prefix(&prev_path, &curr_path) { 123 if let Some(_) = common_prefix(&prev_path, &curr_path) {
123 if prev.use_tree_list().is_none() && curr.use_tree_list().is_none() { 124 if prev.use_tree_list().is_none() && curr.use_tree_list().is_none() {
@@ -133,6 +134,7 @@ impl ImportScope {
133 } 134 }
134 prev = curr; 135 prev = curr;
135 prev_vis = curr_vis; 136 prev_vis = curr_vis;
137 prev_attrs = curr_attrs;
136 } 138 }
137 } 139 }
138} 140}
diff --git a/crates/ide_db/src/helpers/insert_use/tests.rs b/crates/ide_db/src/helpers/insert_use/tests.rs
index f795bbf00..78a2a87b3 100644
--- a/crates/ide_db/src/helpers/insert_use/tests.rs
+++ b/crates/ide_db/src/helpers/insert_use/tests.rs
@@ -718,6 +718,18 @@ pub use foo::bar::qux;
718} 718}
719 719
720#[test] 720#[test]
721fn guess_skips_differing_attrs() {
722 check_guess(
723 r"
724pub use foo::bar::baz;
725#[doc(hidden)]
726pub use foo::bar::qux;
727",
728 ImportGranularityGuess::Unknown,
729 );
730}
731
732#[test]
721fn guess_grouping_matters() { 733fn guess_grouping_matters() {
722 check_guess( 734 check_guess(
723 r" 735 r"
diff --git a/crates/ide_db/src/helpers/merge_imports.rs b/crates/ide_db/src/helpers/merge_imports.rs
index 546f2d0c4..697e8bcff 100644
--- a/crates/ide_db/src/helpers/merge_imports.rs
+++ b/crates/ide_db/src/helpers/merge_imports.rs
@@ -299,7 +299,7 @@ pub fn eq_visibility(vis0: Option<ast::Visibility>, vis1: Option<ast::Visibility
299 } 299 }
300} 300}
301 301
302fn eq_attrs( 302pub fn eq_attrs(
303 attrs0: impl Iterator<Item = ast::Attr>, 303 attrs0: impl Iterator<Item = ast::Attr>,
304 attrs1: impl Iterator<Item = ast::Attr>, 304 attrs1: impl Iterator<Item = ast::Attr>,
305) -> bool { 305) -> bool {