From 762ec9581a4331a2726cc236c565323d0c8cdb07 Mon Sep 17 00:00:00 2001 From: Fedor Sakharov Date: Mon, 11 May 2020 12:25:18 +0300 Subject: [PATCH] Find references to a function outside module --- crates/ra_ide/src/references.rs | 25 +++++++++++++++++++++++++ crates/ra_ide_db/src/defs.rs | 1 + 2 files changed, 26 insertions(+) diff --git a/crates/ra_ide/src/references.rs b/crates/ra_ide/src/references.rs index 555ccf2952d..074284b42e2 100644 --- a/crates/ra_ide/src/references.rs +++ b/crates/ra_ide/src/references.rs @@ -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() diff --git a/crates/ra_ide_db/src/defs.rs b/crates/ra_ide_db/src/defs.rs index f990e3bb97d..c74daff383f 100644 --- a/crates/ra_ide_db/src/defs.rs +++ b/crates/ra_ide_db/src/defs.rs @@ -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,