From e5bcb69e4f88c7536b1039a881816cb8f1c1f867 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 23 Nov 2019 16:39:53 +0300 Subject: Hide ImportId --- crates/ra_hir/src/code_model/src.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'crates/ra_hir/src/code_model') diff --git a/crates/ra_hir/src/code_model/src.rs b/crates/ra_hir/src/code_model/src.rs index 09bacf579..ceb3daa27 100644 --- a/crates/ra_hir/src/code_model/src.rs +++ b/crates/ra_hir/src/code_model/src.rs @@ -8,7 +8,7 @@ use crate::{ db::{AstDatabase, DefDatabase, HirDatabase}, ids::AstItemDef, Const, Enum, EnumVariant, FieldSource, Function, HasBody, MacroDef, Module, ModuleSource, - Static, Struct, StructField, Trait, TypeAlias, Union, + Static, Struct, StructField, Trait, TypeAlias, Union, Import }; pub use hir_expand::Source; @@ -113,6 +113,16 @@ impl HasSource for MacroDef { Source { file_id: self.id.ast_id.file_id(), value: self.id.ast_id.to_node(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 + AstDatabase)) -> Source { + let src = self.parent.definition_source(db); + let (_, source_map) = db.raw_items_with_source_map(src.file_id); + src.with_value(source_map.get(&src.value, self.id)) + } +} pub trait HasBodySource: HasBody + HasSource where -- cgit v1.2.3