diff options
-rw-r--r-- | crates/ra_hir/src/from_source.rs | 23 | ||||
-rw-r--r-- | crates/ra_ide_api/src/references/classify.rs | 14 |
2 files changed, 32 insertions, 5 deletions
diff --git a/crates/ra_hir/src/from_source.rs b/crates/ra_hir/src/from_source.rs index 79152a57c..1c26756c9 100644 --- a/crates/ra_hir/src/from_source.rs +++ b/crates/ra_hir/src/from_source.rs | |||
@@ -1,7 +1,7 @@ | |||
1 | //! FIXME: write short doc here | 1 | //! FIXME: write short doc here |
2 | 2 | ||
3 | use hir_def::{ModuleId, StructId, StructOrUnionId, UnionId}; | 3 | use hir_def::{ModuleId, StructId, StructOrUnionId, UnionId}; |
4 | use hir_expand::name::AsName; | 4 | use hir_expand::{name::AsName, AstId, MacroDefId, MacroDefKind}; |
5 | use ra_syntax::{ | 5 | use ra_syntax::{ |
6 | ast::{self, AstNode, NameOwner}, | 6 | ast::{self, AstNode, NameOwner}, |
7 | match_ast, | 7 | match_ast, |
@@ -11,8 +11,8 @@ use crate::{ | |||
11 | db::{AstDatabase, DefDatabase, HirDatabase}, | 11 | db::{AstDatabase, DefDatabase, HirDatabase}, |
12 | ids::{AstItemDef, LocationCtx}, | 12 | ids::{AstItemDef, LocationCtx}, |
13 | Const, DefWithBody, Enum, EnumVariant, FieldSource, Function, HasBody, HasSource, ImplBlock, | 13 | Const, DefWithBody, Enum, EnumVariant, FieldSource, Function, HasBody, HasSource, ImplBlock, |
14 | Local, Module, ModuleSource, Source, Static, Struct, StructField, Trait, TypeAlias, Union, | 14 | Local, MacroDef, Module, ModuleSource, Source, Static, Struct, StructField, Trait, TypeAlias, |
15 | VariantDef, | 15 | Union, VariantDef, |
16 | }; | 16 | }; |
17 | 17 | ||
18 | pub trait FromSource: Sized { | 18 | pub trait FromSource: Sized { |
@@ -77,7 +77,22 @@ impl FromSource for TypeAlias { | |||
77 | Some(TypeAlias { id }) | 77 | Some(TypeAlias { id }) |
78 | } | 78 | } |
79 | } | 79 | } |
80 | // FIXME: add impl FromSource for MacroDef | 80 | |
81 | impl FromSource for MacroDef { | ||
82 | type Ast = ast::MacroCall; | ||
83 | fn from_source(db: &(impl DefDatabase + AstDatabase), src: Source<Self::Ast>) -> Option<Self> { | ||
84 | let kind = MacroDefKind::Declarative; | ||
85 | |||
86 | let module_src = ModuleSource::from_child_node(db, src.as_ref().map(|it| it.syntax())); | ||
87 | let module = Module::from_definition(db, Source::new(src.file_id, module_src))?; | ||
88 | let krate = module.krate().crate_id(); | ||
89 | |||
90 | let ast_id = AstId::new(src.file_id, db.ast_id_map(src.file_id).ast_id(&src.ast)); | ||
91 | |||
92 | let id: MacroDefId = MacroDefId { krate, ast_id, kind }; | ||
93 | Some(MacroDef { id }) | ||
94 | } | ||
95 | } | ||
81 | 96 | ||
82 | impl FromSource for ImplBlock { | 97 | impl FromSource for ImplBlock { |
83 | type Ast = ast::ImplBlock; | 98 | type Ast = ast::ImplBlock; |
diff --git a/crates/ra_ide_api/src/references/classify.rs b/crates/ra_ide_api/src/references/classify.rs index b5e35e29f..0eeaa7f38 100644 --- a/crates/ra_ide_api/src/references/classify.rs +++ b/crates/ra_ide_api/src/references/classify.rs | |||
@@ -21,7 +21,6 @@ pub(crate) fn classify_name( | |||
21 | let parent = name.syntax().parent()?; | 21 | let parent = name.syntax().parent()?; |
22 | let file_id = file_id.into(); | 22 | let file_id = file_id.into(); |
23 | 23 | ||
24 | // FIXME: add ast::MacroCall(it) | ||
25 | match_ast! { | 24 | match_ast! { |
26 | match parent { | 25 | match parent { |
27 | ast::BindPat(it) => { | 26 | ast::BindPat(it) => { |
@@ -104,6 +103,19 @@ pub(crate) fn classify_name( | |||
104 | Some(from_module_def(db, def.into(), None)) | 103 | Some(from_module_def(db, def.into(), None)) |
105 | } | 104 | } |
106 | }, | 105 | }, |
106 | ast::MacroCall(it) => { | ||
107 | let src = hir::Source { file_id, ast: it}; | ||
108 | let def = hir::MacroDef::from_source(db, src.clone())?; | ||
109 | |||
110 | let module_src = ModuleSource::from_child_node(db, src.as_ref().map(|it| it.syntax())); | ||
111 | let module = Module::from_definition(db, Source::new(file_id, module_src))?; | ||
112 | |||
113 | Some(NameDefinition { | ||
114 | visibility: None, | ||
115 | container: module, | ||
116 | kind: NameKind::Macro(def), | ||
117 | }) | ||
118 | }, | ||
107 | _ => None, | 119 | _ => None, |
108 | } | 120 | } |
109 | } | 121 | } |