aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/source_binder.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir/src/source_binder.rs')
-rw-r--r--crates/ra_hir/src/source_binder.rs17
1 files changed, 7 insertions, 10 deletions
diff --git a/crates/ra_hir/src/source_binder.rs b/crates/ra_hir/src/source_binder.rs
index 797f90d50..cfc4bd326 100644
--- a/crates/ra_hir/src/source_binder.rs
+++ b/crates/ra_hir/src/source_binder.rs
@@ -13,7 +13,9 @@ use hir_def::{
13 resolver::{self, resolver_for_scope, HasResolver, Resolver, TypeNs, ValueNs}, 13 resolver::{self, resolver_for_scope, HasResolver, Resolver, TypeNs, ValueNs},
14 DefWithBodyId, 14 DefWithBodyId,
15}; 15};
16use hir_expand::{name::AsName, AstId, MacroCallId, MacroCallLoc, MacroFileKind, Source}; 16use hir_expand::{
17 name::AsName, AstId, HirFileId, MacroCallId, MacroCallLoc, MacroFileKind, Source,
18};
17use ra_syntax::{ 19use ra_syntax::{
18 ast::{self, AstNode}, 20 ast::{self, AstNode},
19 match_ast, AstPtr, 21 match_ast, AstPtr,
@@ -24,11 +26,10 @@ use ra_syntax::{
24use crate::{ 26use crate::{
25 db::HirDatabase, 27 db::HirDatabase,
26 expr::{BodySourceMap, ExprScopes, ScopeId}, 28 expr::{BodySourceMap, ExprScopes, ScopeId},
27 ids::LocationCtx,
28 ty::method_resolution::{self, implements_trait}, 29 ty::method_resolution::{self, implements_trait},
29 Adt, AssocItem, Const, DefWithBody, Either, Enum, EnumVariant, FromSource, Function, 30 Adt, AssocItem, Const, DefWithBody, Either, Enum, EnumVariant, FromSource, Function,
30 GenericParam, HasBody, HirFileId, Local, MacroDef, Module, Name, Path, ScopeDef, Static, 31 GenericParam, HasBody, Local, MacroDef, Name, Path, ScopeDef, Static, Struct, Trait, Ty,
31 Struct, Trait, Ty, TypeAlias, 32 TypeAlias,
32}; 33};
33 34
34fn try_get_resolver_for_node(db: &impl HirDatabase, node: Source<&SyntaxNode>) -> Option<Resolver> { 35fn try_get_resolver_for_node(db: &impl HirDatabase, node: Source<&SyntaxNode>) -> Option<Resolver> {
@@ -67,16 +68,12 @@ fn def_with_body_from_child_node(
67 db: &impl HirDatabase, 68 db: &impl HirDatabase,
68 child: Source<&SyntaxNode>, 69 child: Source<&SyntaxNode>,
69) -> Option<DefWithBody> { 70) -> Option<DefWithBody> {
70 let module_source = crate::ModuleSource::from_child_node(db, child);
71 let module = Module::from_definition(db, Source::new(child.file_id, module_source))?;
72 let ctx = LocationCtx::new(db, module.id, child.file_id);
73
74 child.value.ancestors().find_map(|node| { 71 child.value.ancestors().find_map(|node| {
75 match_ast! { 72 match_ast! {
76 match node { 73 match node {
77 ast::FnDef(def) => { return Function::from_source(db, child.with_value(def)).map(DefWithBody::from); }, 74 ast::FnDef(def) => { return Function::from_source(db, child.with_value(def)).map(DefWithBody::from); },
78 ast::ConstDef(def) => { return Const::from_source(db, child.with_value(def)).map(DefWithBody::from); }, 75 ast::ConstDef(def) => { return Const::from_source(db, child.with_value(def)).map(DefWithBody::from); },
79 ast::StaticDef(def) => { Some(Static { id: ctx.to_def(&def) }.into()) }, 76 ast::StaticDef(def) => { return Static::from_source(db, child.with_value(def)).map(DefWithBody::from); },
80 _ => { None }, 77 _ => { None },
81 } 78 }
82 } 79 }
@@ -544,7 +541,7 @@ fn adjust(
544} 541}
545 542
546/// Given a `ast::MacroCall`, return what `MacroKindFile` it belongs to. 543/// Given a `ast::MacroCall`, return what `MacroKindFile` it belongs to.
547/// FIXME: Not completed 544/// FIXME: Not completed
548fn to_macro_file_kind(macro_call: &ast::MacroCall) -> MacroFileKind { 545fn to_macro_file_kind(macro_call: &ast::MacroCall) -> MacroFileKind {
549 let syn = macro_call.syntax(); 546 let syn = macro_call.syntax();
550 let parent = match syn.parent() { 547 let parent = match syn.parent() {