aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir')
-rw-r--r--crates/ra_hir/src/code_model.rs24
-rw-r--r--crates/ra_hir/src/code_model/src.rs10
-rw-r--r--crates/ra_hir/src/from_source.rs98
-rw-r--r--crates/ra_hir/src/lib.rs6
-rw-r--r--crates/ra_hir/src/source_binder.rs73
5 files changed, 108 insertions, 103 deletions
diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs
index 7706399ae..4578a0ba8 100644
--- a/crates/ra_hir/src/code_model.rs
+++ b/crates/ra_hir/src/code_model.rs
@@ -15,9 +15,9 @@ use hir_def::{
15 per_ns::PerNs, 15 per_ns::PerNs,
16 resolver::HasResolver, 16 resolver::HasResolver,
17 type_ref::{Mutability, TypeRef}, 17 type_ref::{Mutability, TypeRef},
18 AdtId, AstItemDef, ConstId, ContainerId, DefWithBodyId, EnumId, FunctionId, GenericDefId, 18 AdtId, AstItemDef, ConstId, ContainerId, DefWithBodyId, EnumId, FunctionId, HasModule, ImplId,
19 HasModule, ImplId, LocalEnumVariantId, LocalImportId, LocalModuleId, LocalStructFieldId, 19 LocalEnumVariantId, LocalImportId, LocalModuleId, LocalStructFieldId, Lookup, ModuleId,
20 Lookup, ModuleId, StaticId, StructId, TraitId, TypeAliasId, UnionId, 20 StaticId, StructId, TraitId, TypeAliasId, TypeParamId, UnionId,
21}; 21};
22use hir_expand::{ 22use hir_expand::{
23 diagnostics::DiagnosticSink, 23 diagnostics::DiagnosticSink,
@@ -856,9 +856,19 @@ impl Local {
856} 856}
857 857
858#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] 858#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
859pub struct GenericParam { 859pub struct TypeParam {
860 pub(crate) parent: GenericDefId, 860 pub(crate) id: TypeParamId,
861 pub(crate) idx: u32, 861}
862
863impl TypeParam {
864 pub fn name(self, db: &impl HirDatabase) -> Name {
865 let params = db.generic_params(self.id.parent);
866 params.types[self.id.local_id].name.clone()
867 }
868
869 pub fn module(self, db: &impl HirDatabase) -> Module {
870 self.id.parent.module(db).into()
871 }
862} 872}
863 873
864#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] 874#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
@@ -1101,7 +1111,7 @@ impl HirDisplay for Type {
1101pub enum ScopeDef { 1111pub enum ScopeDef {
1102 ModuleDef(ModuleDef), 1112 ModuleDef(ModuleDef),
1103 MacroDef(MacroDef), 1113 MacroDef(MacroDef),
1104 GenericParam(GenericParam), 1114 GenericParam(TypeParam),
1105 ImplSelfType(ImplBlock), 1115 ImplSelfType(ImplBlock),
1106 AdtSelfType(Adt), 1116 AdtSelfType(Adt),
1107 Local(Local), 1117 Local(Local),
diff --git a/crates/ra_hir/src/code_model/src.rs b/crates/ra_hir/src/code_model/src.rs
index 78a454082..b09582f93 100644
--- a/crates/ra_hir/src/code_model/src.rs
+++ b/crates/ra_hir/src/code_model/src.rs
@@ -10,7 +10,7 @@ use ra_syntax::ast;
10 10
11use crate::{ 11use crate::{
12 db::DefDatabase, Const, Enum, EnumVariant, FieldSource, Function, ImplBlock, Import, MacroDef, 12 db::DefDatabase, Const, Enum, EnumVariant, FieldSource, Function, ImplBlock, Import, MacroDef,
13 Module, Static, Struct, StructField, Trait, TypeAlias, Union, 13 Module, Static, Struct, StructField, Trait, TypeAlias, TypeParam, Union,
14}; 14};
15 15
16pub use hir_expand::InFile; 16pub use hir_expand::InFile;
@@ -129,3 +129,11 @@ impl HasSource for Import {
129 src.with_value(ptr.map_left(|it| it.to_node(&root)).map_right(|it| it.to_node(&root))) 129 src.with_value(ptr.map_left(|it| it.to_node(&root)).map_right(|it| it.to_node(&root)))
130 } 130 }
131} 131}
132
133impl HasSource for TypeParam {
134 type Ast = Either<ast::TraitDef, ast::TypeParam>;
135 fn source(self, db: &impl DefDatabase) -> InFile<Self::Ast> {
136 let child_source = self.id.parent.child_source(db);
137 child_source.map(|it| it[self.id.local_id].clone())
138 }
139}
diff --git a/crates/ra_hir/src/from_source.rs b/crates/ra_hir/src/from_source.rs
index 5cb222bd3..4acc038e4 100644
--- a/crates/ra_hir/src/from_source.rs
+++ b/crates/ra_hir/src/from_source.rs
@@ -1,9 +1,7 @@
1//! FIXME: write short doc here 1//! FIXME: write short doc here
2use either::Either;
3
4use hir_def::{ 2use hir_def::{
5 child_from_source::ChildFromSource, nameres::ModuleSource, AstItemDef, EnumVariantId, ImplId, 3 child_by_source::ChildBySource, dyn_map::DynMap, keys, nameres::ModuleSource, AstItemDef,
6 LocationCtx, ModuleId, TraitId, VariantId, 4 EnumVariantId, GenericDefId, LocationCtx, ModuleId, VariantId,
7}; 5};
8use hir_expand::{name::AsName, AstId, MacroDefId, MacroDefKind}; 6use hir_expand::{name::AsName, AstId, MacroDefId, MacroDefKind};
9use ra_syntax::{ 7use ra_syntax::{
@@ -14,7 +12,7 @@ use ra_syntax::{
14use crate::{ 12use crate::{
15 db::{AstDatabase, DefDatabase, HirDatabase}, 13 db::{AstDatabase, DefDatabase, HirDatabase},
16 Const, DefWithBody, Enum, EnumVariant, FieldSource, Function, ImplBlock, InFile, Local, 14 Const, DefWithBody, Enum, EnumVariant, FieldSource, Function, ImplBlock, InFile, Local,
17 MacroDef, Module, Static, Struct, StructField, Trait, TypeAlias, Union, 15 MacroDef, Module, Static, Struct, StructField, Trait, TypeAlias, TypeParam, Union,
18}; 16};
19 17
20pub trait FromSource: Sized { 18pub trait FromSource: Sized {
@@ -53,8 +51,9 @@ impl FromSource for Trait {
53impl FromSource for Function { 51impl FromSource for Function {
54 type Ast = ast::FnDef; 52 type Ast = ast::FnDef;
55 fn from_source(db: &(impl DefDatabase + AstDatabase), src: InFile<Self::Ast>) -> Option<Self> { 53 fn from_source(db: &(impl DefDatabase + AstDatabase), src: InFile<Self::Ast>) -> Option<Self> {
56 Container::find(db, src.as_ref().map(|it| it.syntax()))? 54 Container::find(db, src.as_ref().map(|it| it.syntax()))?.child_by_source(db)[keys::FUNCTION]
57 .child_from_source(db, src) 55 .get(&src)
56 .copied()
58 .map(Function::from) 57 .map(Function::from)
59 } 58 }
60} 59}
@@ -62,26 +61,29 @@ impl FromSource for Function {
62impl FromSource for Const { 61impl FromSource for Const {
63 type Ast = ast::ConstDef; 62 type Ast = ast::ConstDef;
64 fn from_source(db: &(impl DefDatabase + AstDatabase), src: InFile<Self::Ast>) -> Option<Self> { 63 fn from_source(db: &(impl DefDatabase + AstDatabase), src: InFile<Self::Ast>) -> Option<Self> {
65 Container::find(db, src.as_ref().map(|it| it.syntax()))? 64 Container::find(db, src.as_ref().map(|it| it.syntax()))?.child_by_source(db)[keys::CONST]
66 .child_from_source(db, src) 65 .get(&src)
66 .copied()
67 .map(Const::from) 67 .map(Const::from)
68 } 68 }
69} 69}
70impl FromSource for Static { 70impl FromSource for Static {
71 type Ast = ast::StaticDef; 71 type Ast = ast::StaticDef;
72 fn from_source(db: &(impl DefDatabase + AstDatabase), src: InFile<Self::Ast>) -> Option<Self> { 72 fn from_source(db: &(impl DefDatabase + AstDatabase), src: InFile<Self::Ast>) -> Option<Self> {
73 match Container::find(db, src.as_ref().map(|it| it.syntax()))? { 73 Container::find(db, src.as_ref().map(|it| it.syntax()))?.child_by_source(db)[keys::STATIC]
74 Container::Module(it) => it.id.child_from_source(db, src).map(Static::from), 74 .get(&src)
75 Container::Trait(_) | Container::ImplBlock(_) => None, 75 .copied()
76 } 76 .map(Static::from)
77 } 77 }
78} 78}
79 79
80impl FromSource for TypeAlias { 80impl FromSource for TypeAlias {
81 type Ast = ast::TypeAliasDef; 81 type Ast = ast::TypeAliasDef;
82 fn from_source(db: &(impl DefDatabase + AstDatabase), src: InFile<Self::Ast>) -> Option<Self> { 82 fn from_source(db: &(impl DefDatabase + AstDatabase), src: InFile<Self::Ast>) -> Option<Self> {
83 Container::find(db, src.as_ref().map(|it| it.syntax()))? 83 Container::find(db, src.as_ref().map(|it| it.syntax()))?.child_by_source(db)
84 .child_from_source(db, src) 84 [keys::TYPE_ALIAS]
85 .get(&src)
86 .copied()
85 .map(TypeAlias::from) 87 .map(TypeAlias::from)
86 } 88 }
87} 89}
@@ -116,32 +118,41 @@ impl FromSource for EnumVariant {
116 let parent_enum = src.value.parent_enum(); 118 let parent_enum = src.value.parent_enum();
117 let src_enum = InFile { file_id: src.file_id, value: parent_enum }; 119 let src_enum = InFile { file_id: src.file_id, value: parent_enum };
118 let parent_enum = Enum::from_source(db, src_enum)?; 120 let parent_enum = Enum::from_source(db, src_enum)?;
119 parent_enum.id.child_from_source(db, src).map(EnumVariant::from) 121 parent_enum.id.child_by_source(db)[keys::ENUM_VARIANT]
122 .get(&src)
123 .copied()
124 .map(EnumVariant::from)
120 } 125 }
121} 126}
122 127
123impl FromSource for StructField { 128impl FromSource for StructField {
124 type Ast = FieldSource; 129 type Ast = FieldSource;
125 fn from_source(db: &(impl DefDatabase + AstDatabase), src: InFile<Self::Ast>) -> Option<Self> { 130 fn from_source(db: &(impl DefDatabase + AstDatabase), src: InFile<Self::Ast>) -> Option<Self> {
131 let src = src.as_ref();
132
133 // FIXME this is buggy
126 let variant_id: VariantId = match src.value { 134 let variant_id: VariantId = match src.value {
127 FieldSource::Named(ref field) => { 135 FieldSource::Named(field) => {
128 let value = field.syntax().ancestors().find_map(ast::StructDef::cast)?; 136 let value = field.syntax().ancestors().find_map(ast::StructDef::cast)?;
129 let src = InFile { file_id: src.file_id, value }; 137 let src = InFile { file_id: src.file_id, value };
130 let def = Struct::from_source(db, src)?; 138 let def = Struct::from_source(db, src)?;
131 def.id.into() 139 def.id.into()
132 } 140 }
133 FieldSource::Pos(ref field) => { 141 FieldSource::Pos(field) => {
134 let value = field.syntax().ancestors().find_map(ast::EnumVariant::cast)?; 142 let value = field.syntax().ancestors().find_map(ast::EnumVariant::cast)?;
135 let src = InFile { file_id: src.file_id, value }; 143 let src = InFile { file_id: src.file_id, value };
136 let def = EnumVariant::from_source(db, src)?; 144 let def = EnumVariant::from_source(db, src)?;
137 EnumVariantId::from(def).into() 145 EnumVariantId::from(def).into()
138 } 146 }
139 }; 147 };
140 let src = src.map(|field_source| match field_source { 148
141 FieldSource::Pos(it) => Either::Left(it), 149 let dyn_map = variant_id.child_by_source(db);
142 FieldSource::Named(it) => Either::Right(it), 150 match src.value {
143 }); 151 FieldSource::Pos(it) => dyn_map[keys::TUPLE_FIELD].get(&src.with_value(it.clone())),
144 variant_id.child_from_source(db, src).map(StructField::from) 152 FieldSource::Named(it) => dyn_map[keys::RECORD_FIELD].get(&src.with_value(it.clone())),
153 }
154 .copied()
155 .map(StructField::from)
145 } 156 }
146} 157}
147 158
@@ -166,6 +177,28 @@ impl Local {
166 } 177 }
167} 178}
168 179
180impl TypeParam {
181 pub fn from_source(db: &impl HirDatabase, src: InFile<ast::TypeParam>) -> Option<Self> {
182 let file_id = src.file_id;
183 let parent: GenericDefId = src.value.syntax().ancestors().find_map(|it| {
184 let res = match_ast! {
185 match it {
186 ast::FnDef(value) => { Function::from_source(db, InFile { value, file_id})?.id.into() },
187 ast::StructDef(value) => { Struct::from_source(db, InFile { value, file_id})?.id.into() },
188 ast::EnumDef(value) => { Enum::from_source(db, InFile { value, file_id})?.id.into() },
189 ast::TraitDef(value) => { Trait::from_source(db, InFile { value, file_id})?.id.into() },
190 ast::TypeAliasDef(value) => { TypeAlias::from_source(db, InFile { value, file_id})?.id.into() },
191 ast::ImplBlock(value) => { ImplBlock::from_source(db, InFile { value, file_id})?.id.into() },
192 _ => return None,
193 }
194 };
195 Some(res)
196 })?;
197 let &id = parent.child_by_source(db)[keys::TYPE_PARAM].get(&src)?;
198 Some(TypeParam { id })
199 }
200}
201
169impl Module { 202impl Module {
170 pub fn from_declaration(db: &impl DefDatabase, src: InFile<ast::Module>) -> Option<Self> { 203 pub fn from_declaration(db: &impl DefDatabase, src: InFile<ast::Module>) -> Option<Self> {
171 let parent_declaration = src.value.syntax().ancestors().skip(1).find_map(ast::Module::cast); 204 let parent_declaration = src.value.syntax().ancestors().skip(1).find_map(ast::Module::cast);
@@ -255,21 +288,12 @@ impl Container {
255 } 288 }
256} 289}
257 290
258impl<CHILD, SOURCE> ChildFromSource<CHILD, SOURCE> for Container 291impl ChildBySource for Container {
259where 292 fn child_by_source(&self, db: &impl DefDatabase) -> DynMap {
260 TraitId: ChildFromSource<CHILD, SOURCE>,
261 ImplId: ChildFromSource<CHILD, SOURCE>,
262 ModuleId: ChildFromSource<CHILD, SOURCE>,
263{
264 fn child_from_source(
265 &self,
266 db: &impl DefDatabase,
267 child_source: InFile<SOURCE>,
268 ) -> Option<CHILD> {
269 match self { 293 match self {
270 Container::Trait(it) => it.id.child_from_source(db, child_source), 294 Container::Trait(it) => it.id.child_by_source(db),
271 Container::ImplBlock(it) => it.id.child_from_source(db, child_source), 295 Container::ImplBlock(it) => it.id.child_by_source(db),
272 Container::Module(it) => it.id.child_from_source(db, child_source), 296 Container::Module(it) => it.id.child_by_source(db),
273 } 297 }
274 } 298 }
275} 299}
diff --git a/crates/ra_hir/src/lib.rs b/crates/ra_hir/src/lib.rs
index f12e4ca3f..9eb34b5dc 100644
--- a/crates/ra_hir/src/lib.rs
+++ b/crates/ra_hir/src/lib.rs
@@ -42,9 +42,9 @@ pub mod from_source;
42pub use crate::{ 42pub use crate::{
43 code_model::{ 43 code_model::{
44 src::HasSource, Adt, AssocItem, AttrDef, Const, Container, Crate, CrateDependency, 44 src::HasSource, Adt, AssocItem, AttrDef, Const, Container, Crate, CrateDependency,
45 DefWithBody, Docs, Enum, EnumVariant, FieldSource, Function, GenericDef, GenericParam, 45 DefWithBody, Docs, Enum, EnumVariant, FieldSource, Function, GenericDef, HasAttrs,
46 HasAttrs, ImplBlock, Import, Local, MacroDef, Module, ModuleDef, ScopeDef, Static, Struct, 46 ImplBlock, Import, Local, MacroDef, Module, ModuleDef, ScopeDef, Static, Struct,
47 StructField, Trait, Type, TypeAlias, Union, VariantDef, 47 StructField, Trait, Type, TypeAlias, TypeParam, Union, VariantDef,
48 }, 48 },
49 from_source::FromSource, 49 from_source::FromSource,
50 source_binder::{PathResolution, ScopeEntryWithSyntax, SourceAnalyzer}, 50 source_binder::{PathResolution, ScopeEntryWithSyntax, SourceAnalyzer},
diff --git a/crates/ra_hir/src/source_binder.rs b/crates/ra_hir/src/source_binder.rs
index 42c392513..c5a920688 100644
--- a/crates/ra_hir/src/source_binder.rs
+++ b/crates/ra_hir/src/source_binder.rs
@@ -21,7 +21,6 @@ use hir_def::{
21}; 21};
22use hir_expand::{ 22use hir_expand::{
23 hygiene::Hygiene, name::AsName, AstId, HirFileId, InFile, MacroCallId, MacroCallKind, 23 hygiene::Hygiene, name::AsName, AstId, HirFileId, InFile, MacroCallId, MacroCallKind,
24 MacroFileKind,
25}; 24};
26use ra_syntax::{ 25use ra_syntax::{
27 ast::{self, AstNode}, 26 ast::{self, AstNode},
@@ -36,8 +35,8 @@ use crate::{
36 method_resolution::{self, implements_trait}, 35 method_resolution::{self, implements_trait},
37 InEnvironment, TraitEnvironment, Ty, 36 InEnvironment, TraitEnvironment, Ty,
38 }, 37 },
39 Adt, AssocItem, Const, DefWithBody, Enum, EnumVariant, FromSource, Function, GenericParam, 38 Adt, AssocItem, Const, DefWithBody, Enum, EnumVariant, FromSource, Function, ImplBlock, Local,
40 Local, MacroDef, Name, Path, ScopeDef, Static, Struct, Trait, Type, TypeAlias, 39 MacroDef, Name, Path, ScopeDef, Static, Struct, Trait, Type, TypeAlias, TypeParam,
41}; 40};
42 41
43fn try_get_resolver_for_node(db: &impl HirDatabase, node: InFile<&SyntaxNode>) -> Option<Resolver> { 42fn try_get_resolver_for_node(db: &impl HirDatabase, node: InFile<&SyntaxNode>) -> Option<Resolver> {
@@ -59,6 +58,10 @@ fn try_get_resolver_for_node(db: &impl HirDatabase, node: InFile<&SyntaxNode>) -
59 let src = node.with_value(it); 58 let src = node.with_value(it);
60 Some(Enum::from_source(db, src)?.id.resolver(db)) 59 Some(Enum::from_source(db, src)?.id.resolver(db))
61 }, 60 },
61 ast::ImplBlock(it) => {
62 let src = node.with_value(it);
63 Some(ImplBlock::from_source(db, src)?.id.resolver(db))
64 },
62 _ => match node.value.kind() { 65 _ => match node.value.kind() {
63 FN_DEF | CONST_DEF | STATIC_DEF => { 66 FN_DEF | CONST_DEF | STATIC_DEF => {
64 let def = def_with_body_from_child_node(db, node)?; 67 let def = def_with_body_from_child_node(db, node)?;
@@ -76,12 +79,13 @@ fn def_with_body_from_child_node(
76 db: &impl HirDatabase, 79 db: &impl HirDatabase,
77 child: InFile<&SyntaxNode>, 80 child: InFile<&SyntaxNode>,
78) -> Option<DefWithBody> { 81) -> Option<DefWithBody> {
79 child.value.ancestors().find_map(|node| { 82 child.cloned().ancestors_with_macros(db).find_map(|node| {
83 let n = &node.value;
80 match_ast! { 84 match_ast! {
81 match node { 85 match n {
82 ast::FnDef(def) => { return Function::from_source(db, child.with_value(def)).map(DefWithBody::from); }, 86 ast::FnDef(def) => { return Function::from_source(db, node.with_value(def)).map(DefWithBody::from); },
83 ast::ConstDef(def) => { return Const::from_source(db, child.with_value(def)).map(DefWithBody::from); }, 87 ast::ConstDef(def) => { return Const::from_source(db, node.with_value(def)).map(DefWithBody::from); },
84 ast::StaticDef(def) => { return Static::from_source(db, child.with_value(def)).map(DefWithBody::from); }, 88 ast::StaticDef(def) => { return Static::from_source(db, node.with_value(def)).map(DefWithBody::from); },
85 _ => { None }, 89 _ => { None },
86 } 90 }
87 } 91 }
@@ -107,7 +111,7 @@ pub enum PathResolution {
107 /// A local binding (only value namespace) 111 /// A local binding (only value namespace)
108 Local(Local), 112 Local(Local),
109 /// A generic parameter 113 /// A generic parameter
110 GenericParam(GenericParam), 114 TypeParam(TypeParam),
111 SelfType(crate::ImplBlock), 115 SelfType(crate::ImplBlock),
112 Macro(MacroDef), 116 Macro(MacroDef),
113 AssocItem(crate::AssocItem), 117 AssocItem(crate::AssocItem),
@@ -135,8 +139,8 @@ pub struct ReferenceDescriptor {
135 pub name: String, 139 pub name: String,
136} 140}
137 141
142#[derive(Debug)]
138pub struct Expansion { 143pub struct Expansion {
139 macro_file_kind: MacroFileKind,
140 macro_call_id: MacroCallId, 144 macro_call_id: MacroCallId,
141} 145}
142 146
@@ -151,7 +155,7 @@ impl Expansion {
151 } 155 }
152 156
153 pub fn file_id(&self) -> HirFileId { 157 pub fn file_id(&self) -> HirFileId {
154 self.macro_call_id.as_file(self.macro_file_kind) 158 self.macro_call_id.as_file()
155 } 159 }
156} 160}
157 161
@@ -260,10 +264,7 @@ impl SourceAnalyzer {
260 ) -> Option<PathResolution> { 264 ) -> Option<PathResolution> {
261 let types = self.resolver.resolve_path_in_type_ns_fully(db, &path).map(|ty| match ty { 265 let types = self.resolver.resolve_path_in_type_ns_fully(db, &path).map(|ty| match ty {
262 TypeNs::SelfType(it) => PathResolution::SelfType(it.into()), 266 TypeNs::SelfType(it) => PathResolution::SelfType(it.into()),
263 TypeNs::GenericParam(idx) => PathResolution::GenericParam(GenericParam { 267 TypeNs::GenericParam(id) => PathResolution::TypeParam(TypeParam { id }),
264 parent: self.resolver.generic_def().unwrap(),
265 idx,
266 }),
267 TypeNs::AdtSelfType(it) | TypeNs::AdtId(it) => { 268 TypeNs::AdtSelfType(it) | TypeNs::AdtId(it) => {
268 PathResolution::Def(Adt::from(it).into()) 269 PathResolution::Def(Adt::from(it).into())
269 } 270 }
@@ -335,10 +336,7 @@ impl SourceAnalyzer {
335 resolver::ScopeDef::PerNs(it) => it.into(), 336 resolver::ScopeDef::PerNs(it) => it.into(),
336 resolver::ScopeDef::ImplSelfType(it) => ScopeDef::ImplSelfType(it.into()), 337 resolver::ScopeDef::ImplSelfType(it) => ScopeDef::ImplSelfType(it.into()),
337 resolver::ScopeDef::AdtSelfType(it) => ScopeDef::AdtSelfType(it.into()), 338 resolver::ScopeDef::AdtSelfType(it) => ScopeDef::AdtSelfType(it.into()),
338 resolver::ScopeDef::GenericParam(idx) => { 339 resolver::ScopeDef::GenericParam(id) => ScopeDef::GenericParam(TypeParam { id }),
339 let parent = self.resolver.generic_def().unwrap();
340 ScopeDef::GenericParam(GenericParam { parent, idx })
341 }
342 resolver::ScopeDef::Local(pat_id) => { 340 resolver::ScopeDef::Local(pat_id) => {
343 let parent = self.resolver.body_owner().unwrap().into(); 341 let parent = self.resolver.body_owner().unwrap().into();
344 ScopeDef::Local(Local { parent, pat_id }) 342 ScopeDef::Local(Local { parent, pat_id })
@@ -456,10 +454,7 @@ impl SourceAnalyzer {
456 macro_call.file_id, 454 macro_call.file_id,
457 db.ast_id_map(macro_call.file_id).ast_id(macro_call.value), 455 db.ast_id_map(macro_call.file_id).ast_id(macro_call.value),
458 ); 456 );
459 Some(Expansion { 457 Some(Expansion { macro_call_id: def.as_call_id(db, MacroCallKind::FnLike(ast_id)) })
460 macro_call_id: def.as_call_id(db, MacroCallKind::FnLike(ast_id)),
461 macro_file_kind: to_macro_file_kind(macro_call.value),
462 })
463 } 458 }
464} 459}
465 460
@@ -543,35 +538,3 @@ fn adjust(
543 }) 538 })
544 .map(|(_ptr, scope)| *scope) 539 .map(|(_ptr, scope)| *scope)
545} 540}
546
547/// Given a `ast::MacroCall`, return what `MacroKindFile` it belongs to.
548/// FIXME: Not completed
549fn to_macro_file_kind(macro_call: &ast::MacroCall) -> MacroFileKind {
550 let syn = macro_call.syntax();
551 let parent = match syn.parent() {
552 Some(it) => it,
553 None => {
554 // FIXME:
555 // If it is root, which means the parent HirFile
556 // MacroKindFile must be non-items
557 // return expr now.
558 return MacroFileKind::Expr;
559 }
560 };
561
562 match parent.kind() {
563 MACRO_ITEMS | SOURCE_FILE => MacroFileKind::Items,
564 LET_STMT => {
565 // FIXME: Handle Pattern
566 MacroFileKind::Expr
567 }
568 EXPR_STMT => MacroFileKind::Statements,
569 BLOCK => MacroFileKind::Statements,
570 ARG_LIST => MacroFileKind::Expr,
571 TRY_EXPR => MacroFileKind::Expr,
572 _ => {
573 // Unknown , Just guess it is `Items`
574 MacroFileKind::Items
575 }
576 }
577}