From 973b5cf7e20842711d59a810b268796b26241382 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 21 Dec 2019 15:04:33 +0100 Subject: Revert "Merge #2629" This reverts commit cdc9d682b066b110e0a44e5f8f1c574b38c16ba9, reversing changes made to 90ef070db3dce0a7acb9cd11d0b0d72de13c9d79. --- crates/ra_hir/src/code_model.rs | 18 ++++++++++-------- crates/ra_hir/src/db.rs | 4 ++-- crates/ra_hir/src/has_source.rs | 16 ++++++++++++++-- crates/ra_hir/src/lib.rs | 4 ++-- 4 files changed, 28 insertions(+), 14 deletions(-) (limited to 'crates/ra_hir') diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs index e6768ea0b..fca3a2950 100644 --- a/crates/ra_hir/src/code_model.rs +++ b/crates/ra_hir/src/code_model.rs @@ -12,8 +12,8 @@ use hir_def::{ resolver::HasResolver, type_ref::{Mutability, TypeRef}, AdtId, ConstId, DefWithBodyId, EnumId, FunctionId, HasModule, ImplId, LocalEnumVariantId, - LocalModuleId, LocalStructFieldId, Lookup, ModuleId, StaticId, StructId, TraitId, TypeAliasId, - TypeParamId, UnionId, + LocalImportId, LocalModuleId, LocalStructFieldId, Lookup, ModuleId, StaticId, StructId, + TraitId, TypeAliasId, TypeParamId, UnionId, }; use hir_expand::{ diagnostics::DiagnosticSink, @@ -180,11 +180,13 @@ impl Module { } /// Returns a `ModuleScope`: a set of items, visible in this module. - pub fn scope(self, db: &impl HirDatabase) -> Vec<(Name, ScopeDef)> { + pub fn scope(self, db: &impl HirDatabase) -> Vec<(Name, ScopeDef, Option)> { db.crate_def_map(self.id.krate)[self.id.local_id] .scope .entries() - .map(|(name, res)| (name.clone(), res.def.into())) + .map(|(name, res)| { + (name.clone(), res.def.into(), res.import.map(|id| Import { parent: self, id })) + }) .collect() } @@ -227,10 +229,10 @@ impl Module { } } -// pub struct Import { -// pub(crate) parent: Module, -// pub(crate) id: LocalImportId, -// } +pub struct Import { + pub(crate) parent: Module, + pub(crate) id: LocalImportId, +} #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] pub struct StructField { diff --git a/crates/ra_hir/src/db.rs b/crates/ra_hir/src/db.rs index f5ffd64fa..bfae3660b 100644 --- a/crates/ra_hir/src/db.rs +++ b/crates/ra_hir/src/db.rs @@ -4,8 +4,8 @@ pub use hir_def::db::{ BodyQuery, BodyWithSourceMapQuery, ConstDataQuery, CrateDefMapQuery, CrateLangItemsQuery, DefDatabase, DefDatabaseStorage, DocumentationQuery, EnumDataQuery, ExprScopesQuery, FunctionDataQuery, GenericParamsQuery, ImplDataQuery, InternDatabase, InternDatabaseStorage, - LangItemQuery, ModuleLangItemsQuery, RawItemsQuery, StaticDataQuery, StructDataQuery, - TraitDataQuery, TypeAliasDataQuery, + LangItemQuery, ModuleLangItemsQuery, RawItemsQuery, RawItemsWithSourceMapQuery, + StaticDataQuery, StructDataQuery, TraitDataQuery, TypeAliasDataQuery, }; pub use hir_expand::db::{ AstDatabase, AstDatabaseStorage, AstIdMapQuery, MacroArgQuery, MacroDefQuery, MacroExpandQuery, diff --git a/crates/ra_hir/src/has_source.rs b/crates/ra_hir/src/has_source.rs index 5541266e2..72afecf26 100644 --- a/crates/ra_hir/src/has_source.rs +++ b/crates/ra_hir/src/has_source.rs @@ -9,8 +9,8 @@ use hir_def::{ use ra_syntax::ast; use crate::{ - db::DefDatabase, Const, Enum, EnumVariant, FieldSource, Function, ImplBlock, MacroDef, Module, - Static, Struct, StructField, Trait, TypeAlias, TypeParam, Union, + db::DefDatabase, Const, Enum, EnumVariant, FieldSource, Function, ImplBlock, Import, MacroDef, + Module, Static, Struct, StructField, Trait, TypeAlias, TypeParam, Union, }; pub use hir_expand::InFile; @@ -117,6 +117,18 @@ impl HasSource for ImplBlock { self.id.lookup(db).source(db) } } +impl HasSource for Import { + type Ast = Either; + + /// Returns the syntax of the last path segment corresponding to this import + fn source(self, db: &impl DefDatabase) -> InFile { + let src = self.parent.definition_source(db); + let (_, source_map) = db.raw_items_with_source_map(src.file_id); + let root = db.parse_or_expand(src.file_id).unwrap(); + let ptr = source_map.get(self.id); + src.with_value(ptr.map_left(|it| it.to_node(&root)).map_right(|it| it.to_node(&root))) + } +} impl HasSource for TypeParam { type Ast = Either; diff --git a/crates/ra_hir/src/lib.rs b/crates/ra_hir/src/lib.rs index 0008a8858..7f9aef770 100644 --- a/crates/ra_hir/src/lib.rs +++ b/crates/ra_hir/src/lib.rs @@ -40,8 +40,8 @@ mod from_source; pub use crate::{ code_model::{ Adt, AssocItem, AttrDef, Const, Crate, CrateDependency, DefWithBody, Docs, Enum, - EnumVariant, FieldSource, Function, GenericDef, HasAttrs, ImplBlock, Local, MacroDef, - Module, ModuleDef, ScopeDef, Static, Struct, StructField, Trait, Type, TypeAlias, + EnumVariant, FieldSource, Function, GenericDef, HasAttrs, ImplBlock, Import, Local, + MacroDef, Module, ModuleDef, ScopeDef, Static, Struct, StructField, Trait, Type, TypeAlias, TypeParam, Union, VariantDef, }, from_source::FromSource, -- cgit v1.2.3