From 60fd260e7fb8c88cb9037377dc75f901a54bbe20 Mon Sep 17 00:00:00 2001 From: kjeremy Date: Fri, 15 Nov 2019 16:20:00 -0500 Subject: Handle ast::MacroCall in classify_name and impl FromSource for MacroDef Fixes #2260 --- crates/ra_hir/src/from_source.rs | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) (limited to 'crates/ra_hir') 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 @@ //! FIXME: write short doc here use hir_def::{ModuleId, StructId, StructOrUnionId, UnionId}; -use hir_expand::name::AsName; +use hir_expand::{name::AsName, AstId, MacroDefId, MacroDefKind}; use ra_syntax::{ ast::{self, AstNode, NameOwner}, match_ast, @@ -11,8 +11,8 @@ use crate::{ db::{AstDatabase, DefDatabase, HirDatabase}, ids::{AstItemDef, LocationCtx}, Const, DefWithBody, Enum, EnumVariant, FieldSource, Function, HasBody, HasSource, ImplBlock, - Local, Module, ModuleSource, Source, Static, Struct, StructField, Trait, TypeAlias, Union, - VariantDef, + Local, MacroDef, Module, ModuleSource, Source, Static, Struct, StructField, Trait, TypeAlias, + Union, VariantDef, }; pub trait FromSource: Sized { @@ -77,7 +77,22 @@ impl FromSource for TypeAlias { Some(TypeAlias { id }) } } -// FIXME: add impl FromSource for MacroDef + +impl FromSource for MacroDef { + type Ast = ast::MacroCall; + fn from_source(db: &(impl DefDatabase + AstDatabase), src: Source) -> Option { + let kind = MacroDefKind::Declarative; + + let module_src = ModuleSource::from_child_node(db, src.as_ref().map(|it| it.syntax())); + let module = Module::from_definition(db, Source::new(src.file_id, module_src))?; + let krate = module.krate().crate_id(); + + let ast_id = AstId::new(src.file_id, db.ast_id_map(src.file_id).ast_id(&src.ast)); + + let id: MacroDefId = MacroDefId { krate, ast_id, kind }; + Some(MacroDef { id }) + } +} impl FromSource for ImplBlock { type Ast = ast::ImplBlock; -- cgit v1.2.3