aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-11-24 12:20:59 +0000
committerAleksey Kladov <[email protected]>2019-11-24 12:20:59 +0000
commit151180057b0304ee4dee75401e8f1aaa7aaaec21 (patch)
treef61f810aa5f0c9cda0f07bd15d8f03b2d3b5ee83 /crates
parente0b06cb672b7aae770fea24e4a5efdbec8cbf5c6 (diff)
Simplify
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_hir/src/from_source.rs4
-rw-r--r--crates/ra_hir_def/src/lib.rs15
2 files changed, 3 insertions, 16 deletions
diff --git a/crates/ra_hir/src/from_source.rs b/crates/ra_hir/src/from_source.rs
index e6eefcace..f506bba70 100644
--- a/crates/ra_hir/src/from_source.rs
+++ b/crates/ra_hir/src/from_source.rs
@@ -282,7 +282,9 @@ where
282 let module_src = ModuleSource::from_child_node(db, src.as_ref().map(|it| it.syntax())); 282 let module_src = ModuleSource::from_child_node(db, src.as_ref().map(|it| it.syntax()));
283 let module = Module::from_definition(db, Source::new(src.file_id, module_src))?; 283 let module = Module::from_definition(db, Source::new(src.file_id, module_src))?;
284 let ctx = LocationCtx::new(db, module.id, src.file_id); 284 let ctx = LocationCtx::new(db, module.id, src.file_id);
285 Some(DEF::from_ast(ctx, &src.value)) 285 let items = db.ast_id_map(src.file_id);
286 let item_id = items.ast_id(&src.value);
287 Some(DEF::from_ast_id(ctx, item_id))
286} 288}
287 289
288enum Container { 290enum Container {
diff --git a/crates/ra_hir_def/src/lib.rs b/crates/ra_hir_def/src/lib.rs
index 89f1ceb58..f60feb5fa 100644
--- a/crates/ra_hir_def/src/lib.rs
+++ b/crates/ra_hir_def/src/lib.rs
@@ -94,25 +94,10 @@ impl<'a, DB> LocationCtx<&'a DB> {
94 } 94 }
95} 95}
96 96
97impl<'a, DB: AstDatabase + InternDatabase> LocationCtx<&'a DB> {
98 pub fn to_def<N, DEF>(self, ast: &N) -> DEF
99 where
100 N: AstNode,
101 DEF: AstItemDef<N>,
102 {
103 DEF::from_ast(self, ast)
104 }
105}
106
107pub trait AstItemDef<N: AstNode>: salsa::InternKey + Clone { 97pub trait AstItemDef<N: AstNode>: salsa::InternKey + Clone {
108 fn intern(db: &impl InternDatabase, loc: ItemLoc<N>) -> Self; 98 fn intern(db: &impl InternDatabase, loc: ItemLoc<N>) -> Self;
109 fn lookup_intern(self, db: &impl InternDatabase) -> ItemLoc<N>; 99 fn lookup_intern(self, db: &impl InternDatabase) -> ItemLoc<N>;
110 100
111 fn from_ast(ctx: LocationCtx<&(impl AstDatabase + InternDatabase)>, ast: &N) -> Self {
112 let items = ctx.db.ast_id_map(ctx.file_id);
113 let item_id = items.ast_id(ast);
114 Self::from_ast_id(ctx, item_id)
115 }
116 fn from_ast_id(ctx: LocationCtx<&impl InternDatabase>, ast_id: FileAstId<N>) -> Self { 101 fn from_ast_id(ctx: LocationCtx<&impl InternDatabase>, ast_id: FileAstId<N>) -> Self {
117 let loc = ItemLoc { module: ctx.module, ast_id: AstId::new(ctx.file_id, ast_id) }; 102 let loc = ItemLoc { module: ctx.module, ast_id: AstId::new(ctx.file_id, ast_id) };
118 Self::intern(ctx.db, loc) 103 Self::intern(ctx.db, loc)