aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/has_source.rs
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2019-12-21 14:08:10 +0000
committerGitHub <[email protected]>2019-12-21 14:08:10 +0000
commitdf45f28fedab9b0620ea038849ec8e93c3b4ab26 (patch)
tree7025977c0333378cd209dc47c1d160c7cdef206a /crates/ra_hir/src/has_source.rs
parenta1f4c988e47b7160b11070d18f50657b6fb9014c (diff)
parent973b5cf7e20842711d59a810b268796b26241382 (diff)
Merge #2632
2632: Revert "Merge #2629" r=matklad a=matklad Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_hir/src/has_source.rs')
-rw-r--r--crates/ra_hir/src/has_source.rs16
1 files changed, 14 insertions, 2 deletions
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::{
9use ra_syntax::ast; 9use ra_syntax::ast;
10 10
11use crate::{ 11use crate::{
12 db::DefDatabase, Const, Enum, EnumVariant, FieldSource, Function, ImplBlock, MacroDef, Module, 12 db::DefDatabase, Const, Enum, EnumVariant, FieldSource, Function, ImplBlock, Import, MacroDef,
13 Static, Struct, StructField, Trait, TypeAlias, TypeParam, Union, 13 Module, Static, Struct, StructField, Trait, TypeAlias, TypeParam, Union,
14}; 14};
15 15
16pub use hir_expand::InFile; 16pub use hir_expand::InFile;
@@ -117,6 +117,18 @@ impl HasSource for ImplBlock {
117 self.id.lookup(db).source(db) 117 self.id.lookup(db).source(db)
118 } 118 }
119} 119}
120impl HasSource for Import {
121 type Ast = Either<ast::UseTree, ast::ExternCrateItem>;
122
123 /// Returns the syntax of the last path segment corresponding to this import
124 fn source(self, db: &impl DefDatabase) -> InFile<Self::Ast> {
125 let src = self.parent.definition_source(db);
126 let (_, source_map) = db.raw_items_with_source_map(src.file_id);
127 let root = db.parse_or_expand(src.file_id).unwrap();
128 let ptr = source_map.get(self.id);
129 src.with_value(ptr.map_left(|it| it.to_node(&root)).map_right(|it| it.to_node(&root)))
130 }
131}
120 132
121impl HasSource for TypeParam { 133impl HasSource for TypeParam {
122 type Ast = Either<ast::TraitDef, ast::TypeParam>; 134 type Ast = Either<ast::TraitDef, ast::TypeParam>;