From aa69757a01c26cfad12498053c55cbc3d66a4bdb Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 23 Jun 2020 22:27:24 +0200 Subject: More principled indentation trimming in fixtures --- crates/ra_ide/src/call_hierarchy.rs | 172 ++++++++++----------- .../completion/complete_macro_in_item_position.rs | 16 +- .../src/completion/complete_qualified_path.rs | 112 +++++++------- .../src/completion/complete_unqualified_path.rs | 48 +++--- crates/ra_ide/src/diagnostics.rs | 23 +-- crates/ra_ide/src/goto_definition.rs | 146 ++++++++--------- crates/ra_ide/src/hover.rs | 86 +++++------ crates/ra_ide/src/references.rs | 16 +- crates/ra_ide/src/runnables.rs | 16 +- 9 files changed, 310 insertions(+), 325 deletions(-) (limited to 'crates/ra_ide/src') diff --git a/crates/ra_ide/src/call_hierarchy.rs b/crates/ra_ide/src/call_hierarchy.rs index defd8176f..1e3a31602 100644 --- a/crates/ra_ide/src/call_hierarchy.rs +++ b/crates/ra_ide/src/call_hierarchy.rs @@ -145,12 +145,12 @@ mod tests { use crate::mock_analysis::analysis_and_position; fn check_hierarchy( - fixture: &str, + ra_fixture: &str, expected: &str, expected_incoming: &[&str], expected_outgoing: &[&str], ) { - let (analysis, pos) = analysis_and_position(fixture); + let (analysis, pos) = analysis_and_position(ra_fixture); let mut navs = analysis.call_hierarchy(pos).unwrap().unwrap().info; assert_eq!(navs.len(), 1); @@ -177,12 +177,12 @@ mod tests { fn test_call_hierarchy_on_ref() { check_hierarchy( r#" - //- /lib.rs - fn callee() {} - fn caller() { - call<|>ee(); - } - "#, +//- /lib.rs +fn callee() {} +fn caller() { + call<|>ee(); +} +"#, "callee FN_DEF FileId(1) 0..14 3..9", &["caller FN_DEF FileId(1) 15..44 18..24 : [33..39]"], &[], @@ -193,12 +193,12 @@ mod tests { fn test_call_hierarchy_on_def() { check_hierarchy( r#" - //- /lib.rs - fn call<|>ee() {} - fn caller() { - callee(); - } - "#, +//- /lib.rs +fn call<|>ee() {} +fn caller() { + callee(); +} +"#, "callee FN_DEF FileId(1) 0..14 3..9", &["caller FN_DEF FileId(1) 15..44 18..24 : [33..39]"], &[], @@ -209,13 +209,13 @@ mod tests { fn test_call_hierarchy_in_same_fn() { check_hierarchy( r#" - //- /lib.rs - fn callee() {} - fn caller() { - call<|>ee(); - callee(); - } - "#, +//- /lib.rs +fn callee() {} +fn caller() { + call<|>ee(); + callee(); +} +"#, "callee FN_DEF FileId(1) 0..14 3..9", &["caller FN_DEF FileId(1) 15..58 18..24 : [33..39, 47..53]"], &[], @@ -226,20 +226,20 @@ mod tests { fn test_call_hierarchy_in_different_fn() { check_hierarchy( r#" - //- /lib.rs - fn callee() {} - fn caller1() { - call<|>ee(); - } +//- /lib.rs +fn callee() {} +fn caller1() { + call<|>ee(); +} - fn caller2() { - callee(); - } - "#, +fn caller2() { + callee(); +} +"#, "callee FN_DEF FileId(1) 0..14 3..9", &[ "caller1 FN_DEF FileId(1) 15..45 18..25 : [34..40]", - "caller2 FN_DEF FileId(1) 46..76 49..56 : [65..71]", + "caller2 FN_DEF FileId(1) 47..77 50..57 : [66..72]", ], &[], ); @@ -249,26 +249,26 @@ mod tests { fn test_call_hierarchy_in_tests_mod() { check_hierarchy( r#" - //- /lib.rs cfg:test - fn callee() {} - fn caller1() { - call<|>ee(); - } +//- /lib.rs cfg:test +fn callee() {} +fn caller1() { + call<|>ee(); +} - #[cfg(test)] - mod tests { - use super::*; +#[cfg(test)] +mod tests { + use super::*; - #[test] - fn test_caller() { - callee(); - } - } - "#, + #[test] + fn test_caller() { + callee(); + } +} +"#, "callee FN_DEF FileId(1) 0..14 3..9", &[ "caller1 FN_DEF FileId(1) 15..45 18..25 : [34..40]", - "test_caller FN_DEF FileId(1) 93..147 108..119 : [132..138]", + "test_caller FN_DEF FileId(1) 95..149 110..121 : [134..140]", ], &[], ); @@ -278,19 +278,19 @@ mod tests { fn test_call_hierarchy_in_different_files() { check_hierarchy( r#" - //- /lib.rs - mod foo; - use foo::callee; +//- /lib.rs +mod foo; +use foo::callee; - fn caller() { - call<|>ee(); - } +fn caller() { + call<|>ee(); +} - //- /foo/mod.rs - pub fn callee() {} - "#, +//- /foo/mod.rs +pub fn callee() {} +"#, "callee FN_DEF FileId(2) 0..18 7..13", - &["caller FN_DEF FileId(1) 26..55 29..35 : [44..50]"], + &["caller FN_DEF FileId(1) 27..56 30..36 : [45..51]"], &[], ); } @@ -299,13 +299,13 @@ mod tests { fn test_call_hierarchy_outgoing() { check_hierarchy( r#" - //- /lib.rs - fn callee() {} - fn call<|>er() { - callee(); - callee(); - } - "#, +//- /lib.rs +fn callee() {} +fn call<|>er() { + callee(); + callee(); +} +"#, "caller FN_DEF FileId(1) 15..58 18..24", &[], &["callee FN_DEF FileId(1) 0..14 3..9 : [33..39, 47..53]"], @@ -316,20 +316,20 @@ mod tests { fn test_call_hierarchy_outgoing_in_different_files() { check_hierarchy( r#" - //- /lib.rs - mod foo; - use foo::callee; +//- /lib.rs +mod foo; +use foo::callee; - fn call<|>er() { - callee(); - } +fn call<|>er() { + callee(); +} - //- /foo/mod.rs - pub fn callee() {} - "#, - "caller FN_DEF FileId(1) 26..55 29..35", +//- /foo/mod.rs +pub fn callee() {} +"#, + "caller FN_DEF FileId(1) 27..56 30..36", &[], - &["callee FN_DEF FileId(2) 0..18 7..13 : [44..50]"], + &["callee FN_DEF FileId(2) 0..18 7..13 : [45..51]"], ); } @@ -337,22 +337,22 @@ mod tests { fn test_call_hierarchy_incoming_outgoing() { check_hierarchy( r#" - //- /lib.rs - fn caller1() { - call<|>er2(); - } +//- /lib.rs +fn caller1() { + call<|>er2(); +} - fn caller2() { - caller3(); - } +fn caller2() { + caller3(); +} - fn caller3() { +fn caller3() { - } - "#, - "caller2 FN_DEF FileId(1) 32..63 35..42", +} +"#, + "caller2 FN_DEF FileId(1) 33..64 36..43", &["caller1 FN_DEF FileId(1) 0..31 3..10 : [19..26]"], - &["caller3 FN_DEF FileId(1) 64..80 67..74 : [51..58]"], + &["caller3 FN_DEF FileId(1) 66..83 69..76 : [52..59]"], ); } } diff --git a/crates/ra_ide/src/completion/complete_macro_in_item_position.rs b/crates/ra_ide/src/completion/complete_macro_in_item_position.rs index d9bb5fd25..4c33f41d4 100644 --- a/crates/ra_ide/src/completion/complete_macro_in_item_position.rs +++ b/crates/ra_ide/src/completion/complete_macro_in_item_position.rs @@ -42,8 +42,8 @@ mod tests { [ CompletionItem { label: "foo!(…)", - source_range: 46..46, - delete: 46..46, + source_range: 48..48, + delete: 48..48, insert: "foo!($0)", kind: Macro, detail: "macro_rules! foo", @@ -82,8 +82,8 @@ mod tests { [ CompletionItem { label: "vec![…]", - source_range: 280..280, - delete: 280..280, + source_range: 282..282, + delete: 282..282, insert: "vec![$0]", kind: Macro, detail: "macro_rules! vec", @@ -119,8 +119,8 @@ mod tests { [ CompletionItem { label: "foo! {…}", - source_range: 163..163, - delete: 163..163, + source_range: 164..164, + delete: 164..164, insert: "foo! {$0}", kind: Macro, detail: "macro_rules! foo", @@ -130,8 +130,8 @@ mod tests { }, CompletionItem { label: "main()", - source_range: 163..163, - delete: 163..163, + source_range: 164..164, + delete: 164..164, insert: "main()$0", kind: Function, lookup: "main", diff --git a/crates/ra_ide/src/completion/complete_qualified_path.rs b/crates/ra_ide/src/completion/complete_qualified_path.rs index 02ac0166b..d3a1cbc1d 100644 --- a/crates/ra_ide/src/completion/complete_qualified_path.rs +++ b/crates/ra_ide/src/completion/complete_qualified_path.rs @@ -541,8 +541,8 @@ mod tests { [ CompletionItem { label: "m()", - source_range: 100..100, - delete: 100..100, + source_range: 102..102, + delete: 102..102, insert: "m()$0", kind: Function, lookup: "m", @@ -577,8 +577,8 @@ mod tests { [ CompletionItem { label: "m()", - source_range: 105..105, - delete: 105..105, + source_range: 107..107, + delete: 107..107, insert: "m()$0", kind: Method, lookup: "m", @@ -613,8 +613,8 @@ mod tests { [ CompletionItem { label: "C", - source_range: 107..107, - delete: 107..107, + source_range: 109..109, + delete: 109..109, insert: "C", kind: Const, detail: "const C: i32 = 42;", @@ -648,8 +648,8 @@ mod tests { [ CompletionItem { label: "T", - source_range: 101..101, - delete: 101..101, + source_range: 103..103, + delete: 103..103, insert: "T", kind: TypeAlias, detail: "type T = i32;", @@ -688,24 +688,24 @@ mod tests { [ CompletionItem { label: "PUBLIC_CONST", - source_range: 302..302, - delete: 302..302, + source_range: 304..304, + delete: 304..304, insert: "PUBLIC_CONST", kind: Const, detail: "pub(super) const PUBLIC_CONST: u32 = 1;", }, CompletionItem { label: "PublicType", - source_range: 302..302, - delete: 302..302, + source_range: 304..304, + delete: 304..304, insert: "PublicType", kind: TypeAlias, detail: "pub(super) type PublicType = u32;", }, CompletionItem { label: "public_method()", - source_range: 302..302, - delete: 302..302, + source_range: 304..304, + delete: 304..304, insert: "public_method()$0", kind: Function, lookup: "public_method", @@ -737,8 +737,8 @@ mod tests { [ CompletionItem { label: "m()", - source_range: 100..100, - delete: 100..100, + source_range: 102..102, + delete: 102..102, insert: "m()$0", kind: Function, lookup: "m", @@ -773,8 +773,8 @@ mod tests { [ CompletionItem { label: "m()", - source_range: 101..101, - delete: 101..101, + source_range: 103..103, + delete: 103..103, insert: "m()$0", kind: Function, lookup: "m", @@ -834,8 +834,8 @@ mod tests { [ CompletionItem { label: "m()", - source_range: 73..73, - delete: 73..73, + source_range: 74..74, + delete: 74..74, insert: "m()$0", kind: Function, lookup: "m", @@ -870,8 +870,8 @@ mod tests { [ CompletionItem { label: "m()", - source_range: 99..99, - delete: 99..99, + source_range: 101..101, + delete: 101..101, insert: "m()$0", kind: Function, lookup: "m", @@ -906,8 +906,8 @@ mod tests { [ CompletionItem { label: "m()", - source_range: 110..110, - delete: 110..110, + source_range: 112..112, + delete: 112..112, insert: "m()$0", kind: Function, lookup: "m", @@ -950,40 +950,40 @@ mod tests { [ CompletionItem { label: "C2", - source_range: 219..219, - delete: 219..219, + source_range: 221..221, + delete: 221..221, insert: "C2", kind: Const, detail: "const C2: ();", }, CompletionItem { label: "CONST", - source_range: 219..219, - delete: 219..219, + source_range: 221..221, + delete: 221..221, insert: "CONST", kind: Const, detail: "const CONST: u8;", }, CompletionItem { label: "SubTy", - source_range: 219..219, - delete: 219..219, + source_range: 221..221, + delete: 221..221, insert: "SubTy", kind: TypeAlias, detail: "type SubTy;", }, CompletionItem { label: "Ty", - source_range: 219..219, - delete: 219..219, + source_range: 221..221, + delete: 221..221, insert: "Ty", kind: TypeAlias, detail: "type Ty;", }, CompletionItem { label: "func()", - source_range: 219..219, - delete: 219..219, + source_range: 221..221, + delete: 221..221, insert: "func()$0", kind: Function, lookup: "func", @@ -991,8 +991,8 @@ mod tests { }, CompletionItem { label: "method()", - source_range: 219..219, - delete: 219..219, + source_range: 221..221, + delete: 221..221, insert: "method()$0", kind: Method, lookup: "method", @@ -1000,8 +1000,8 @@ mod tests { }, CompletionItem { label: "subfunc()", - source_range: 219..219, - delete: 219..219, + source_range: 221..221, + delete: 221..221, insert: "subfunc()$0", kind: Function, lookup: "subfunc", @@ -1009,8 +1009,8 @@ mod tests { }, CompletionItem { label: "submethod()", - source_range: 219..219, - delete: 219..219, + source_range: 221..221, + delete: 221..221, insert: "submethod()$0", kind: Method, lookup: "submethod", @@ -1055,40 +1055,40 @@ mod tests { [ CompletionItem { label: "C2", - source_range: 365..365, - delete: 365..365, + source_range: 367..367, + delete: 367..367, insert: "C2", kind: Const, detail: "const C2: () = ();", }, CompletionItem { label: "CONST", - source_range: 365..365, - delete: 365..365, + source_range: 367..367, + delete: 367..367, insert: "CONST", kind: Const, detail: "const CONST: u8 = 0;", }, CompletionItem { label: "SubTy", - source_range: 365..365, - delete: 365..365, + source_range: 367..367, + delete: 367..367, insert: "SubTy", kind: TypeAlias, detail: "type SubTy;", }, CompletionItem { label: "Ty", - source_range: 365..365, - delete: 365..365, + source_range: 367..367, + delete: 367..367, insert: "Ty", kind: TypeAlias, detail: "type Ty;", }, CompletionItem { label: "func()", - source_range: 365..365, - delete: 365..365, + source_range: 367..367, + delete: 367..367, insert: "func()$0", kind: Function, lookup: "func", @@ -1096,8 +1096,8 @@ mod tests { }, CompletionItem { label: "method()", - source_range: 365..365, - delete: 365..365, + source_range: 367..367, + delete: 367..367, insert: "method()$0", kind: Method, lookup: "method", @@ -1105,8 +1105,8 @@ mod tests { }, CompletionItem { label: "subfunc()", - source_range: 365..365, - delete: 365..365, + source_range: 367..367, + delete: 367..367, insert: "subfunc()$0", kind: Function, lookup: "subfunc", @@ -1114,8 +1114,8 @@ mod tests { }, CompletionItem { label: "submethod()", - source_range: 365..365, - delete: 365..365, + source_range: 367..367, + delete: 367..367, insert: "submethod()$0", kind: Method, lookup: "submethod", diff --git a/crates/ra_ide/src/completion/complete_unqualified_path.rs b/crates/ra_ide/src/completion/complete_unqualified_path.rs index 68032c37e..aa2b07a2f 100644 --- a/crates/ra_ide/src/completion/complete_unqualified_path.rs +++ b/crates/ra_ide/src/completion/complete_unqualified_path.rs @@ -781,46 +781,46 @@ mod tests { [ CompletionItem { label: "bar!(…)", - source_range: 252..252, - delete: 252..252, + source_range: 256..256, + delete: 256..256, insert: "bar!($0)", kind: Macro, detail: "macro_rules! bar", }, CompletionItem { label: "baz!(…)", - source_range: 252..252, - delete: 252..252, + source_range: 256..256, + delete: 256..256, insert: "baz!($0)", kind: Macro, detail: "#[macro_export]\nmacro_rules! baz", }, CompletionItem { label: "foo!(…)", - source_range: 252..252, - delete: 252..252, + source_range: 256..256, + delete: 256..256, insert: "foo!($0)", kind: Macro, detail: "macro_rules! foo", }, CompletionItem { label: "m1", - source_range: 252..252, - delete: 252..252, + source_range: 256..256, + delete: 256..256, insert: "m1", kind: Module, }, CompletionItem { label: "m2", - source_range: 252..252, - delete: 252..252, + source_range: 256..256, + delete: 256..256, insert: "m2", kind: Module, }, CompletionItem { label: "main()", - source_range: 252..252, - delete: 252..252, + source_range: 256..256, + delete: 256..256, insert: "main()$0", kind: Function, lookup: "main", @@ -850,16 +850,16 @@ mod tests { [ CompletionItem { label: "foo!(…)", - source_range: 49..49, - delete: 49..49, + source_range: 50..50, + delete: 50..50, insert: "foo!($0)", kind: Macro, detail: "macro_rules! foo", }, CompletionItem { label: "foo()", - source_range: 49..49, - delete: 49..49, + source_range: 50..50, + delete: 50..50, insert: "foo()$0", kind: Function, lookup: "foo", @@ -889,16 +889,16 @@ mod tests { [ CompletionItem { label: "foo!(…)", - source_range: 57..57, - delete: 57..57, + source_range: 58..58, + delete: 58..58, insert: "foo!($0)", kind: Macro, detail: "macro_rules! foo", }, CompletionItem { label: "main()", - source_range: 57..57, - delete: 57..57, + source_range: 58..58, + delete: 58..58, insert: "main()$0", kind: Function, lookup: "main", @@ -928,16 +928,16 @@ mod tests { [ CompletionItem { label: "foo!(…)", - source_range: 50..50, - delete: 50..50, + source_range: 51..51, + delete: 51..51, insert: "foo!($0)", kind: Macro, detail: "macro_rules! foo", }, CompletionItem { label: "main()", - source_range: 50..50, - delete: 50..50, + source_range: 51..51, + delete: 51..51, insert: "main()$0", kind: Function, lookup: "main", diff --git a/crates/ra_ide/src/diagnostics.rs b/crates/ra_ide/src/diagnostics.rs index 9bde1db8e..8cb0700b9 100644 --- a/crates/ra_ide/src/diagnostics.rs +++ b/crates/ra_ide/src/diagnostics.rs @@ -283,7 +283,7 @@ fn check_struct_shorthand_initialization( mod tests { use insta::assert_debug_snapshot; use ra_syntax::SourceFile; - use stdx::SepBy; + use stdx::trim_indent; use test_utils::assert_eq_text; use crate::mock_analysis::{analysis_and_position, single_file}; @@ -325,6 +325,8 @@ mod tests { /// * this diagnostic touches the input cursor position /// * that the contents of the file containing the cursor match `after` after the diagnostic fix is applied fn check_apply_diagnostic_fix_from_position(fixture: &str, after: &str) { + let after = trim_indent(after); + let (analysis, file_position) = analysis_and_position(fixture); let diagnostic = analysis.diagnostics(file_position.file_id).unwrap().pop().unwrap(); let mut fix = diagnostic.fix.unwrap(); @@ -336,21 +338,6 @@ mod tests { actual }; - // Strip indent and empty lines from `after`, to match the behaviour of - // `parse_fixture` called from `analysis_and_position`. - let margin = fixture - .lines() - .filter(|it| it.trim_start().starts_with("//-")) - .map(|it| it.len() - it.trim_start().len()) - .next() - .expect("empty fixture"); - let after = after - .lines() - .filter_map(|line| if line.len() > margin { Some(&line[margin..]) } else { None }) - .sep_by("\n") - .suffix("\n") - .to_string(); - assert_eq_text!(&after, &actual); assert!( diagnostic.range.start() <= file_position.offset @@ -400,7 +387,6 @@ mod tests { } x / y<|> } - //- /core/lib.rs pub mod result { pub enum Result { Ok(T), Err(E) } @@ -431,7 +417,6 @@ mod tests { } <|>x } - //- /core/lib.rs pub mod result { pub enum Result { Ok(T), Err(E) } @@ -464,7 +449,6 @@ mod tests { } x <|>/ y } - //- /core/lib.rs pub mod result { pub enum Result { Ok(T), Err(E) } @@ -474,6 +458,7 @@ mod tests { use core::result::Result::{self, Ok, Err}; type MyResult = Result; + fn div(x: i32, y: i32) -> MyResult { if y == 0 { return Err(()); diff --git a/crates/ra_ide/src/goto_definition.rs b/crates/ra_ide/src/goto_definition.rs index 450ce0ba7..bea7fbfa7 100644 --- a/crates/ra_ide/src/goto_definition.rs +++ b/crates/ra_ide/src/goto_definition.rs @@ -192,27 +192,27 @@ mod tests { #[test] fn goto_def_for_module_declaration() { check_goto( - " - //- /lib.rs - mod <|>foo; + r#" +//- /lib.rs +mod <|>foo; - //- /foo.rs - // empty - ", - "foo SOURCE_FILE FileId(2) 0..10", - "// empty\n\n", +//- /foo.rs +// empty +"#, + "foo SOURCE_FILE FileId(2) 0..9", + "// empty\n", ); check_goto( - " - //- /lib.rs - mod <|>foo; + r#" +//- /lib.rs +mod <|>foo; - //- /foo/mod.rs - // empty - ", - "foo SOURCE_FILE FileId(2) 0..10", - "// empty\n\n", +//- /foo/mod.rs +// empty +"#, + "foo SOURCE_FILE FileId(2) 0..9", + "// empty\n", ); } @@ -254,14 +254,14 @@ mod tests { #[test] fn goto_def_for_use_alias() { check_goto( - " - //- /lib.rs - use foo as bar<|>; - + r#" +//- /lib.rs +use foo as bar<|>; - //- /foo/lib.rs - #[macro_export] - macro_rules! foo { () => { () } }", +//- /foo/lib.rs +#[macro_export] +macro_rules! foo { () => { () } } +"#, "SOURCE_FILE FileId(2) 0..50", "#[macro_export]\nmacro_rules! foo { () => { () } }\n", ); @@ -302,19 +302,19 @@ mod tests { #[test] fn goto_def_for_macro_defined_fn_with_arg() { check_goto( - " - //- /lib.rs - macro_rules! define_fn { - ($name:ident) => (fn $name() {}) - } + r#" +//- /lib.rs +macro_rules! define_fn { + ($name:ident) => (fn $name() {}) +} - define_fn!(foo); +define_fn!(foo); - fn bar() { - <|>foo(); - } - ", - "foo FN_DEF FileId(1) 64..80 75..78", +fn bar() { + <|>foo(); +} +"#, + "foo FN_DEF FileId(1) 65..81 76..79", "define_fn!(foo);|foo", ); } @@ -322,19 +322,19 @@ mod tests { #[test] fn goto_def_for_macro_defined_fn_no_arg() { check_goto( - " - //- /lib.rs - macro_rules! define_fn { - () => (fn foo() {}) - } + r#" +//- /lib.rs +macro_rules! define_fn { + () => (fn foo() {}) +} - define_fn!(); +define_fn!(); - fn bar() { - <|>foo(); - } - ", - "foo FN_DEF FileId(1) 51..64 51..64", +fn bar() { + <|>foo(); +} +"#, + "foo FN_DEF FileId(1) 52..65 52..65", "define_fn!();|define_fn!();", ); } @@ -804,40 +804,40 @@ mod tests { #[test] fn goto_within_macro() { check_goto( - " - //- /lib.rs - macro_rules! id { - ($($tt:tt)*) => ($($tt)*) - } + r#" +//- /lib.rs +macro_rules! id { + ($($tt:tt)*) => ($($tt)*) +} - fn foo() { - let x = 1; - id!({ - let y = <|>x; - let z = y; - }); - } - ", - "x BIND_PAT FileId(1) 69..70", +fn foo() { + let x = 1; + id!({ + let y = <|>x; + let z = y; + }); +} +"#, + "x BIND_PAT FileId(1) 70..71", "x", ); check_goto( - " - //- /lib.rs - macro_rules! id { - ($($tt:tt)*) => ($($tt)*) - } + r#" +//- /lib.rs +macro_rules! id { + ($($tt:tt)*) => ($($tt)*) +} - fn foo() { - let x = 1; - id!({ - let y = x; - let z = <|>y; - }); - } - ", - "y BIND_PAT FileId(1) 98..99", +fn foo() { + let x = 1; + id!({ + let y = x; + let z = <|>y; + }); +} +"#, + "y BIND_PAT FileId(1) 99..100", "y", ); } diff --git a/crates/ra_ide/src/hover.rs b/crates/ra_ide/src/hover.rs index d870e4cbc..a898f2e4a 100644 --- a/crates/ra_ide/src/hover.rs +++ b/crates/ra_ide/src/hover.rs @@ -2106,51 +2106,51 @@ fn func(foo: i32) { if true { <|>foo; }; } ); assert_debug_snapshot!(actions, @r###" - [ - GoToType( - [ - HoverGotoTypeData { - mod_path: "B", - nav: NavigationTarget { - file_id: FileId( - 1, - ), - full_range: 41..54, - name: "B", - kind: STRUCT_DEF, - focus_range: Some( - 48..49, - ), - container_name: None, - description: Some( - "struct B", - ), - docs: None, - }, + [ + GoToType( + [ + HoverGotoTypeData { + mod_path: "B", + nav: NavigationTarget { + file_id: FileId( + 1, + ), + full_range: 42..55, + name: "B", + kind: STRUCT_DEF, + focus_range: Some( + 49..50, + ), + container_name: None, + description: Some( + "struct B", + ), + docs: None, }, - HoverGotoTypeData { - mod_path: "Foo", - nav: NavigationTarget { - file_id: FileId( - 1, - ), - full_range: 0..12, - name: "Foo", - kind: TRAIT_DEF, - focus_range: Some( - 6..9, - ), - container_name: None, - description: Some( - "trait Foo", - ), - docs: None, - }, + }, + HoverGotoTypeData { + mod_path: "Foo", + nav: NavigationTarget { + file_id: FileId( + 1, + ), + full_range: 0..12, + name: "Foo", + kind: TRAIT_DEF, + focus_range: Some( + 6..9, + ), + container_name: None, + description: Some( + "trait Foo", + ), + docs: None, }, - ], - ), - ] - "###); + }, + ], + ), + ] + "###); } #[test] diff --git a/crates/ra_ide/src/references.rs b/crates/ra_ide/src/references.rs index bb40d2043..4a96d6505 100644 --- a/crates/ra_ide/src/references.rs +++ b/crates/ra_ide/src/references.rs @@ -427,8 +427,8 @@ mod tests { let refs = analysis.find_all_refs(pos, None).unwrap().unwrap(); check_result( refs, - "Foo STRUCT_DEF FileId(2) 16..50 27..30 Other", - &["FileId(1) 52..55 StructLiteral", "FileId(3) 77..80 StructLiteral"], + "Foo STRUCT_DEF FileId(2) 17..51 28..31 Other", + &["FileId(1) 53..56 StructLiteral", "FileId(3) 79..82 StructLiteral"], ); } @@ -455,7 +455,7 @@ mod tests { let (analysis, pos) = analysis_and_position(code); let refs = analysis.find_all_refs(pos, None).unwrap().unwrap(); - check_result(refs, "foo SOURCE_FILE FileId(2) 0..35 Other", &["FileId(1) 13..16 Other"]); + check_result(refs, "foo SOURCE_FILE FileId(2) 0..35 Other", &["FileId(1) 14..17 Other"]); } #[test] @@ -483,7 +483,7 @@ mod tests { check_result( refs, "Foo STRUCT_DEF FileId(3) 0..41 18..21 Other", - &["FileId(2) 20..23 Other", "FileId(2) 46..49 StructLiteral"], + &["FileId(2) 20..23 Other", "FileId(2) 47..50 StructLiteral"], ); } @@ -510,7 +510,7 @@ mod tests { let refs = analysis.find_all_refs(pos, None).unwrap().unwrap(); check_result( refs, - "quux FN_DEF FileId(1) 18..34 25..29 Other", + "quux FN_DEF FileId(1) 19..35 26..30 Other", &["FileId(2) 16..20 StructLiteral", "FileId(3) 16..20 StructLiteral"], ); @@ -518,7 +518,7 @@ mod tests { analysis.find_all_refs(pos, Some(SearchScope::single_file(bar))).unwrap().unwrap(); check_result( refs, - "quux FN_DEF FileId(1) 18..34 25..29 Other", + "quux FN_DEF FileId(1) 19..35 26..30 Other", &["FileId(3) 16..20 StructLiteral"], ); } @@ -637,8 +637,8 @@ mod tests { let refs = analysis.find_all_refs(pos, None).unwrap().unwrap(); check_result( refs, - "f FN_DEF FileId(1) 25..34 28..29 Other", - &["FileId(2) 11..12 Other", "FileId(2) 27..28 StructLiteral"], + "f FN_DEF FileId(1) 26..35 29..30 Other", + &["FileId(2) 11..12 Other", "FileId(2) 28..29 StructLiteral"], ); } diff --git a/crates/ra_ide/src/runnables.rs b/crates/ra_ide/src/runnables.rs index 8105ef373..f569a3f17 100644 --- a/crates/ra_ide/src/runnables.rs +++ b/crates/ra_ide/src/runnables.rs @@ -310,11 +310,11 @@ mod tests { file_id: FileId( 1, ), - full_range: 22..46, + full_range: 23..47, name: "test_foo", kind: FN_DEF, focus_range: Some( - 33..41, + 34..42, ), container_name: None, description: None, @@ -335,11 +335,11 @@ mod tests { file_id: FileId( 1, ), - full_range: 47..81, + full_range: 49..83, name: "test_foo", kind: FN_DEF, focus_range: Some( - 68..76, + 70..78, ), container_name: None, description: None, @@ -360,11 +360,11 @@ mod tests { file_id: FileId( 1, ), - full_range: 82..104, + full_range: 85..107, name: "bench", kind: FN_DEF, focus_range: Some( - 94..99, + 97..102, ), container_name: None, description: None, @@ -424,7 +424,7 @@ mod tests { file_id: FileId( 1, ), - full_range: 22..64, + full_range: 23..65, name: "foo", kind: FN_DEF, focus_range: None, @@ -489,7 +489,7 @@ mod tests { file_id: FileId( 1, ), - full_range: 51..105, + full_range: 52..106, name: "foo", kind: FN_DEF, focus_range: None, -- cgit v1.2.3