aboutsummaryrefslogtreecommitdiff
path: root/crates/ide_db
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2021-06-08 21:18:54 +0100
committerGitHub <[email protected]>2021-06-08 21:18:54 +0100
commitf1a40f9093798efda0eb9b09a8dcb3d26410faf4 (patch)
tree4a537c51d629873a8c83950377ea3a44baf3da7c /crates/ide_db
parentb6199de706868dcbf57d9821829381609212d851 (diff)
parent31aad2528f53349e9a0601c756d3c9f86ca9154c (diff)
Merge #9187
9187: fix: Fix edge case for ImportGranularity guessing r=Veykril a=Veykril bors r+ Co-authored-by: Lukas Wirth <[email protected]>
Diffstat (limited to 'crates/ide_db')
-rw-r--r--crates/ide_db/src/helpers/insert_use.rs18
-rw-r--r--crates/ide_db/src/helpers/insert_use/tests.rs15
2 files changed, 26 insertions, 7 deletions
diff --git a/crates/ide_db/src/helpers/insert_use.rs b/crates/ide_db/src/helpers/insert_use.rs
index aa61c5bcb..10bbafe77 100644
--- a/crates/ide_db/src/helpers/insert_use.rs
+++ b/crates/ide_db/src/helpers/insert_use.rs
@@ -120,15 +120,19 @@ impl ImportScope {
120 if eq_visibility(prev_vis, curr_vis.clone()) && eq_attrs(prev_attrs, curr_attrs.clone()) 120 if eq_visibility(prev_vis, curr_vis.clone()) && eq_attrs(prev_attrs, curr_attrs.clone())
121 { 121 {
122 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()) {
123 if let Some(_) = common_prefix(&prev_path, &curr_path) { 123 if let Some((prev_prefix, _)) = common_prefix(&prev_path, &curr_path) {
124 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() {
125 // Same prefix but no use tree lists so this has to be of item style. 125 let prefix_c = prev_prefix.qualifiers().count();
126 break ImportGranularityGuess::Item; // this overwrites CrateOrModule, technically the file doesn't adhere to anything here. 126 let curr_c = curr_path.qualifiers().count() - prefix_c;
127 } else { 127 let prev_c = prev_path.qualifiers().count() - prefix_c;
128 // Same prefix with item tree lists, has to be module style as it 128 if curr_c <= 1 || prev_c <= 1 {
129 // can't be crate style since the trees wouldn't share a prefix then. 129 // Same prefix but no use tree lists so this has to be of item style.
130 break ImportGranularityGuess::Module; 130 break ImportGranularityGuess::Item; // this overwrites CrateOrModule, technically the file doesn't adhere to anything here.
131 }
131 } 132 }
133 // Same prefix with item tree lists, has to be module style as it
134 // can't be crate style since the trees wouldn't share a prefix then.
135 break ImportGranularityGuess::Module;
132 } 136 }
133 } 137 }
134 } 138 }
diff --git a/crates/ide_db/src/helpers/insert_use/tests.rs b/crates/ide_db/src/helpers/insert_use/tests.rs
index 78a2a87b3..70b11bf81 100644
--- a/crates/ide_db/src/helpers/insert_use/tests.rs
+++ b/crates/ide_db/src/helpers/insert_use/tests.rs
@@ -663,6 +663,13 @@ use foo::bar::qux;
663", 663",
664 ImportGranularityGuess::Item, 664 ImportGranularityGuess::Item,
665 ); 665 );
666 check_guess(
667 r"
668use foo::bar::Bar;
669use foo::baz;
670",
671 ImportGranularityGuess::Item,
672 );
666} 673}
667 674
668#[test] 675#[test]
@@ -682,6 +689,14 @@ use foo::{baz::{qux, quux}, bar};
682", 689",
683 ImportGranularityGuess::Module, 690 ImportGranularityGuess::Module,
684 ); 691 );
692 check_guess(
693 r"
694use foo::bar::Bar;
695use foo::baz::Baz;
696use foo::{Foo, Qux};
697",
698 ImportGranularityGuess::Module,
699 );
685} 700}
686 701
687#[test] 702#[test]