mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 21:05:02 +00:00
inline goto_defention tests
This commit is contained in:
parent
c2a0f5e50f
commit
da32463cbf
3 changed files with 58 additions and 66 deletions
|
@ -78,3 +78,61 @@ fn name_defenition(
|
||||||
}
|
}
|
||||||
Ok(None)
|
Ok(None)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use test_utils::assert_eq_dbg;
|
||||||
|
use crate::mock_analysis::analysis_and_position;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn goto_defenition_works_in_items() {
|
||||||
|
let (analysis, pos) = analysis_and_position(
|
||||||
|
"
|
||||||
|
//- /lib.rs
|
||||||
|
struct Foo;
|
||||||
|
enum E { X(Foo<|>) }
|
||||||
|
",
|
||||||
|
);
|
||||||
|
|
||||||
|
let symbols = analysis.goto_defenition(pos).unwrap().unwrap();
|
||||||
|
assert_eq_dbg(
|
||||||
|
r#"[NavigationTarget { file_id: FileId(1), name: "Foo",
|
||||||
|
kind: STRUCT_DEF, range: [0; 11),
|
||||||
|
ptr: Some(LocalSyntaxPtr { range: [0; 11), kind: STRUCT_DEF }) }]"#,
|
||||||
|
&symbols,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn goto_defenition_works_for_module_declaration() {
|
||||||
|
let (analysis, pos) = analysis_and_position(
|
||||||
|
"
|
||||||
|
//- /lib.rs
|
||||||
|
mod <|>foo;
|
||||||
|
//- /foo.rs
|
||||||
|
// empty
|
||||||
|
",
|
||||||
|
);
|
||||||
|
|
||||||
|
let symbols = analysis.goto_defenition(pos).unwrap().unwrap();
|
||||||
|
assert_eq_dbg(
|
||||||
|
r#"[NavigationTarget { file_id: FileId(2), name: "foo", kind: MODULE, range: [0; 0), ptr: None }]"#,
|
||||||
|
&symbols,
|
||||||
|
);
|
||||||
|
|
||||||
|
let (analysis, pos) = analysis_and_position(
|
||||||
|
"
|
||||||
|
//- /lib.rs
|
||||||
|
mod <|>foo;
|
||||||
|
//- /foo/mod.rs
|
||||||
|
// empty
|
||||||
|
",
|
||||||
|
);
|
||||||
|
|
||||||
|
let symbols = analysis.goto_defenition(pos).unwrap().unwrap();
|
||||||
|
assert_eq_dbg(
|
||||||
|
r#"[NavigationTarget { file_id: FileId(2), name: "foo", kind: MODULE, range: [0; 0), ptr: None }]"#,
|
||||||
|
&symbols,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -399,13 +399,6 @@ impl Analysis {
|
||||||
) -> Cancelable<Option<Vec<NavigationTarget>>> {
|
) -> Cancelable<Option<Vec<NavigationTarget>>> {
|
||||||
goto_defenition::goto_defenition(&*self.db, position)
|
goto_defenition::goto_defenition(&*self.db, position)
|
||||||
}
|
}
|
||||||
// /// Resolves reference to definition, but does not gurantee correctness.
|
|
||||||
// pub fn approximately_resolve_symbol(
|
|
||||||
// &self,
|
|
||||||
// position: FilePosition,
|
|
||||||
// ) -> Cancelable<Option<ReferenceResolution>> {
|
|
||||||
// self.db.approximately_resolve_symbol(position)
|
|
||||||
// }
|
|
||||||
/// Finds all usages of the reference at point.
|
/// Finds all usages of the reference at point.
|
||||||
pub fn find_all_refs(&self, position: FilePosition) -> Cancelable<Vec<(FileId, TextRange)>> {
|
pub fn find_all_refs(&self, position: FilePosition) -> Cancelable<Vec<(FileId, TextRange)>> {
|
||||||
self.db.find_all_refs(position)
|
self.db.find_all_refs(position)
|
||||||
|
|
|
@ -14,65 +14,6 @@ fn get_signature(text: &str) -> (FnSignatureInfo, Option<usize>) {
|
||||||
analysis.resolve_callable(position).unwrap().unwrap()
|
analysis.resolve_callable(position).unwrap().unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn approximate_resolve_works_in_items() {
|
|
||||||
let (analysis, pos) = analysis_and_position(
|
|
||||||
"
|
|
||||||
//- /lib.rs
|
|
||||||
struct Foo;
|
|
||||||
enum E { X(Foo<|>) }
|
|
||||||
",
|
|
||||||
);
|
|
||||||
|
|
||||||
let symbols = analysis.approximately_resolve_symbol(pos).unwrap().unwrap();
|
|
||||||
assert_eq_dbg(
|
|
||||||
r#"ReferenceResolution {
|
|
||||||
reference_range: [23; 26),
|
|
||||||
resolves_to: [NavigationTarget { file_id: FileId(1), name: "Foo", kind: STRUCT_DEF, range: [0; 11), ptr: Some(LocalSyntaxPtr { range: [0; 11), kind: STRUCT_DEF }) }]
|
|
||||||
}"#,
|
|
||||||
&symbols,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_resolve_module() {
|
|
||||||
let (analysis, pos) = analysis_and_position(
|
|
||||||
"
|
|
||||||
//- /lib.rs
|
|
||||||
mod <|>foo;
|
|
||||||
//- /foo.rs
|
|
||||||
// empty
|
|
||||||
",
|
|
||||||
);
|
|
||||||
|
|
||||||
let symbols = analysis.approximately_resolve_symbol(pos).unwrap().unwrap();
|
|
||||||
assert_eq_dbg(
|
|
||||||
r#"ReferenceResolution {
|
|
||||||
reference_range: [4; 7),
|
|
||||||
resolves_to: [NavigationTarget { file_id: FileId(2), name: "foo", kind: MODULE, range: [0; 0), ptr: None }]
|
|
||||||
}"#,
|
|
||||||
&symbols,
|
|
||||||
);
|
|
||||||
|
|
||||||
let (analysis, pos) = analysis_and_position(
|
|
||||||
"
|
|
||||||
//- /lib.rs
|
|
||||||
mod <|>foo;
|
|
||||||
//- /foo/mod.rs
|
|
||||||
// empty
|
|
||||||
",
|
|
||||||
);
|
|
||||||
|
|
||||||
let symbols = analysis.approximately_resolve_symbol(pos).unwrap().unwrap();
|
|
||||||
assert_eq_dbg(
|
|
||||||
r#"ReferenceResolution {
|
|
||||||
reference_range: [4; 7),
|
|
||||||
resolves_to: [NavigationTarget { file_id: FileId(2), name: "foo", kind: MODULE, range: [0; 0), ptr: None }]
|
|
||||||
}"#,
|
|
||||||
&symbols,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_unresolved_module_diagnostic() {
|
fn test_unresolved_module_diagnostic() {
|
||||||
let (analysis, file_id) = single_file("mod foo;");
|
let (analysis, file_id) = single_file("mod foo;");
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue