mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-03 07:04:49 +00:00
Move fn to proc-macro conversion to name classification
This commit is contained in:
parent
cef8a17ea5
commit
0d3cd90d08
3 changed files with 27 additions and 10 deletions
|
@ -1550,14 +1550,27 @@ fn func() {}
|
||||||
|
|
||||||
FileId(0) 16..24
|
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]
|
#[test]
|
||||||
fn derive() {
|
fn derive() {
|
||||||
check(
|
check(
|
||||||
r#"
|
r#"
|
||||||
//- proc_macros: derive_identity
|
//- proc_macros: derive_identity
|
||||||
|
//- minicore: derive
|
||||||
|
|
||||||
#[derive(proc_macros::DeriveIdentity$0)]
|
#[derive(proc_macros::DeriveIdentity$0)]
|
||||||
struct Foo;
|
struct Foo;
|
||||||
|
|
|
@ -225,7 +225,12 @@ impl NameClass {
|
||||||
Definition::Macro(sema.to_def(&ast::Macro::MacroDef(it))?)
|
Definition::Macro(sema.to_def(&ast::Macro::MacroDef(it))?)
|
||||||
}
|
}
|
||||||
ast::Item::Const(it) => Definition::Const(sema.to_def(&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::Module(it) => Definition::Module(sema.to_def(&it)?),
|
||||||
ast::Item::Static(it) => Definition::Static(sema.to_def(&it)?),
|
ast::Item::Static(it) => Definition::Static(sema.to_def(&it)?),
|
||||||
ast::Item::Trait(it) => Definition::Trait(sema.to_def(&it)?),
|
ast::Item::Trait(it) => Definition::Trait(sema.to_def(&it)?),
|
||||||
|
|
|
@ -309,14 +309,13 @@ impl Definition {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn usages<'a>(self, sema: &'a Semantics<RootDatabase>) -> FindUsages<'a> {
|
pub fn usages<'a>(self, sema: &'a Semantics<RootDatabase>) -> FindUsages<'a> {
|
||||||
let def = match self {
|
FindUsages {
|
||||||
def @ Definition::Function(f) => {
|
def: self,
|
||||||
// search for proc-macro usages if this function describes a proc macro
|
sema,
|
||||||
f.as_proc_macro(sema.db).map(Definition::Macro).unwrap_or(def)
|
scope: None,
|
||||||
}
|
include_self_kw_refs: None,
|
||||||
def => def,
|
search_self_mod: false,
|
||||||
};
|
}
|
||||||
FindUsages { def, sema, scope: None, include_self_kw_refs: None, search_self_mod: false }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue