From 4c90b7e2ecd03e739a3c92bbe5afd4c90fe2812d Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 15 Nov 2019 23:24:56 +0300 Subject: Sourcify some things If we want to support macros properly, we need to get rid of those FileIds everywhere... --- crates/ra_hir/src/from_source.rs | 5 ++--- crates/ra_hir/src/source_binder.rs | 15 +++++++-------- 2 files changed, 9 insertions(+), 11 deletions(-) (limited to 'crates/ra_hir') diff --git a/crates/ra_hir/src/from_source.rs b/crates/ra_hir/src/from_source.rs index ec56dfa6a..79152a57c 100644 --- a/crates/ra_hir/src/from_source.rs +++ b/crates/ra_hir/src/from_source.rs @@ -196,9 +196,8 @@ where N: AstNode, DEF: AstItemDef, { - let module_src = - crate::ModuleSource::from_child_node(db, src.file_id.original_file(db), &src.ast.syntax()); - let module = Module::from_definition(db, Source { file_id: src.file_id, ast: module_src })?; + 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.ast)) } diff --git a/crates/ra_hir/src/source_binder.rs b/crates/ra_hir/src/source_binder.rs index 662d3f880..f08827ed3 100644 --- a/crates/ra_hir/src/source_binder.rs +++ b/crates/ra_hir/src/source_binder.rs @@ -56,7 +56,7 @@ fn try_get_resolver_for_node( }, _ => { if node.kind() == FN_DEF || node.kind() == CONST_DEF || node.kind() == STATIC_DEF { - Some(def_with_body_from_child_node(db, file_id, node)?.resolver(db)) + Some(def_with_body_from_child_node(db, Source::new(file_id.into(), node))?.resolver(db)) } else { // FIXME add missing cases None @@ -68,14 +68,13 @@ fn try_get_resolver_for_node( fn def_with_body_from_child_node( db: &impl HirDatabase, - file_id: FileId, - node: &SyntaxNode, + child: Source<&SyntaxNode>, ) -> Option { - let src = crate::ModuleSource::from_child_node(db, file_id, node); - let module = Module::from_definition(db, crate::Source { file_id: file_id.into(), ast: src })?; - let ctx = LocationCtx::new(db, module.id, file_id.into()); + let module_source = crate::ModuleSource::from_child_node(db, child); + let module = Module::from_definition(db, Source::new(child.file_id, module_source))?; + let ctx = LocationCtx::new(db, module.id, child.file_id); - node.ancestors().find_map(|node| { + child.ast.ancestors().find_map(|node| { match_ast! { match node { ast::FnDef(def) => { Some(Function {id: ctx.to_def(&def) }.into()) }, @@ -142,7 +141,7 @@ impl SourceAnalyzer { node: &SyntaxNode, offset: Option, ) -> SourceAnalyzer { - let def_with_body = def_with_body_from_child_node(db, file_id, node); + let def_with_body = def_with_body_from_child_node(db, Source::new(file_id.into(), node)); if let Some(def) = def_with_body { let source_map = def.body_source_map(db); let scopes = def.expr_scopes(db); -- cgit v1.2.3