From 151180057b0304ee4dee75401e8f1aaa7aaaec21 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 24 Nov 2019 15:20:59 +0300 Subject: Simplify --- crates/ra_hir/src/from_source.rs | 4 +++- crates/ra_hir_def/src/lib.rs | 15 --------------- 2 files changed, 3 insertions(+), 16 deletions(-) (limited to 'crates') 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 let module_src = ModuleSource::from_child_node(db, src.as_ref().map(|it| it.syntax())); let module = Module::from_definition(db, Source::new(src.file_id, module_src))?; let ctx = LocationCtx::new(db, module.id, src.file_id); - Some(DEF::from_ast(ctx, &src.value)) + let items = db.ast_id_map(src.file_id); + let item_id = items.ast_id(&src.value); + Some(DEF::from_ast_id(ctx, item_id)) } enum 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> { } } -impl<'a, DB: AstDatabase + InternDatabase> LocationCtx<&'a DB> { - pub fn to_def(self, ast: &N) -> DEF - where - N: AstNode, - DEF: AstItemDef, - { - DEF::from_ast(self, ast) - } -} - pub trait AstItemDef: salsa::InternKey + Clone { fn intern(db: &impl InternDatabase, loc: ItemLoc) -> Self; fn lookup_intern(self, db: &impl InternDatabase) -> ItemLoc; - fn from_ast(ctx: LocationCtx<&(impl AstDatabase + InternDatabase)>, ast: &N) -> Self { - let items = ctx.db.ast_id_map(ctx.file_id); - let item_id = items.ast_id(ast); - Self::from_ast_id(ctx, item_id) - } fn from_ast_id(ctx: LocationCtx<&impl InternDatabase>, ast_id: FileAstId) -> Self { let loc = ItemLoc { module: ctx.module, ast_id: AstId::new(ctx.file_id, ast_id) }; Self::intern(ctx.db, loc) -- cgit v1.2.3