diff options
Diffstat (limited to 'crates/ra_ide')
-rw-r--r-- | crates/ra_ide/Cargo.toml | 1 | ||||
-rw-r--r-- | crates/ra_ide/src/goto_definition.rs | 41 |
2 files changed, 34 insertions, 8 deletions
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" } | |||
28 | ra_fmt = { path = "../ra_fmt" } | 28 | ra_fmt = { path = "../ra_fmt" } |
29 | ra_prof = { path = "../ra_prof" } | 29 | ra_prof = { path = "../ra_prof" } |
30 | test_utils = { path = "../test_utils" } | 30 | test_utils = { path = "../test_utils" } |
31 | expect = { path = "../expect" } | ||
31 | ra_assists = { path = "../ra_assists" } | 32 | ra_assists = { path = "../ra_assists" } |
32 | ra_ssr = { path = "../ra_ssr" } | 33 | ra_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)] |
105 | mod tests { | 105 | mod 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 | 173 | struct Foo; |
150 | struct Foo; | 174 | enum 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 | ||