aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2019-11-15 22:36:10 +0000
committerGitHub <[email protected]>2019-11-15 22:36:10 +0000
commit69f3b01dc5dd70d9bdf6de4d859ad593a689395d (patch)
treec847ded853cea83c2f64c6ffc20d1ad4138613fb /crates/ra_hir
parentad10c4b8e2d81af7fc35a466cd434e2c3952bfd8 (diff)
parent06984ed1164d7607f89f9a6f4893dd05ec058a99 (diff)
Merge #2268
2268: Handle ast::MacroCall in classify_name and impl FromSource for MacroDef r=matklad a=kjeremy Fixes #2260 Co-authored-by: kjeremy <[email protected]>
Diffstat (limited to 'crates/ra_hir')
-rw-r--r--crates/ra_hir/src/from_source.rs23
1 files changed, 19 insertions, 4 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
3use hir_def::{ModuleId, StructId, StructOrUnionId, UnionId}; 3use hir_def::{ModuleId, StructId, StructOrUnionId, UnionId};
4use hir_expand::name::AsName; 4use hir_expand::{name::AsName, AstId, MacroDefId, MacroDefKind};
5use ra_syntax::{ 5use 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
18pub trait FromSource: Sized { 18pub 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
81impl 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
82impl FromSource for ImplBlock { 97impl FromSource for ImplBlock {
83 type Ast = ast::ImplBlock; 98 type Ast = ast::ImplBlock;