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/has_source.rs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'crates/ra_hir/src/has_source.rs') 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; -- cgit v1.2.3