aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_analysis/src
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-01-05 16:41:43 +0000
committerAleksey Kladov <[email protected]>2019-01-05 16:41:43 +0000
commitda32463cbf8dc32229eb13844c71a40df2d3b77e (patch)
treeb64b08018711ef6021a1ad00c4246d10cfdc44e0 /crates/ra_analysis/src
parentc2a0f5e50f6deb2e15bbfa6056a3cc0866c203a5 (diff)
inline goto_defention tests
Diffstat (limited to 'crates/ra_analysis/src')
-rw-r--r--crates/ra_analysis/src/goto_defenition.rs58
-rw-r--r--crates/ra_analysis/src/lib.rs7
2 files changed, 58 insertions, 7 deletions
diff --git a/crates/ra_analysis/src/goto_defenition.rs b/crates/ra_analysis/src/goto_defenition.rs
index 91de7ef65..08d1809ee 100644
--- a/crates/ra_analysis/src/goto_defenition.rs
+++ b/crates/ra_analysis/src/goto_defenition.rs
@@ -78,3 +78,61 @@ fn name_defenition(
78 } 78 }
79 Ok(None) 79 Ok(None)
80} 80}
81
82#[cfg(test)]
83mod tests {
84 use test_utils::assert_eq_dbg;
85 use crate::mock_analysis::analysis_and_position;
86
87 #[test]
88 fn goto_defenition_works_in_items() {
89 let (analysis, pos) = analysis_and_position(
90 "
91 //- /lib.rs
92 struct Foo;
93 enum E { X(Foo<|>) }
94 ",
95 );
96
97 let symbols = analysis.goto_defenition(pos).unwrap().unwrap();
98 assert_eq_dbg(
99 r#"[NavigationTarget { file_id: FileId(1), name: "Foo",
100 kind: STRUCT_DEF, range: [0; 11),
101 ptr: Some(LocalSyntaxPtr { range: [0; 11), kind: STRUCT_DEF }) }]"#,
102 &symbols,
103 );
104 }
105
106 #[test]
107 fn goto_defenition_works_for_module_declaration() {
108 let (analysis, pos) = analysis_and_position(
109 "
110 //- /lib.rs
111 mod <|>foo;
112 //- /foo.rs
113 // empty
114 ",
115 );
116
117 let symbols = analysis.goto_defenition(pos).unwrap().unwrap();
118 assert_eq_dbg(
119 r#"[NavigationTarget { file_id: FileId(2), name: "foo", kind: MODULE, range: [0; 0), ptr: None }]"#,
120 &symbols,
121 );
122
123 let (analysis, pos) = analysis_and_position(
124 "
125 //- /lib.rs
126 mod <|>foo;
127 //- /foo/mod.rs
128 // empty
129 ",
130 );
131
132 let symbols = analysis.goto_defenition(pos).unwrap().unwrap();
133 assert_eq_dbg(
134 r#"[NavigationTarget { file_id: FileId(2), name: "foo", kind: MODULE, range: [0; 0), ptr: None }]"#,
135 &symbols,
136 );
137 }
138}
diff --git a/crates/ra_analysis/src/lib.rs b/crates/ra_analysis/src/lib.rs
index 0dac9f268..13527e628 100644
--- a/crates/ra_analysis/src/lib.rs
+++ b/crates/ra_analysis/src/lib.rs
@@ -399,13 +399,6 @@ impl Analysis {
399 ) -> Cancelable<Option<Vec<NavigationTarget>>> { 399 ) -> Cancelable<Option<Vec<NavigationTarget>>> {
400 goto_defenition::goto_defenition(&*self.db, position) 400 goto_defenition::goto_defenition(&*self.db, position)
401 } 401 }
402 // /// Resolves reference to definition, but does not gurantee correctness.
403 // pub fn approximately_resolve_symbol(
404 // &self,
405 // position: FilePosition,
406 // ) -> Cancelable<Option<ReferenceResolution>> {
407 // self.db.approximately_resolve_symbol(position)
408 // }
409 /// Finds all usages of the reference at point. 402 /// Finds all usages of the reference at point.
410 pub fn find_all_refs(&self, position: FilePosition) -> Cancelable<Vec<(FileId, TextRange)>> { 403 pub fn find_all_refs(&self, position: FilePosition) -> Cancelable<Vec<(FileId, TextRange)>> {
411 self.db.find_all_refs(position) 404 self.db.find_all_refs(position)