mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 21:05:02 +00:00
Fix edge case for ImportGranularity guessing
This commit is contained in:
parent
590472607c
commit
31aad2528f
3 changed files with 30 additions and 8 deletions
|
@ -120,15 +120,19 @@ impl ImportScope {
|
|||
if eq_visibility(prev_vis, curr_vis.clone()) && eq_attrs(prev_attrs, curr_attrs.clone())
|
||||
{
|
||||
if let Some((prev_path, curr_path)) = prev.path().zip(curr.path()) {
|
||||
if let Some(_) = common_prefix(&prev_path, &curr_path) {
|
||||
if let Some((prev_prefix, _)) = common_prefix(&prev_path, &curr_path) {
|
||||
if prev.use_tree_list().is_none() && curr.use_tree_list().is_none() {
|
||||
// Same prefix but no use tree lists so this has to be of item style.
|
||||
break ImportGranularityGuess::Item; // this overwrites CrateOrModule, technically the file doesn't adhere to anything here.
|
||||
} else {
|
||||
// Same prefix with item tree lists, has to be module style as it
|
||||
// can't be crate style since the trees wouldn't share a prefix then.
|
||||
break ImportGranularityGuess::Module;
|
||||
let prefix_c = prev_prefix.qualifiers().count();
|
||||
let curr_c = curr_path.qualifiers().count() - prefix_c;
|
||||
let prev_c = prev_path.qualifiers().count() - prefix_c;
|
||||
if curr_c <= 1 || prev_c <= 1 {
|
||||
// Same prefix but no use tree lists so this has to be of item style.
|
||||
break ImportGranularityGuess::Item; // this overwrites CrateOrModule, technically the file doesn't adhere to anything here.
|
||||
}
|
||||
}
|
||||
// Same prefix with item tree lists, has to be module style as it
|
||||
// can't be crate style since the trees wouldn't share a prefix then.
|
||||
break ImportGranularityGuess::Module;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue