diff options
author | Kirill Bulatov <[email protected]> | 2021-03-01 11:55:47 +0000 |
---|---|---|
committer | Kirill Bulatov <[email protected]> | 2021-03-08 21:59:20 +0000 |
commit | e214c3a6bd7f74b42d38663b959fc4f0d113c90c (patch) | |
tree | 7b104366b08ab039ca999a4b2164907f577d105e /crates/ide_db | |
parent | e74c55bb4adcad001b0f7373ebff795fc2aaeb1b (diff) |
Simplify
Diffstat (limited to 'crates/ide_db')
-rw-r--r-- | crates/ide_db/src/helpers/import_assets.rs | 18 |
1 files changed, 5 insertions, 13 deletions
diff --git a/crates/ide_db/src/helpers/import_assets.rs b/crates/ide_db/src/helpers/import_assets.rs index 2909ecd45..4e352d546 100644 --- a/crates/ide_db/src/helpers/import_assets.rs +++ b/crates/ide_db/src/helpers/import_assets.rs | |||
@@ -130,7 +130,6 @@ impl<'a> ImportAssets<'a> { | |||
130 | 130 | ||
131 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 131 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
132 | pub struct LocatedImport { | 132 | pub struct LocatedImport { |
133 | // TODO kb extract both into a separate struct + add another field: `assoc_item_name: Optional<String|Name>` | ||
134 | import_path: ModPath, | 133 | import_path: ModPath, |
135 | item_to_import: ItemInNs, | 134 | item_to_import: ItemInNs, |
136 | data_to_display: Option<(ModPath, ItemInNs)>, | 135 | data_to_display: Option<(ModPath, ItemInNs)>, |
@@ -146,7 +145,7 @@ impl LocatedImport { | |||
146 | } | 145 | } |
147 | 146 | ||
148 | pub fn display_path(&self) -> &ModPath { | 147 | pub fn display_path(&self) -> &ModPath { |
149 | self.data_to_display.as_ref().map(|(mod_pathh, _)| mod_pathh).unwrap_or(&self.import_path) | 148 | self.data_to_display.as_ref().map(|(mod_path, _)| mod_path).unwrap_or(&self.import_path) |
150 | } | 149 | } |
151 | 150 | ||
152 | pub fn import_path(&self) -> &ModPath { | 151 | pub fn import_path(&self) -> &ModPath { |
@@ -227,14 +226,7 @@ impl<'a> ImportAssets<'a> { | |||
227 | self.applicable_defs(sema.db, prefixed, defs_for_candidate_name) | 226 | self.applicable_defs(sema.db, prefixed, defs_for_candidate_name) |
228 | .into_iter() | 227 | .into_iter() |
229 | .filter(|import| import.import_path().len() > 1) | 228 | .filter(|import| import.import_path().len() > 1) |
230 | .filter(|import| { | 229 | .filter(|import| !scope_definitions.contains(&ScopeDef::from(import.item_to_import()))) |
231 | let proposed_def = match import.item_to_import() { | ||
232 | ItemInNs::Types(id) => ScopeDef::ModuleDef(id.into()), | ||
233 | ItemInNs::Values(id) => ScopeDef::ModuleDef(id.into()), | ||
234 | ItemInNs::Macros(id) => ScopeDef::MacroDef(id.into()), | ||
235 | }; | ||
236 | !scope_definitions.contains(&proposed_def) | ||
237 | }) | ||
238 | .collect() | 230 | .collect() |
239 | } | 231 | } |
240 | 232 | ||
@@ -314,8 +306,8 @@ fn import_for_item( | |||
314 | unresolved_qualifier: &str, | 306 | unresolved_qualifier: &str, |
315 | original_item: ItemInNs, | 307 | original_item: ItemInNs, |
316 | ) -> Option<LocatedImport> { | 308 | ) -> Option<LocatedImport> { |
317 | let (item_candidate, trait_to_import) = match original_item { | 309 | let (item_candidate, trait_to_import) = match original_item.as_module_def_id() { |
318 | ItemInNs::Types(module_def_id) | ItemInNs::Values(module_def_id) => { | 310 | Some(module_def_id) => { |
319 | match ModuleDef::from(module_def_id).as_assoc_item(db).map(|assoc| assoc.container(db)) | 311 | match ModuleDef::from(module_def_id).as_assoc_item(db).map(|assoc| assoc.container(db)) |
320 | { | 312 | { |
321 | Some(AssocItemContainer::Trait(trait_)) => { | 313 | Some(AssocItemContainer::Trait(trait_)) => { |
@@ -328,7 +320,7 @@ fn import_for_item( | |||
328 | None => (original_item, None), | 320 | None => (original_item, None), |
329 | } | 321 | } |
330 | } | 322 | } |
331 | ItemInNs::Macros(_) => (original_item, None), | 323 | None => (original_item, None), |
332 | }; | 324 | }; |
333 | let import_path_candidate = mod_path(item_candidate)?; | 325 | let import_path_candidate = mod_path(item_candidate)?; |
334 | 326 | ||