aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock1
-rw-r--r--crates/ra_ide/Cargo.toml1
-rw-r--r--crates/ra_ide/src/goto_definition.rs41
3 files changed, 35 insertions, 8 deletions
diff --git a/Cargo.lock b/Cargo.lock
index a3cfe5dc4..de7337be1 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1130,6 +1130,7 @@ name = "ra_ide"
1130version = "0.1.0" 1130version = "0.1.0"
1131dependencies = [ 1131dependencies = [
1132 "either", 1132 "either",
1133 "expect",
1133 "indexmap", 1134 "indexmap",
1134 "insta", 1135 "insta",
1135 "itertools", 1136 "itertools",
diff --git a/crates/ra_ide/Cargo.toml b/crates/ra_ide/Cargo.toml
index bbc6a5c9b..8e8892309 100644
--- a/crates/ra_ide/Cargo.toml
+++ b/crates/ra_ide/Cargo.toml
@@ -28,6 +28,7 @@ ra_cfg = { path = "../ra_cfg" }
28ra_fmt = { path = "../ra_fmt" } 28ra_fmt = { path = "../ra_fmt" }
29ra_prof = { path = "../ra_prof" } 29ra_prof = { path = "../ra_prof" }
30test_utils = { path = "../test_utils" } 30test_utils = { path = "../test_utils" }
31expect = { path = "../expect" }
31ra_assists = { path = "../ra_assists" } 32ra_assists = { path = "../ra_assists" }
32ra_ssr = { path = "../ra_ssr" } 33ra_ssr = { path = "../ra_ssr" }
33 34
diff --git a/crates/ra_ide/src/goto_definition.rs b/crates/ra_ide/src/goto_definition.rs
index bea7fbfa7..969d5e0ff 100644
--- a/crates/ra_ide/src/goto_definition.rs
+++ b/crates/ra_ide/src/goto_definition.rs
@@ -103,6 +103,7 @@ pub(crate) fn reference_definition(
103 103
104#[cfg(test)] 104#[cfg(test)]
105mod tests { 105mod tests {
106 use expect::{expect, Expect};
106 use test_utils::assert_eq_text; 107 use test_utils::assert_eq_text;
107 108
108 use crate::mock_analysis::analysis_and_position; 109 use crate::mock_analysis::analysis_and_position;
@@ -142,16 +143,40 @@ mod tests {
142 nav.assert_match(expected); 143 nav.assert_match(expected);
143 } 144 }
144 145
146 fn check(ra_fixture: &str, expect: Expect) {
147 let (analysis, pos) = analysis_and_position(ra_fixture);
148
149 let mut navs = analysis.goto_definition(pos).unwrap().unwrap().info;
150 if navs.len() == 0 {
151 panic!("unresolved reference")
152 }
153 assert_eq!(navs.len(), 1);
154
155 let nav = navs.pop().unwrap();
156 let file_text = analysis.file_text(nav.file_id()).unwrap();
157
158 let mut actual = nav.debug_render();
159 actual += "\n";
160 actual += &file_text[nav.full_range()].to_string();
161 if let Some(focus) = nav.focus_range() {
162 actual += "|";
163 actual += &file_text[focus];
164 actual += "\n";
165 }
166 expect.assert_eq(&actual);
167 }
168
145 #[test] 169 #[test]
146 fn goto_def_in_items() { 170 fn goto_def_in_items() {
147 check_goto( 171 check(
148 " 172 r#"
149 //- /lib.rs 173struct Foo;
150 struct Foo; 174enum E { X(Foo<|>) }
151 enum E { X(Foo<|>) } 175"#,
152 ", 176 expect![[r#"
153 "Foo STRUCT_DEF FileId(1) 0..11 7..10", 177 Foo STRUCT_DEF FileId(1) 0..11 7..10
154 "struct Foo;|Foo", 178 struct Foo;|Foo
179 "#]],
155 ); 180 );
156 } 181 }
157 182