From 699ce06ac3d857c7d4eaf01c523964f01d1b35f2 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Mon, 4 Feb 2019 22:09:56 +0100 Subject: Complete extern prelude (again) --- crates/ra_hir/src/nameres.rs | 2 +- crates/ra_hir/src/resolve.rs | 5 ++++- crates/ra_ide_api/src/completion/complete_scope.rs | 14 ++++++++++++++ .../snapshots/completion_item__extern_prelude.snap | 22 ++++++++++++++++++++++ 4 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 crates/ra_ide_api/src/completion/snapshots/completion_item__extern_prelude.snap (limited to 'crates') diff --git a/crates/ra_hir/src/nameres.rs b/crates/ra_hir/src/nameres.rs index 68df083d8..f9da6bc83 100644 --- a/crates/ra_hir/src/nameres.rs +++ b/crates/ra_hir/src/nameres.rs @@ -34,7 +34,7 @@ use crate::{ /// module, the set of visible items. #[derive(Default, Debug, PartialEq, Eq)] pub struct ItemMap { - extern_prelude: FxHashMap, + pub(crate) extern_prelude: FxHashMap, per_module: ArenaMap, } diff --git a/crates/ra_hir/src/resolve.rs b/crates/ra_hir/src/resolve.rs index 6c87d0df7..5ca7bacb5 100644 --- a/crates/ra_hir/src/resolve.rs +++ b/crates/ra_hir/src/resolve.rs @@ -197,7 +197,10 @@ impl Scope { .entries() .for_each(|(name, res)| { f(name.clone(), res.def.map(Resolution::Def)); - }) + }); + m.item_map.extern_prelude.iter().for_each(|(name, def)| { + f(name.clone(), PerNs::types(Resolution::Def(*def))); + }); } Scope::GenericParams(gp) => { for param in &gp.params { diff --git a/crates/ra_ide_api/src/completion/complete_scope.rs b/crates/ra_ide_api/src/completion/complete_scope.rs index 44514ab2b..8674b1e66 100644 --- a/crates/ra_ide_api/src/completion/complete_scope.rs +++ b/crates/ra_ide_api/src/completion/complete_scope.rs @@ -110,6 +110,20 @@ mod tests { ); } + #[test] + fn completes_extern_prelude() { + check_reference_completion( + "extern_prelude", + r" + //- /lib.rs + use <|>; + + //- /other_crate/lib.rs + // nothing here + ", + ); + } + #[test] fn completes_module_items_in_nested_modules() { check_reference_completion( diff --git a/crates/ra_ide_api/src/completion/snapshots/completion_item__extern_prelude.snap b/crates/ra_ide_api/src/completion/snapshots/completion_item__extern_prelude.snap new file mode 100644 index 000000000..d0e3a6188 --- /dev/null +++ b/crates/ra_ide_api/src/completion/snapshots/completion_item__extern_prelude.snap @@ -0,0 +1,22 @@ +--- +created: "2019-02-04T21:08:32.615556587+00:00" +creator: insta@0.5.3 +expression: kind_completions +source: crates/ra_ide_api/src/completion/completion_item.rs +--- +[ + CompletionItem { + completion_kind: Reference, + label: "other_crate", + kind: Some( + Module + ), + detail: None, + documentation: None, + lookup: None, + insert_text: None, + insert_text_format: PlainText, + source_range: [4; 4), + text_edit: None + } +] -- cgit v1.2.3