Move fn to proc-macro conversion to name classification

This commit is contained in:
Lukas Wirth 2022-02-21 17:56:11 +01:00
parent cef8a17ea5
commit 0d3cd90d08
3 changed files with 27 additions and 10 deletions

View File

@ -1550,14 +1550,27 @@ fn func() {}
FileId(0) 16..24
"#]],
)
);
check(
r#"
#[proc_macro_attribute]
fn func$0() {}
"#,
expect![[r#"
func Attribute FileId(0) 0..36 27..31
(no references)
"#]],
);
}
// FIXME
#[test]
fn derive() {
check(
r#"
//- proc_macros: derive_identity
//- minicore: derive
#[derive(proc_macros::DeriveIdentity$0)]
struct Foo;

View File

@ -225,7 +225,12 @@ impl NameClass {
Definition::Macro(sema.to_def(&ast::Macro::MacroDef(it))?)
}
ast::Item::Const(it) => Definition::Const(sema.to_def(&it)?),
ast::Item::Fn(it) => Definition::Function(sema.to_def(&it)?),
ast::Item::Fn(it) => {
let def = sema.to_def(&it)?;
def.as_proc_macro(sema.db)
.map(Definition::Macro)
.unwrap_or(Definition::Function(def))
}
ast::Item::Module(it) => Definition::Module(sema.to_def(&it)?),
ast::Item::Static(it) => Definition::Static(sema.to_def(&it)?),
ast::Item::Trait(it) => Definition::Trait(sema.to_def(&it)?),

View File

@ -309,14 +309,13 @@ impl Definition {
}
pub fn usages<'a>(self, sema: &'a Semantics<RootDatabase>) -> FindUsages<'a> {
let def = match self {
def @ Definition::Function(f) => {
// search for proc-macro usages if this function describes a proc macro
f.as_proc_macro(sema.db).map(Definition::Macro).unwrap_or(def)
}
def => def,
};
FindUsages { def, sema, scope: None, include_self_kw_refs: None, search_self_mod: false }
FindUsages {
def: self,
sema,
scope: None,
include_self_kw_refs: None,
search_self_mod: false,
}
}
}