diff options
-rw-r--r-- | crates/ra_assists/src/assists/auto_import.rs | 24 | ||||
-rw-r--r-- | crates/ra_hir/src/code_model.rs | 17 |
2 files changed, 35 insertions, 6 deletions
diff --git a/crates/ra_assists/src/assists/auto_import.rs b/crates/ra_assists/src/assists/auto_import.rs index 9e874aebb..2629f00e6 100644 --- a/crates/ra_assists/src/assists/auto_import.rs +++ b/crates/ra_assists/src/assists/auto_import.rs | |||
@@ -232,4 +232,28 @@ mod tests { | |||
232 | }", | 232 | }", |
233 | ); | 233 | ); |
234 | } | 234 | } |
235 | |||
236 | #[test] | ||
237 | fn function_import() { | ||
238 | check_assist_with_imports_locator( | ||
239 | auto_import, | ||
240 | TestImportsLocator::new, | ||
241 | r" | ||
242 | test_function<|> | ||
243 | |||
244 | pub mod PubMod { | ||
245 | pub fn test_function() {}; | ||
246 | } | ||
247 | ", | ||
248 | r" | ||
249 | use PubMod::test_function; | ||
250 | |||
251 | test_function<|> | ||
252 | |||
253 | pub mod PubMod { | ||
254 | pub fn test_function() {}; | ||
255 | } | ||
256 | ", | ||
257 | ); | ||
258 | } | ||
235 | } | 259 | } |
diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs index 500b34c17..eaacf8c9e 100644 --- a/crates/ra_hir/src/code_model.rs +++ b/crates/ra_hir/src/code_model.rs | |||
@@ -119,7 +119,7 @@ impl_froms!( | |||
119 | BuiltinType | 119 | BuiltinType |
120 | ); | 120 | ); |
121 | 121 | ||
122 | pub use hir_def::{attr::Attrs, visibility::Visibility, AssocItemId}; | 122 | pub use hir_def::{attr::Attrs, item_scope::ItemInNs, visibility::Visibility, AssocItemId}; |
123 | use rustc_hash::FxHashSet; | 123 | use rustc_hash::FxHashSet; |
124 | 124 | ||
125 | impl Module { | 125 | impl Module { |
@@ -238,11 +238,16 @@ impl Module { | |||
238 | item: ModuleDef, | 238 | item: ModuleDef, |
239 | ) -> Option<hir_def::path::ModPath> { | 239 | ) -> Option<hir_def::path::ModPath> { |
240 | // FIXME expose namespace choice | 240 | // FIXME expose namespace choice |
241 | hir_def::find_path::find_path( | 241 | hir_def::find_path::find_path(db, determine_item_namespace(item), self.into()) |
242 | db, | 242 | } |
243 | hir_def::item_scope::ItemInNs::Types(item.into()), | 243 | } |
244 | self.into(), | 244 | |
245 | ) | 245 | fn determine_item_namespace(module_def: ModuleDef) -> ItemInNs { |
246 | match module_def { | ||
247 | ModuleDef::Static(_) | ModuleDef::Const(_) | ModuleDef::Function(_) => { | ||
248 | ItemInNs::Values(module_def.into()) | ||
249 | } | ||
250 | _ => ItemInNs::Types(module_def.into()), | ||
246 | } | 251 | } |
247 | } | 252 | } |
248 | 253 | ||