From 18f6a995d0fc1f45099f3cc810a5d55d5401b41b Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Thu, 5 Dec 2019 15:10:33 +0100 Subject: Add expansion infrastructure for derive macros --- crates/ra_hir/src/code_model/src.rs | 5 ++++- crates/ra_hir/src/from_source.rs | 4 ++-- crates/ra_hir/src/source_binder.rs | 5 +++-- 3 files changed, 9 insertions(+), 5 deletions(-) (limited to 'crates/ra_hir/src') 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 { impl HasSource for MacroDef { type Ast = ast::MacroCall; fn source(self, db: &impl DefDatabase) -> InFile { - InFile { file_id: self.id.ast_id.file_id, value: self.id.ast_id.to_node(db) } + InFile { + file_id: self.id.ast_id.expect("MacroDef without ast_id").file_id, + value: self.id.ast_id.expect("MacroDef without ast_id").to_node(db), + } } } 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 { let module_src = ModuleSource::from_child_node(db, src.as_ref().map(|it| it.syntax())); let module = Module::from_definition(db, InFile::new(src.file_id, module_src))?; - let krate = module.krate().crate_id(); + let krate = Some(module.krate().crate_id()); - let ast_id = AstId::new(src.file_id, db.ast_id_map(src.file_id).ast_id(&src.value)); + let ast_id = Some(AstId::new(src.file_id, db.ast_id_map(src.file_id).ast_id(&src.value))); let id: MacroDefId = MacroDefId { krate, ast_id, kind }; 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::{ AssocItemId, DefWithBodyId, }; use hir_expand::{ - hygiene::Hygiene, name::AsName, AstId, HirFileId, InFile, MacroCallId, MacroFileKind, + hygiene::Hygiene, name::AsName, AstId, HirFileId, InFile, MacroCallId, MacroCallKind, + MacroFileKind, }; use ra_syntax::{ ast::{self, AstNode}, @@ -456,7 +457,7 @@ impl SourceAnalyzer { db.ast_id_map(macro_call.file_id).ast_id(macro_call.value), ); Some(Expansion { - macro_call_id: def.as_call_id(db, ast_id), + macro_call_id: def.as_call_id(db, MacroCallKind::FnLike(ast_id)), macro_file_kind: to_macro_file_kind(macro_call.value), }) } -- cgit v1.2.3