aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/code_model.rs
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2019-11-23 13:41:33 +0000
committerGitHub <[email protected]>2019-11-23 13:41:33 +0000
commit87903420968a958e9f420788edb181ddca7b8b31 (patch)
tree6551407c9053a4e521a3f4cda018b8b1c1f9cb00 /crates/ra_hir/src/code_model.rs
parentcf8ac6e3c75b501cf59ba7b4d97c58efb9cb2adb (diff)
parent338ff052c2fe658d6fcf88888918b2e372129e21 (diff)
Merge #2374
2374: Simplify HasSource r=matklad a=matklad Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_hir/src/code_model.rs')
-rw-r--r--crates/ra_hir/src/code_model.rs26
1 files changed, 11 insertions, 15 deletions
diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs
index 4b3ec5457..50c9a79fc 100644
--- a/crates/ra_hir/src/code_model.rs
+++ b/crates/ra_hir/src/code_model.rs
@@ -9,7 +9,7 @@ use hir_def::{
9 body::scope::ExprScopes, 9 body::scope::ExprScopes,
10 builtin_type::BuiltinType, 10 builtin_type::BuiltinType,
11 docs::Documentation, 11 docs::Documentation,
12 nameres::per_ns::PerNs, 12 nameres::{per_ns::PerNs, raw::ImportId},
13 resolver::{HasResolver, TypeNs}, 13 resolver::{HasResolver, TypeNs},
14 type_ref::TypeRef, 14 type_ref::TypeRef,
15 ContainerId, CrateModuleId, HasModule, ImplId, LocalEnumVariantId, LocalStructFieldId, Lookup, 15 ContainerId, CrateModuleId, HasModule, ImplId, LocalEnumVariantId, LocalStructFieldId, Lookup,
@@ -30,7 +30,7 @@ use crate::{
30 TypeAliasId, 30 TypeAliasId,
31 }, 31 },
32 ty::{InferenceResult, Namespace, TraitRef}, 32 ty::{InferenceResult, Namespace, TraitRef},
33 Either, HasSource, ImportId, Name, Source, Ty, 33 Either, HasSource, Name, Source, Ty,
34}; 34};
35 35
36/// hir::Crate describes a single crate. It's the main interface with which 36/// hir::Crate describes a single crate. It's the main interface with which
@@ -129,17 +129,6 @@ impl Module {
129 }) 129 })
130 } 130 }
131 131
132 /// Returns the syntax of the last path segment corresponding to this import
133 pub fn import_source(
134 self,
135 db: &impl HirDatabase,
136 import: ImportId,
137 ) -> Either<ast::UseTree, ast::ExternCrateItem> {
138 let src = self.definition_source(db);
139 let (_, source_map) = db.raw_items_with_source_map(src.file_id);
140 source_map.get(&src.value, import)
141 }
142
143 /// Returns the crate this module is part of. 132 /// Returns the crate this module is part of.
144 pub fn krate(self) -> Crate { 133 pub fn krate(self) -> Crate {
145 Crate { crate_id: self.id.krate } 134 Crate { crate_id: self.id.krate }
@@ -189,11 +178,13 @@ impl Module {
189 } 178 }
190 179
191 /// Returns a `ModuleScope`: a set of items, visible in this module. 180 /// Returns a `ModuleScope`: a set of items, visible in this module.
192 pub fn scope(self, db: &impl HirDatabase) -> Vec<(Name, ScopeDef, Option<ImportId>)> { 181 pub fn scope(self, db: &impl HirDatabase) -> Vec<(Name, ScopeDef, Option<Import>)> {
193 db.crate_def_map(self.id.krate)[self.id.module_id] 182 db.crate_def_map(self.id.krate)[self.id.module_id]
194 .scope 183 .scope
195 .entries() 184 .entries()
196 .map(|(name, res)| (name.clone(), res.def.into(), res.import)) 185 .map(|(name, res)| {
186 (name.clone(), res.def.into(), res.import.map(|id| Import { parent: self, id }))
187 })
197 .collect() 188 .collect()
198 } 189 }
199 190
@@ -236,6 +227,11 @@ impl Module {
236 } 227 }
237} 228}
238 229
230pub struct Import {
231 pub(crate) parent: Module,
232 pub(crate) id: ImportId,
233}
234
239#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] 235#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
240pub struct StructField { 236pub struct StructField {
241 pub(crate) parent: VariantDef, 237 pub(crate) parent: VariantDef,