aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide/src/goto_definition.rs
diff options
context:
space:
mode:
authorEdwin Cheng <[email protected]>2019-12-14 17:20:07 +0000
committerEdwin Cheng <[email protected]>2019-12-14 17:24:51 +0000
commit61360fdfec981eadef1eefb595c8b32c951771e8 (patch)
tree08e89aa372dd4680569ee4a7788019196d65b375 /crates/ra_ide/src/goto_definition.rs
parent7238037de42a2fd88434930c521b926d7b0026da (diff)
Fix original_source find order
Diffstat (limited to 'crates/ra_ide/src/goto_definition.rs')
-rw-r--r--crates/ra_ide/src/goto_definition.rs34
1 files changed, 26 insertions, 8 deletions
diff --git a/crates/ra_ide/src/goto_definition.rs b/crates/ra_ide/src/goto_definition.rs
index cfe62037f..2c634990d 100644
--- a/crates/ra_ide/src/goto_definition.rs
+++ b/crates/ra_ide/src/goto_definition.rs
@@ -209,7 +209,7 @@ fn named_target(db: &RootDatabase, node: InFile<&SyntaxNode>) -> Option<Navigati
209 209
210#[cfg(test)] 210#[cfg(test)]
211mod tests { 211mod tests {
212 use test_utils::covers; 212 use test_utils::{assert_eq_text, covers};
213 213
214 use crate::mock_analysis::analysis_and_position; 214 use crate::mock_analysis::analysis_and_position;
215 215
@@ -222,6 +222,24 @@ mod tests {
222 nav.assert_match(expected); 222 nav.assert_match(expected);
223 } 223 }
224 224
225 fn check_goto_with_range_content(fixture: &str, expected: &str, expected_range: &str) {
226 let (analysis, pos) = analysis_and_position(fixture);
227
228 let mut navs = analysis.goto_definition(pos).unwrap().unwrap().info;
229 assert_eq!(navs.len(), 1);
230 let nav = navs.pop().unwrap();
231 let file_text = analysis.file_text(pos.file_id).unwrap();
232
233 let actual_full_range = &file_text[nav.full_range()];
234 let actual_range = &file_text[nav.range()];
235
236 test_utils::assert_eq_text!(
237 &format!("{}|{}", actual_full_range, actual_range),
238 expected_range
239 );
240 nav.assert_match(expected);
241 }
242
225 #[test] 243 #[test]
226 fn goto_definition_works_in_items() { 244 fn goto_definition_works_in_items() {
227 check_goto( 245 check_goto(
@@ -339,28 +357,27 @@ mod tests {
339 357
340 #[test] 358 #[test]
341 fn goto_definition_works_for_macro_defined_fn_with_arg() { 359 fn goto_definition_works_for_macro_defined_fn_with_arg() {
342 check_goto( 360 check_goto_with_range_content(
343 " 361 "
344 //- /lib.rs 362 //- /lib.rs
345 macro_rules! define_fn { 363 macro_rules! define_fn {
346 ($name:ident) => (fn $name() {}) 364 ($name:ident) => (fn $name() {})
347 } 365 }
348 366
349 define_fn!( 367 define_fn!(foo);
350 foo
351 )
352 368
353 fn bar() { 369 fn bar() {
354 <|>foo(); 370 <|>foo();
355 } 371 }
356 ", 372 ",
357 "foo FN_DEF FileId(1) [80; 83) [80; 83)", 373 "foo FN_DEF FileId(1) [64; 80) [75; 78)",
374 "define_fn!(foo);|foo",
358 ); 375 );
359 } 376 }
360 377
361 #[test] 378 #[test]
362 fn goto_definition_works_for_macro_defined_fn_no_arg() { 379 fn goto_definition_works_for_macro_defined_fn_no_arg() {
363 check_goto( 380 check_goto_with_range_content(
364 " 381 "
365 //- /lib.rs 382 //- /lib.rs
366 macro_rules! define_fn { 383 macro_rules! define_fn {
@@ -373,7 +390,8 @@ mod tests {
373 <|>foo(); 390 <|>foo();
374 } 391 }
375 ", 392 ",
376 "foo FN_DEF FileId(1) [39; 42) [39; 42)", 393 "foo FN_DEF FileId(1) [51; 64) [51; 64)",
394 "define_fn!();|define_fn!();",
377 ); 395 );
378 } 396 }
379 397