Find references to a function outside module

This commit is contained in:
Fedor Sakharov 2020-05-11 12:25:18 +03:00
parent 4578154b60
commit 762ec9581a
No known key found for this signature in database
GPG key ID: 93D436E666BF0FEE
2 changed files with 26 additions and 0 deletions

View file

@ -593,6 +593,31 @@ mod tests {
check_result(refs, "i BIND_PAT FileId(1) 36..37 Other", &["FileId(1) 51..52 Other Write"]);
}
#[test]
fn test_find_struct_function_refs_outside_module() {
let code = r#"
mod foo {
pub struct Foo;
impl Foo {
pub fn new<|>() -> Foo {
Foo
}
}
}
fn main() {
let _f = foo::Foo::new();
}"#;
let refs = get_all_refs(code);
check_result(
refs,
"new FN_DEF FileId(1) 87..150 94..97 Other",
&["FileId(1) 227..230 StructLiteral"],
);
}
fn get_all_refs(text: &str) -> ReferenceSearchResult {
let (analysis, position) = single_file_with_position(text);
analysis.find_all_refs(position, None).unwrap().unwrap()

View file

@ -52,6 +52,7 @@ impl Definition {
let parent = id.parent_enum(db);
module?.visibility_of(db, &ModuleDef::Adt(Adt::Enum(parent)))
}
ModuleDef::Function(f) => Some(f.visibility(db)),
_ => module?.visibility_of(db, def),
},
Definition::SelfType(_) => None,