mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-02 06:41:48 +00:00
classify module from declaration
This commit is contained in:
parent
93c179531b
commit
55e1910d00
4 changed files with 44 additions and 9 deletions
|
@ -232,7 +232,7 @@ mod tests {
|
|||
}
|
||||
|
||||
#[test]
|
||||
fn test_find_all_refs_modules() {
|
||||
fn test_find_all_refs_two_modules() {
|
||||
let code = r#"
|
||||
//- /lib.rs
|
||||
pub mod foo;
|
||||
|
@ -270,6 +270,33 @@ mod tests {
|
|||
assert_eq!(refs.len(), 3);
|
||||
}
|
||||
|
||||
|
||||
// `mod foo;` is not in the results because `foo` is an `ast::Name`.
|
||||
// So, there are two references: the first one is a definition of the `foo` module,
|
||||
// which is the whole `foo.rs`, and the second one is in `use foo::Foo`.
|
||||
#[test]
|
||||
fn test_find_all_refs_decl_module() {
|
||||
let code = r#"
|
||||
//- /lib.rs
|
||||
mod foo<|>;
|
||||
|
||||
use foo::Foo;
|
||||
|
||||
fn f() {
|
||||
let i = Foo { n: 5 };
|
||||
}
|
||||
|
||||
//- /foo.rs
|
||||
pub struct Foo {
|
||||
pub n: u32,
|
||||
}
|
||||
"#;
|
||||
|
||||
let (analysis, pos) = analysis_and_position(code);
|
||||
let refs = analysis.find_all_refs(pos).unwrap().unwrap();
|
||||
assert_eq!(refs.len(), 2);
|
||||
}
|
||||
|
||||
fn get_all_refs(text: &str) -> ReferenceSearchResult {
|
||||
let (analysis, position) = single_file_with_position(text);
|
||||
analysis.find_all_refs(position).unwrap().unwrap()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue