diff options
Diffstat (limited to 'crates/ra_hir/src/code_model')
-rw-r--r-- | crates/ra_hir/src/code_model/src.rs | 12 |
1 files changed, 11 insertions, 1 deletions
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::{ | |||
8 | db::{AstDatabase, DefDatabase, HirDatabase}, | 8 | db::{AstDatabase, DefDatabase, HirDatabase}, |
9 | ids::AstItemDef, | 9 | ids::AstItemDef, |
10 | Const, Enum, EnumVariant, FieldSource, Function, HasBody, MacroDef, Module, ModuleSource, | 10 | Const, Enum, EnumVariant, FieldSource, Function, HasBody, MacroDef, Module, ModuleSource, |
11 | Static, Struct, StructField, Trait, TypeAlias, Union, | 11 | Static, Struct, StructField, Trait, TypeAlias, Union, Import |
12 | }; | 12 | }; |
13 | 13 | ||
14 | pub use hir_expand::Source; | 14 | pub use hir_expand::Source; |
@@ -113,6 +113,16 @@ impl HasSource for MacroDef { | |||
113 | Source { file_id: self.id.ast_id.file_id(), value: self.id.ast_id.to_node(db) } | 113 | Source { file_id: self.id.ast_id.file_id(), value: self.id.ast_id.to_node(db) } |
114 | } | 114 | } |
115 | } | 115 | } |
116 | impl HasSource for Import { | ||
117 | type Ast = Either<ast::UseTree, ast::ExternCrateItem>; | ||
118 | |||
119 | /// Returns the syntax of the last path segment corresponding to this import | ||
120 | fn source(self, db: &(impl DefDatabase + AstDatabase)) -> Source<Self::Ast> { | ||
121 | let src = self.parent.definition_source(db); | ||
122 | let (_, source_map) = db.raw_items_with_source_map(src.file_id); | ||
123 | src.with_value(source_map.get(&src.value, self.id)) | ||
124 | } | ||
125 | } | ||
116 | 126 | ||
117 | pub trait HasBodySource: HasBody + HasSource | 127 | pub trait HasBodySource: HasBody + HasSource |
118 | where | 128 | where |