diff options
author | Florian Diebold <[email protected]> | 2019-12-05 14:10:33 +0000 |
---|---|---|
committer | Florian Diebold <[email protected]> | 2019-12-05 16:23:09 +0000 |
commit | 18f6a995d0fc1f45099f3cc810a5d55d5401b41b (patch) | |
tree | 808cb0f025b488f59935007802d1bb85f1cf0044 /crates/ra_hir/src | |
parent | 4c0bd068da39e74c66104206e27c270454e3562e (diff) |
Add expansion infrastructure for derive macros
Diffstat (limited to 'crates/ra_hir/src')
-rw-r--r-- | crates/ra_hir/src/code_model/src.rs | 5 | ||||
-rw-r--r-- | crates/ra_hir/src/from_source.rs | 4 | ||||
-rw-r--r-- | crates/ra_hir/src/source_binder.rs | 5 |
3 files changed, 9 insertions, 5 deletions
diff --git a/crates/ra_hir/src/code_model/src.rs b/crates/ra_hir/src/code_model/src.rs index d9bccd902..78a454082 100644 --- a/crates/ra_hir/src/code_model/src.rs +++ b/crates/ra_hir/src/code_model/src.rs | |||
@@ -105,7 +105,10 @@ impl HasSource for TypeAlias { | |||
105 | impl HasSource for MacroDef { | 105 | impl HasSource for MacroDef { |
106 | type Ast = ast::MacroCall; | 106 | type Ast = ast::MacroCall; |
107 | fn source(self, db: &impl DefDatabase) -> InFile<ast::MacroCall> { | 107 | fn source(self, db: &impl DefDatabase) -> InFile<ast::MacroCall> { |
108 | InFile { file_id: self.id.ast_id.file_id, value: self.id.ast_id.to_node(db) } | 108 | InFile { |
109 | file_id: self.id.ast_id.expect("MacroDef without ast_id").file_id, | ||
110 | value: self.id.ast_id.expect("MacroDef without ast_id").to_node(db), | ||
111 | } | ||
109 | } | 112 | } |
110 | } | 113 | } |
111 | impl HasSource for ImplBlock { | 114 | impl HasSource for ImplBlock { |
diff --git a/crates/ra_hir/src/from_source.rs b/crates/ra_hir/src/from_source.rs index 18d87f6d7..0d3ecbc77 100644 --- a/crates/ra_hir/src/from_source.rs +++ b/crates/ra_hir/src/from_source.rs | |||
@@ -152,9 +152,9 @@ impl FromSource for MacroDef { | |||
152 | 152 | ||
153 | let module_src = ModuleSource::from_child_node(db, src.as_ref().map(|it| it.syntax())); | 153 | let module_src = ModuleSource::from_child_node(db, src.as_ref().map(|it| it.syntax())); |
154 | let module = Module::from_definition(db, InFile::new(src.file_id, module_src))?; | 154 | let module = Module::from_definition(db, InFile::new(src.file_id, module_src))?; |
155 | let krate = module.krate().crate_id(); | 155 | let krate = Some(module.krate().crate_id()); |
156 | 156 | ||
157 | let ast_id = AstId::new(src.file_id, db.ast_id_map(src.file_id).ast_id(&src.value)); | 157 | let ast_id = Some(AstId::new(src.file_id, db.ast_id_map(src.file_id).ast_id(&src.value))); |
158 | 158 | ||
159 | let id: MacroDefId = MacroDefId { krate, ast_id, kind }; | 159 | let id: MacroDefId = MacroDefId { krate, ast_id, kind }; |
160 | Some(MacroDef { id }) | 160 | Some(MacroDef { id }) |
diff --git a/crates/ra_hir/src/source_binder.rs b/crates/ra_hir/src/source_binder.rs index db0451059..42c392513 100644 --- a/crates/ra_hir/src/source_binder.rs +++ b/crates/ra_hir/src/source_binder.rs | |||
@@ -20,7 +20,8 @@ use hir_def::{ | |||
20 | AssocItemId, DefWithBodyId, | 20 | AssocItemId, DefWithBodyId, |
21 | }; | 21 | }; |
22 | use hir_expand::{ | 22 | use hir_expand::{ |
23 | hygiene::Hygiene, name::AsName, AstId, HirFileId, InFile, MacroCallId, MacroFileKind, | 23 | hygiene::Hygiene, name::AsName, AstId, HirFileId, InFile, MacroCallId, MacroCallKind, |
24 | MacroFileKind, | ||
24 | }; | 25 | }; |
25 | use ra_syntax::{ | 26 | use ra_syntax::{ |
26 | ast::{self, AstNode}, | 27 | ast::{self, AstNode}, |
@@ -456,7 +457,7 @@ impl SourceAnalyzer { | |||
456 | db.ast_id_map(macro_call.file_id).ast_id(macro_call.value), | 457 | db.ast_id_map(macro_call.file_id).ast_id(macro_call.value), |
457 | ); | 458 | ); |
458 | Some(Expansion { | 459 | Some(Expansion { |
459 | macro_call_id: def.as_call_id(db, ast_id), | 460 | macro_call_id: def.as_call_id(db, MacroCallKind::FnLike(ast_id)), |
460 | macro_file_kind: to_macro_file_kind(macro_call.value), | 461 | macro_file_kind: to_macro_file_kind(macro_call.value), |
461 | }) | 462 | }) |
462 | } | 463 | } |