7184: Changes Cursor Marker To $0 r=matklad a=kevaundray



Co-authored-by: Kevaundray Wedderburn <kevtheappdev@gmail.com>
This commit is contained in:
bors[bot] 2021-01-07 12:27:17 +00:00 committed by GitHub
commit 7967ce85cf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
110 changed files with 1745 additions and 1765 deletions

View file

@ -12,7 +12,7 @@ use crate::{AssistContext, AssistId, AssistKind, Assists};
//
// ```
// fn main() {
// let x<|> = 92;
// let x$0 = 92;
// }
// ```
// ->
@ -81,21 +81,17 @@ mod tests {
#[test]
fn add_explicit_type_target() {
check_assist_target(add_explicit_type, "fn f() { let a<|> = 1; }", "a");
check_assist_target(add_explicit_type, "fn f() { let a$0 = 1; }", "a");
}
#[test]
fn add_explicit_type_works_for_simple_expr() {
check_assist(add_explicit_type, "fn f() { let a<|> = 1; }", "fn f() { let a: i32 = 1; }");
check_assist(add_explicit_type, "fn f() { let a$0 = 1; }", "fn f() { let a: i32 = 1; }");
}
#[test]
fn add_explicit_type_works_for_underscore() {
check_assist(
add_explicit_type,
"fn f() { let a<|>: _ = 1; }",
"fn f() { let a: i32 = 1; }",
);
check_assist(add_explicit_type, "fn f() { let a$0: _ = 1; }", "fn f() { let a: i32 = 1; }");
}
#[test]
@ -109,7 +105,7 @@ mod tests {
}
fn f() {
let a<|>: Option<_> = Option::Some(1);
let a$0: Option<_> = Option::Some(1);
}"#,
r#"
enum Option<T> {
@ -127,7 +123,7 @@ mod tests {
fn add_explicit_type_works_for_macro_call() {
check_assist(
add_explicit_type,
r"macro_rules! v { () => {0u64} } fn f() { let a<|> = v!(); }",
r"macro_rules! v { () => {0u64} } fn f() { let a$0 = v!(); }",
r"macro_rules! v { () => {0u64} } fn f() { let a: u64 = v!(); }",
);
}
@ -136,31 +132,31 @@ mod tests {
fn add_explicit_type_works_for_macro_call_recursive() {
check_assist(
add_explicit_type,
r#"macro_rules! u { () => {0u64} } macro_rules! v { () => {u!()} } fn f() { let a<|> = v!(); }"#,
r#"macro_rules! u { () => {0u64} } macro_rules! v { () => {u!()} } fn f() { let a$0 = v!(); }"#,
r#"macro_rules! u { () => {0u64} } macro_rules! v { () => {u!()} } fn f() { let a: u64 = v!(); }"#,
);
}
#[test]
fn add_explicit_type_not_applicable_if_ty_not_inferred() {
check_assist_not_applicable(add_explicit_type, "fn f() { let a<|> = None; }");
check_assist_not_applicable(add_explicit_type, "fn f() { let a$0 = None; }");
}
#[test]
fn add_explicit_type_not_applicable_if_ty_already_specified() {
check_assist_not_applicable(add_explicit_type, "fn f() { let a<|>: i32 = 1; }");
check_assist_not_applicable(add_explicit_type, "fn f() { let a$0: i32 = 1; }");
}
#[test]
fn add_explicit_type_not_applicable_if_specified_ty_is_tuple() {
check_assist_not_applicable(add_explicit_type, "fn f() { let a<|>: (i32, i32) = (3, 4); }");
check_assist_not_applicable(add_explicit_type, "fn f() { let a$0: (i32, i32) = (3, 4); }");
}
#[test]
fn add_explicit_type_not_applicable_if_cursor_after_equals() {
check_assist_not_applicable(
add_explicit_type,
"fn f() {let a =<|> match 1 {2 => 3, 3 => 5};}",
"fn f() {let a =$0 match 1 {2 => 3, 3 => 5};}",
)
}
@ -168,7 +164,7 @@ mod tests {
fn add_explicit_type_not_applicable_if_cursor_before_let() {
check_assist_not_applicable(
add_explicit_type,
"fn f() <|>{let a = match 1 {2 => 3, 3 => 5};}",
"fn f() $0{let a = match 1 {2 => 3, 3 => 5};}",
)
}
@ -178,7 +174,7 @@ mod tests {
add_explicit_type,
r#"
fn main() {
let multiply_by_two<|> = |i| i * 3;
let multiply_by_two$0 = |i| i * 3;
let six = multiply_by_two(2);
}"#,
)
@ -195,7 +191,7 @@ struct Test<K, T = u8> {
}
fn main() {
let test<|> = Test { t: 23u8, k: 33 };
let test$0 = Test { t: 23u8, k: 33 };
}"#,
r#"
struct Test<K, T = u8> {

View file

@ -20,7 +20,7 @@ use crate::{
// fn bar(&self) {}
// }
//
// impl Trait<u32> for () {<|>
// impl Trait<u32> for () {$0
//
// }
// ```
@ -63,7 +63,7 @@ pub(crate) fn add_missing_impl_members(acc: &mut Assists, ctx: &AssistContext) -
//
// impl Trait for () {
// type X = ();
// fn foo(&self) {}<|>
// fn foo(&self) {}$0
//
// }
// ```
@ -166,7 +166,7 @@ struct S;
impl Foo for S {
fn bar(&self) {}
<|>
$0
}"#,
r#"
trait Foo {
@ -214,7 +214,7 @@ struct S;
impl Foo for S {
fn bar(&self) {}
<|>
$0
}"#,
r#"
trait Foo {
@ -242,7 +242,7 @@ impl Foo for S {
r#"
trait Foo { fn foo(&self); }
struct S;
impl Foo for S { <|> }"#,
impl Foo for S { $0 }"#,
r#"
trait Foo { fn foo(&self); }
struct S;
@ -261,7 +261,7 @@ impl Foo for S {
r#"
trait Foo { fn foo(&self); }
struct S;
impl Foo for S<|>"#,
impl Foo for S$0"#,
r#"
trait Foo { fn foo(&self); }
struct S;
@ -280,7 +280,7 @@ impl Foo for S {
r#"
trait Foo<T> { fn foo(&self, t: T) -> &T; }
struct S;
impl Foo<u32> for S { <|> }"#,
impl Foo<u32> for S { $0 }"#,
r#"
trait Foo<T> { fn foo(&self, t: T) -> &T; }
struct S;
@ -299,7 +299,7 @@ impl Foo<u32> for S {
r#"
trait Foo<T> { fn foo(&self, t: T) -> &T; }
struct S;
impl<U> Foo<U> for S { <|> }"#,
impl<U> Foo<U> for S { $0 }"#,
r#"
trait Foo<T> { fn foo(&self, t: T) -> &T; }
struct S;
@ -318,7 +318,7 @@ impl<U> Foo<U> for S {
r#"
trait Foo { fn foo(&self); }
struct S;
impl Foo for S {}<|>"#,
impl Foo for S {}$0"#,
r#"
trait Foo { fn foo(&self); }
struct S;
@ -340,7 +340,7 @@ mod foo {
trait Foo { fn foo(&self, bar: Bar); }
}
struct S;
impl foo::Foo for S { <|> }"#,
impl foo::Foo for S { $0 }"#,
r#"
mod foo {
pub struct Bar;
@ -370,7 +370,7 @@ mod foo {
use foo::bar;
struct S;
impl bar::Foo for S { <|> }"#,
impl bar::Foo for S { $0 }"#,
r#"
mod foo {
pub mod bar {
@ -400,7 +400,7 @@ mod foo {
trait Foo { fn foo(&self, bar: Bar<u32>); }
}
struct S;
impl foo::Foo for S { <|> }"#,
impl foo::Foo for S { $0 }"#,
r#"
mod foo {
pub struct Bar<T>;
@ -425,7 +425,7 @@ mod foo {
trait Foo<T> { fn foo(&self, bar: Bar<T>); }
}
struct S;
impl foo::Foo<u32> for S { <|> }"#,
impl foo::Foo<u32> for S { $0 }"#,
r#"
mod foo {
pub struct Bar<T>;
@ -452,7 +452,7 @@ mod foo {
}
struct Param;
struct S;
impl foo::Foo<Param> for S { <|> }"#,
impl foo::Foo<Param> for S { $0 }"#,
r#"
mod foo {
trait Foo<T> { fn foo(&self, bar: T); }
@ -479,7 +479,7 @@ mod foo {
trait Foo { fn foo(&self, bar: Bar<u32>::Assoc); }
}
struct S;
impl foo::Foo for S { <|> }"#,
impl foo::Foo for S { $0 }"#,
r#"
mod foo {
pub struct Bar<T>;
@ -506,7 +506,7 @@ mod foo {
trait Foo { fn foo(&self, bar: Bar<Baz>); }
}
struct S;
impl foo::Foo for S { <|> }"#,
impl foo::Foo for S { $0 }"#,
r#"
mod foo {
pub struct Bar<T>;
@ -532,7 +532,7 @@ mod foo {
trait Foo { fn foo(&self, bar: dyn Fn(u32) -> i32); }
}
struct S;
impl foo::Foo for S { <|> }"#,
impl foo::Foo for S { $0 }"#,
r#"
mod foo {
pub trait Fn<Args> { type Output; }
@ -554,7 +554,7 @@ impl foo::Foo for S {
r#"
trait Foo;
struct S;
impl Foo for S { <|> }"#,
impl Foo for S { $0 }"#,
)
}
@ -568,7 +568,7 @@ trait Foo {
fn valid(some: u32) -> bool { false }
}
struct S;
impl Foo for S { <|> }"#,
impl Foo for S { $0 }"#,
)
}
@ -586,7 +586,7 @@ trait Foo {
fn foo(&self);
}
struct S;
impl Foo for S {}<|>"#,
impl Foo for S {}$0"#,
r#"
#[doc(alias = "test alias")]
trait Foo {
@ -621,7 +621,7 @@ trait Foo {
fn foo(some: u32) -> bool;
}
struct S;
impl Foo for S { <|> }"#,
impl Foo for S { $0 }"#,
r#"
trait Foo {
type Output;
@ -648,7 +648,7 @@ trait Foo<T = Self> {
}
struct S;
impl Foo for S { <|> }"#,
impl Foo for S { $0 }"#,
r#"
trait Foo<T = Self> {
fn bar(&self, other: &T);
@ -673,7 +673,7 @@ trait Foo<T1, T2 = Self> {
}
struct S<T>;
impl Foo<T> for S<T> { <|> }"#,
impl Foo<T> for S<T> { $0 }"#,
r#"
trait Foo<T1, T2 = Self> {
fn bar(&self, this: &T1, that: &T2);
@ -697,7 +697,7 @@ trait Tr {
type Ty: Copy + 'static;
}
impl Tr for ()<|> {
impl Tr for ()$0 {
}"#,
r#"
trait Tr {
@ -719,7 +719,7 @@ trait Tr {
fn foo();
}
impl Tr for ()<|> {
impl Tr for ()$0 {
+++
}"#,
r#"
@ -745,7 +745,7 @@ trait Tr {
fn foo();
}
impl Tr for ()<|> {
impl Tr for ()$0 {
// very important
}"#,
r#"
@ -771,7 +771,7 @@ trait Test {
fn foo(&self, x: crate)
}
impl Test for () {
<|>
$0
}
"#,
r#"
@ -796,7 +796,7 @@ trait Foo<BAR> {
fn foo(&self, bar: BAR);
}
impl Foo for () {
<|>
$0
}
"#,
r#"

View file

@ -14,7 +14,7 @@ use crate::{
// ```
// fn make<T>() -> T { todo!() }
// fn main() {
// let x = make<|>();
// let x = make$0();
// }
// ```
// ->
@ -77,7 +77,7 @@ mod tests {
r#"
fn make<T>() -> T {}
fn main() {
make<|>();
make$0();
}
"#,
r#"
@ -97,7 +97,7 @@ fn main() {
r#"
fn make<T>() -> T {}
fn main() {
make()<|>;
make()$0;
}
"#,
r#"
@ -119,7 +119,7 @@ impl S {
fn make<T>(&self) -> T {}
}
fn main() {
S.make<|>();
S.make$0();
}
"#,
r#"
@ -142,7 +142,7 @@ fn main() {
r#"
fn make<T>() -> T {}
fn main() {
make<|>::<()>();
make$0::<()>();
}
"#,
);
@ -156,7 +156,7 @@ fn main() {
r#"
fn make() -> () {}
fn main() {
make<|>();
make$0();
}
"#,
);

View file

@ -12,7 +12,7 @@ use crate::{utils::invert_boolean_expression, AssistContext, AssistId, AssistKin
//
// ```
// fn main() {
// if x != 4 ||<|> !y {}
// if x != 4 ||$0 !y {}
// }
// ```
// ->
@ -68,26 +68,26 @@ mod tests {
#[test]
fn demorgan_turns_and_into_or() {
check_assist(apply_demorgan, "fn f() { !x &&<|> !x }", "fn f() { !(x || x) }")
check_assist(apply_demorgan, "fn f() { !x &&$0 !x }", "fn f() { !(x || x) }")
}
#[test]
fn demorgan_turns_or_into_and() {
check_assist(apply_demorgan, "fn f() { !x ||<|> !x }", "fn f() { !(x && x) }")
check_assist(apply_demorgan, "fn f() { !x ||$0 !x }", "fn f() { !(x && x) }")
}
#[test]
fn demorgan_removes_inequality() {
check_assist(apply_demorgan, "fn f() { x != x ||<|> !x }", "fn f() { !(x == x && x) }")
check_assist(apply_demorgan, "fn f() { x != x ||$0 !x }", "fn f() { !(x == x && x) }")
}
#[test]
fn demorgan_general_case() {
check_assist(apply_demorgan, "fn f() { x ||<|> x }", "fn f() { !(!x && !x) }")
check_assist(apply_demorgan, "fn f() { x ||$0 x }", "fn f() { !(!x && !x) }")
}
#[test]
fn demorgan_doesnt_apply_with_cursor_not_on_op() {
check_assist_not_applicable(apply_demorgan, "fn f() { <|> !x || !x }")
check_assist_not_applicable(apply_demorgan, "fn f() { $0 !x || !x }")
}
}

View file

@ -70,7 +70,7 @@ use crate::{
//
// ```
// fn main() {
// let map = HashMap<|>::new();
// let map = HashMap$0::new();
// }
// # pub mod std { pub mod collections { pub struct HashMap { } } }
// ```
@ -151,7 +151,7 @@ mod tests {
use std::fmt;
<|>Formatter
$0Formatter
",
r"
mod std {
@ -172,7 +172,7 @@ mod tests {
check_assist(
auto_import,
r"
<|>PubStruct
$0PubStruct
pub mod PubMod {
pub struct PubStruct;
@ -198,7 +198,7 @@ mod tests {
macro_rules! foo {
($i:ident) => { fn foo(a: $i) {} }
}
foo!(Pub<|>Struct);
foo!(Pub$0Struct);
pub mod PubMod {
pub struct PubStruct;
@ -227,7 +227,7 @@ mod tests {
use PubMod::PubStruct1;
struct Test {
test: Pub<|>Struct2<u8>,
test: Pub$0Struct2<u8>,
}
pub mod PubMod {
@ -259,7 +259,7 @@ mod tests {
check_assist(
auto_import,
r"
PubSt<|>ruct
PubSt$0ruct
pub mod PubMod1 {
pub struct PubStruct;
@ -296,7 +296,7 @@ mod tests {
r"
use PubMod::PubStruct;
PubStruct<|>
PubStruct$0
pub mod PubMod {
pub struct PubStruct;
@ -310,7 +310,7 @@ mod tests {
check_assist_not_applicable(
auto_import,
r"
PrivateStruct<|>
PrivateStruct$0
pub mod PubMod {
struct PrivateStruct;
@ -324,7 +324,7 @@ mod tests {
check_assist_not_applicable(
auto_import,
"
PubStruct<|>",
PubStruct$0",
);
}
@ -333,7 +333,7 @@ mod tests {
check_assist_not_applicable(
auto_import,
r"
use PubStruct<|>;
use PubStruct$0;
pub mod PubMod {
pub struct PubStruct;
@ -346,7 +346,7 @@ mod tests {
check_assist(
auto_import,
r"
test_function<|>
test_function$0
pub mod PubMod {
pub fn test_function() {};
@ -377,7 +377,7 @@ macro_rules! foo {
//- /main.rs crate:main deps:crate_with_macro
fn main() {
foo<|>
foo$0
}
",
r"use crate_with_macro::foo;
@ -395,7 +395,7 @@ fn main() {
auto_import,
r"
struct AssistInfo {
group_label: Option<<|>GroupLabel>,
group_label: Option<$0GroupLabel>,
}
mod m { pub struct GroupLabel; }
@ -419,7 +419,7 @@ fn main() {
use mod1::mod2;
fn main() {
mod2::mod3::TestStruct<|>
mod2::mod3::TestStruct$0
}
",
);
@ -436,7 +436,7 @@ fn main() {
use test_mod::test_function;
fn main() {
test_function<|>
test_function$0
}
",
);
@ -455,7 +455,7 @@ fn main() {
}
fn main() {
TestStruct::test_function<|>
TestStruct::test_function$0
}
",
r"
@ -488,7 +488,7 @@ fn main() {
}
fn main() {
TestStruct::TEST_CONST<|>
TestStruct::TEST_CONST$0
}
",
r"
@ -524,7 +524,7 @@ fn main() {
}
fn main() {
test_mod::TestStruct::test_function<|>
test_mod::TestStruct::test_function$0
}
",
r"
@ -573,7 +573,7 @@ fn main() {
use test_mod::TestTrait2;
fn main() {
test_mod::TestEnum::test_function<|>;
test_mod::TestEnum::test_function$0;
}
",
)
@ -595,7 +595,7 @@ fn main() {
}
fn main() {
test_mod::TestStruct::TEST_CONST<|>
test_mod::TestStruct::TEST_CONST$0
}
",
r"
@ -644,7 +644,7 @@ fn main() {
use test_mod::TestTrait2;
fn main() {
test_mod::TestEnum::TEST_CONST<|>;
test_mod::TestEnum::TEST_CONST$0;
}
",
)
@ -667,7 +667,7 @@ fn main() {
fn main() {
let test_struct = test_mod::TestStruct {};
test_struct.test_meth<|>od()
test_struct.test_meth$0od()
}
",
r"
@ -699,7 +699,7 @@ fn main() {
//- /main.rs crate:main deps:dep
fn main() {
let test_struct = dep::test_mod::TestStruct {};
test_struct.test_meth<|>od()
test_struct.test_meth$0od()
}
//- /dep.rs crate:dep
pub mod test_mod {
@ -730,7 +730,7 @@ fn main() {
r"
//- /main.rs crate:main deps:dep
fn main() {
dep::test_mod::TestStruct::test_func<|>tion
dep::test_mod::TestStruct::test_func$0tion
}
//- /dep.rs crate:dep
pub mod test_mod {
@ -760,7 +760,7 @@ fn main() {
r"
//- /main.rs crate:main deps:dep
fn main() {
dep::test_mod::TestStruct::CONST<|>
dep::test_mod::TestStruct::CONST$0
}
//- /dep.rs crate:dep
pub mod test_mod {
@ -791,7 +791,7 @@ fn main() {
//- /main.rs crate:main deps:dep
fn main() {
let test_struct = dep::test_mod::TestStruct {};
test_struct.test_func<|>tion()
test_struct.test_func$0tion()
}
//- /dep.rs crate:dep
pub mod test_mod {
@ -815,7 +815,7 @@ fn main() {
//- /main.rs crate:main deps:dep
fn main() {
let test_struct = dep::test_mod::TestStruct {};
test_struct.test_meth<|>od()
test_struct.test_meth$0od()
}
//- /dep.rs crate:dep
pub mod test_mod {
@ -858,7 +858,7 @@ fn main() {
use test_mod::TestTrait2;
fn main() {
let one = test_mod::TestEnum::One;
one.test<|>_method();
one.test$0_method();
}
",
)
@ -874,7 +874,7 @@ pub struct Struct;
//- /main.rs crate:main deps:dep
fn main() {
Struct<|>
Struct$0
}
",
r"use dep::Struct;
@ -902,7 +902,7 @@ pub fn panic_fmt() {}
//- /main.rs crate:main deps:dep
struct S;
impl f<|>mt::Display for S {}
impl f$0mt::Display for S {}
",
r"use dep::fmt;
@ -930,7 +930,7 @@ mac!();
//- /main.rs crate:main deps:dep
fn main() {
Cheese<|>;
Cheese$0;
}
",
r"use dep::Cheese;
@ -954,7 +954,7 @@ pub struct fmt;
//- /main.rs crate:main deps:dep
fn main() {
FMT<|>;
FMT$0;
}
",
r"use dep::FMT;

View file

@ -13,7 +13,7 @@ use crate::{utils::vis_offset, AssistContext, AssistId, AssistKind, Assists};
// Adds or changes existing visibility specifier.
//
// ```
// <|>fn frobnicate() {}
// $0fn frobnicate() {}
// ```
// ->
// ```
@ -118,23 +118,23 @@ mod tests {
#[test]
fn change_visibility_adds_pub_crate_to_items() {
check_assist(change_visibility, "<|>fn foo() {}", "pub(crate) fn foo() {}");
check_assist(change_visibility, "f<|>n foo() {}", "pub(crate) fn foo() {}");
check_assist(change_visibility, "<|>struct Foo {}", "pub(crate) struct Foo {}");
check_assist(change_visibility, "<|>mod foo {}", "pub(crate) mod foo {}");
check_assist(change_visibility, "<|>trait Foo {}", "pub(crate) trait Foo {}");
check_assist(change_visibility, "m<|>od {}", "pub(crate) mod {}");
check_assist(change_visibility, "unsafe f<|>n foo() {}", "pub(crate) unsafe fn foo() {}");
check_assist(change_visibility, "$0fn foo() {}", "pub(crate) fn foo() {}");
check_assist(change_visibility, "f$0n foo() {}", "pub(crate) fn foo() {}");
check_assist(change_visibility, "$0struct Foo {}", "pub(crate) struct Foo {}");
check_assist(change_visibility, "$0mod foo {}", "pub(crate) mod foo {}");
check_assist(change_visibility, "$0trait Foo {}", "pub(crate) trait Foo {}");
check_assist(change_visibility, "m$0od {}", "pub(crate) mod {}");
check_assist(change_visibility, "unsafe f$0n foo() {}", "pub(crate) unsafe fn foo() {}");
}
#[test]
fn change_visibility_works_with_struct_fields() {
check_assist(
change_visibility,
r"struct S { <|>field: u32 }",
r"struct S { $0field: u32 }",
r"struct S { pub(crate) field: u32 }",
);
check_assist(change_visibility, r"struct S ( <|>u32 )", r"struct S ( pub(crate) u32 )");
check_assist(change_visibility, r"struct S ( $0u32 )", r"struct S ( pub(crate) u32 )");
}
#[test]
@ -142,33 +142,33 @@ mod tests {
mark::check!(change_visibility_field_false_positive);
check_assist_not_applicable(
change_visibility,
r"struct S { field: [(); { let <|>x = ();}] }",
r"struct S { field: [(); { let $0x = ();}] }",
)
}
#[test]
fn change_visibility_pub_to_pub_crate() {
check_assist(change_visibility, "<|>pub fn foo() {}", "pub(crate) fn foo() {}")
check_assist(change_visibility, "$0pub fn foo() {}", "pub(crate) fn foo() {}")
}
#[test]
fn change_visibility_pub_crate_to_pub() {
check_assist(change_visibility, "<|>pub(crate) fn foo() {}", "pub fn foo() {}")
check_assist(change_visibility, "$0pub(crate) fn foo() {}", "pub fn foo() {}")
}
#[test]
fn change_visibility_const() {
check_assist(change_visibility, "<|>const FOO = 3u8;", "pub(crate) const FOO = 3u8;");
check_assist(change_visibility, "$0const FOO = 3u8;", "pub(crate) const FOO = 3u8;");
}
#[test]
fn change_visibility_static() {
check_assist(change_visibility, "<|>static FOO = 3u8;", "pub(crate) static FOO = 3u8;");
check_assist(change_visibility, "$0static FOO = 3u8;", "pub(crate) static FOO = 3u8;");
}
#[test]
fn change_visibility_type_alias() {
check_assist(change_visibility, "<|>type T = ();", "pub(crate) type T = ();");
check_assist(change_visibility, "$0type T = ();", "pub(crate) type T = ();");
}
#[test]
@ -181,7 +181,7 @@ mod tests {
// comments
#[derive(Debug)]
<|>struct Foo;
$0struct Foo;
",
r"
/// docs
@ -199,14 +199,14 @@ mod tests {
check_assist_not_applicable(
change_visibility,
r"mod foo { pub enum Foo {Foo1} }
fn main() { foo::Foo::Foo1<|> } ",
fn main() { foo::Foo::Foo1$0 } ",
);
}
#[test]
fn change_visibility_target() {
check_assist_target(change_visibility, "<|>fn foo() {}", "fn");
check_assist_target(change_visibility, "pub(crate)<|> fn foo() {}", "pub(crate)");
check_assist_target(change_visibility, "struct S { <|>field: u32 }", "field");
check_assist_target(change_visibility, "$0fn foo() {}", "fn");
check_assist_target(change_visibility, "pub(crate)$0 fn foo() {}", "pub(crate)");
check_assist_target(change_visibility, "struct S { $0field: u32 }", "field");
}
}

View file

@ -7,7 +7,7 @@ use crate::{AssistContext, AssistId, AssistKind, Assists, GroupLabel};
// Converts the base of integer literals to other bases.
//
// ```
// const _: i32 = 10<|>;
// const _: i32 = 10$0;
// ```
// ->
// ```
@ -65,47 +65,47 @@ mod tests {
#[test]
fn binary_target() {
check_assist_target(convert_integer_literal, "const _: i32 = 0b1010<|>;", "0b1010");
check_assist_target(convert_integer_literal, "const _: i32 = 0b1010$0;", "0b1010");
}
#[test]
fn octal_target() {
check_assist_target(convert_integer_literal, "const _: i32 = 0o12<|>;", "0o12");
check_assist_target(convert_integer_literal, "const _: i32 = 0o12$0;", "0o12");
}
#[test]
fn decimal_target() {
check_assist_target(convert_integer_literal, "const _: i32 = 10<|>;", "10");
check_assist_target(convert_integer_literal, "const _: i32 = 10$0;", "10");
}
#[test]
fn hexadecimal_target() {
check_assist_target(convert_integer_literal, "const _: i32 = 0xA<|>;", "0xA");
check_assist_target(convert_integer_literal, "const _: i32 = 0xA$0;", "0xA");
}
#[test]
fn binary_target_with_underscores() {
check_assist_target(convert_integer_literal, "const _: i32 = 0b10_10<|>;", "0b10_10");
check_assist_target(convert_integer_literal, "const _: i32 = 0b10_10$0;", "0b10_10");
}
#[test]
fn octal_target_with_underscores() {
check_assist_target(convert_integer_literal, "const _: i32 = 0o1_2<|>;", "0o1_2");
check_assist_target(convert_integer_literal, "const _: i32 = 0o1_2$0;", "0o1_2");
}
#[test]
fn decimal_target_with_underscores() {
check_assist_target(convert_integer_literal, "const _: i32 = 1_0<|>;", "1_0");
check_assist_target(convert_integer_literal, "const _: i32 = 1_0$0;", "1_0");
}
#[test]
fn hexadecimal_target_with_underscores() {
check_assist_target(convert_integer_literal, "const _: i32 = 0x_A<|>;", "0x_A");
check_assist_target(convert_integer_literal, "const _: i32 = 0x_A$0;", "0x_A");
}
#[test]
fn convert_decimal_integer() {
let before = "const _: i32 = 1000<|>;";
let before = "const _: i32 = 1000$0;";
check_assist_by_label(
convert_integer_literal,
@ -131,7 +131,7 @@ mod tests {
#[test]
fn convert_hexadecimal_integer() {
let before = "const _: i32 = 0xFF<|>;";
let before = "const _: i32 = 0xFF$0;";
check_assist_by_label(
convert_integer_literal,
@ -157,7 +157,7 @@ mod tests {
#[test]
fn convert_binary_integer() {
let before = "const _: i32 = 0b11111111<|>;";
let before = "const _: i32 = 0b11111111$0;";
check_assist_by_label(
convert_integer_literal,
@ -183,7 +183,7 @@ mod tests {
#[test]
fn convert_octal_integer() {
let before = "const _: i32 = 0o377<|>;";
let before = "const _: i32 = 0o377$0;";
check_assist_by_label(
convert_integer_literal,
@ -209,7 +209,7 @@ mod tests {
#[test]
fn convert_integer_with_underscores() {
let before = "const _: i32 = 1_00_0<|>;";
let before = "const _: i32 = 1_00_0$0;";
check_assist_by_label(
convert_integer_literal,
@ -235,7 +235,7 @@ mod tests {
#[test]
fn convert_integer_with_suffix() {
let before = "const _: i32 = 1000i32<|>;";
let before = "const _: i32 = 1000i32$0;";
check_assist_by_label(
convert_integer_literal,
@ -262,7 +262,7 @@ mod tests {
#[test]
fn convert_overflowing_literal() {
let before = "const _: i32 =
111111111111111111111111111111111111111111111111111111111111111111111111<|>;";
111111111111111111111111111111111111111111111111111111111111111111111111$0;";
check_assist_not_applicable(convert_integer_literal, before);
}
}

View file

@ -24,7 +24,7 @@ use crate::{
//
// ```
// fn main() {
// <|>if cond {
// $0if cond {
// foo();
// bar();
// }
@ -200,7 +200,7 @@ mod tests {
r#"
fn main() {
bar();
if<|> true {
if$0 true {
foo();
//comment
@ -230,7 +230,7 @@ mod tests {
r#"
fn main(n: Option<String>) {
bar();
if<|> let Some(n) = n {
if$0 let Some(n) = n {
foo(n);
//comment
@ -260,7 +260,7 @@ mod tests {
convert_to_guarded_return,
r#"
fn main() {
if<|> let Ok(x) = Err(92) {
if$0 let Ok(x) = Err(92) {
foo(x);
}
}
@ -284,7 +284,7 @@ mod tests {
r#"
fn main(n: Option<String>) {
bar();
if<|> let Ok(n) = n {
if$0 let Ok(n) = n {
foo(n);
//comment
@ -315,7 +315,7 @@ mod tests {
r#"
fn main() {
while true {
if<|> true {
if$0 true {
foo();
bar();
}
@ -343,7 +343,7 @@ mod tests {
r#"
fn main() {
while true {
if<|> let Some(n) = n {
if$0 let Some(n) = n {
foo(n);
bar();
}
@ -372,7 +372,7 @@ mod tests {
r#"
fn main() {
loop {
if<|> true {
if$0 true {
foo();
bar();
}
@ -400,7 +400,7 @@ mod tests {
r#"
fn main() {
loop {
if<|> let Some(n) = n {
if$0 let Some(n) = n {
foo(n);
bar();
}
@ -428,7 +428,7 @@ mod tests {
convert_to_guarded_return,
r#"
fn main() {
if<|> true {
if$0 true {
return;
}
}
@ -443,7 +443,7 @@ mod tests {
r#"
fn main() {
loop {
if<|> true {
if$0 true {
continue;
}
}
@ -458,7 +458,7 @@ mod tests {
convert_to_guarded_return,
r#"
fn main() {
if<|> true {
if$0 true {
return
}
}
@ -472,7 +472,7 @@ mod tests {
convert_to_guarded_return,
r#"
fn main() {
if<|> true {
if$0 true {
foo();
} else {
bar()
@ -488,7 +488,7 @@ mod tests {
convert_to_guarded_return,
r#"
fn main() {
if<|> true {
if$0 true {
foo();
}
bar();
@ -504,7 +504,7 @@ mod tests {
r#"
fn main() {
if false {
if<|> true {
if$0 true {
foo();
}
}

View file

@ -25,7 +25,7 @@ use crate::{
// pub struct Baz;
// }
//
// use foo::*<|>;
// use foo::*$0;
//
// fn qux(bar: Bar, baz: Baz) {}
// ```
@ -201,7 +201,7 @@ fn is_mod_visible_from(ctx: &AssistContext, module: Module, from: Module) -> boo
// }
//
// ↓ ---------------
// use foo::*<|>;
// use foo::*$0;
// use baz::Baz;
// ↑ ---------------
fn find_imported_defs(ctx: &AssistContext, star: SyntaxToken) -> Option<Vec<Def>> {
@ -303,7 +303,7 @@ mod foo {
pub fn f() {}
}
use foo::*<|>;
use foo::*$0;
fn qux(bar: Bar, baz: Baz) {
f();
@ -340,7 +340,7 @@ mod foo {
pub fn f() {}
}
use foo::{*<|>, f};
use foo::{*$0, f};
fn qux(bar: Bar, baz: Baz) {
f();
@ -378,7 +378,7 @@ mod foo {
}
use foo::Bar;
use foo::{*<|>, f};
use foo::{*$0, f};
fn qux(bar: Bar, baz: Baz) {
f();
@ -422,7 +422,7 @@ mod foo {
}
}
use foo::{bar::{*<|>, f}, baz::*};
use foo::{bar::{*$0, f}, baz::*};
fn qux(bar: Bar, baz: Baz) {
f();
@ -470,7 +470,7 @@ mod foo {
}
}
use foo::{bar::{Bar, Baz, f}, baz::*<|>};
use foo::{bar::{Bar, Baz, f}, baz::*$0};
fn qux(bar: Bar, baz: Baz) {
f();
@ -529,7 +529,7 @@ mod foo {
use foo::{
bar::{*, f},
baz::{g, qux::*<|>}
baz::{g, qux::*$0}
};
fn qux(bar: Bar, baz: Baz) {
@ -605,7 +605,7 @@ mod foo {
use foo::{
bar::{*, f},
baz::{g, qux::{h, q::*<|>}}
baz::{g, qux::{h, q::*$0}}
};
fn qux(bar: Bar, baz: Baz) {
@ -681,7 +681,7 @@ mod foo {
use foo::{
bar::{*, f},
baz::{g, qux::{q::j, *<|>}}
baz::{g, qux::{q::j, *$0}}
};
fn qux(bar: Bar, baz: Baz) {
@ -747,7 +747,7 @@ fn qux(bar: Bar, baz: Baz) {
// pub fn baz() {}
// //- /main.rs crate:main deps:foo
// use foo::*<|>;
// use foo::*$0;
// fn main() {
// bar!();
@ -777,7 +777,7 @@ pub trait Tr {
impl Tr for () {}
//- /main.rs crate:main deps:foo
use foo::*<|>;
use foo::*$0;
fn main() {
().method();
@ -807,7 +807,7 @@ pub trait Tr2 {
impl Tr2 for () {}
//- /main.rs crate:main deps:foo
use foo::*<|>;
use foo::*$0;
fn main() {
().method();
@ -834,7 +834,7 @@ mod foo {
}
}
use foo::bar::*<|>;
use foo::bar::*$0;
fn baz(bar: Bar) {}
",
@ -851,7 +851,7 @@ mod foo {
}
}
use foo::bar::baz::*<|>;
use foo::bar::baz::*$0;
fn qux(baz: Baz) {}
",
@ -869,7 +869,7 @@ fn qux(baz: Baz) {}
pub struct Qux;
}
use foo::Bar<|>;
use foo::Bar$0;
fn qux(bar: Bar, baz: Baz) {}
",
@ -885,7 +885,7 @@ mod foo {
pub struct Bar;
}
use foo::{*<|>};
use foo::{*$0};
struct Baz {
bar: Bar

View file

@ -21,7 +21,7 @@ use crate::{AssistContext, AssistId, AssistKind, Assists};
// Extracts a struct from enum variant.
//
// ```
// enum A { <|>One(u32, u32) }
// enum A { $0One(u32, u32) }
// ```
// ->
// ```
@ -251,7 +251,7 @@ mod tests {
fn test_extract_struct_several_fields_tuple() {
check_assist(
extract_struct_from_enum_variant,
"enum A { <|>One(u32, u32) }",
"enum A { $0One(u32, u32) }",
r#"struct One(pub u32, pub u32);
enum A { One(One) }"#,
@ -262,7 +262,7 @@ enum A { One(One) }"#,
fn test_extract_struct_several_fields_named() {
check_assist(
extract_struct_from_enum_variant,
"enum A { <|>One { foo: u32, bar: u32 } }",
"enum A { $0One { foo: u32, bar: u32 } }",
r#"struct One{ pub foo: u32, pub bar: u32 }
enum A { One(One) }"#,
@ -273,7 +273,7 @@ enum A { One(One) }"#,
fn test_extract_struct_one_field_named() {
check_assist(
extract_struct_from_enum_variant,
"enum A { <|>One { foo: u32 } }",
"enum A { $0One { foo: u32 } }",
r#"struct One{ pub foo: u32 }
enum A { One(One) }"#,
@ -285,7 +285,7 @@ enum A { One(One) }"#,
check_assist(
extract_struct_from_enum_variant,
r#"const One: () = ();
enum A { <|>One(u32, u32) }"#,
enum A { $0One(u32, u32) }"#,
r#"const One: () = ();
struct One(pub u32, pub u32);
@ -297,7 +297,7 @@ enum A { One(One) }"#,
fn test_extract_struct_pub_visibility() {
check_assist(
extract_struct_from_enum_variant,
"pub enum A { <|>One(u32, u32) }",
"pub enum A { $0One(u32, u32) }",
r#"pub struct One(pub u32, pub u32);
pub enum A { One(One) }"#,
@ -319,7 +319,7 @@ pub enum A { One(One) }"#,
}
pub enum MyEnum {
<|>MyField(u8, u8),
$0MyField(u8, u8),
}
}
}
@ -361,7 +361,7 @@ fn another_fn() {
extract_struct_from_enum_variant,
r#"
enum E {
<|>V { i: i32, j: i32 }
$0V { i: i32, j: i32 }
}
fn f() {
@ -389,7 +389,7 @@ fn f() {
r#"
//- /main.rs
enum E {
<|>V(i32, i32)
$0V(i32, i32)
}
mod foo;
@ -424,7 +424,7 @@ fn f() {
r#"
//- /main.rs
enum E {
<|>V { i: i32, j: i32 }
$0V { i: i32, j: i32 }
}
mod foo;
@ -457,7 +457,7 @@ fn f() {
check_assist(
extract_struct_from_enum_variant,
r#"
enum A { <|>One { a: u32, b: u32 } }
enum A { $0One { a: u32, b: u32 } }
struct B(A);
@ -487,29 +487,29 @@ fn foo() {
#[test]
fn test_extract_enum_not_applicable_for_element_with_no_fields() {
check_not_applicable("enum A { <|>One }");
check_not_applicable("enum A { $0One }");
}
#[test]
fn test_extract_enum_not_applicable_if_struct_exists() {
check_not_applicable(
r#"struct One;
enum A { <|>One(u8, u32) }"#,
enum A { $0One(u8, u32) }"#,
);
}
#[test]
fn test_extract_not_applicable_one_field() {
check_not_applicable(r"enum A { <|>One(u32) }");
check_not_applicable(r"enum A { $0One(u32) }");
}
#[test]
fn test_extract_not_applicable_no_field_tuple() {
check_not_applicable(r"enum A { <|>None() }");
check_not_applicable(r"enum A { $0None() }");
}
#[test]
fn test_extract_not_applicable_no_field_named() {
check_not_applicable(r"enum A { <|>None {} }");
check_not_applicable(r"enum A { $0None {} }");
}
}

View file

@ -16,7 +16,7 @@ use crate::{AssistContext, AssistId, AssistKind, Assists};
//
// ```
// fn main() {
// <|>(1 + 2)<|> * 4;
// $0(1 + 2)$0 * 4;
// }
// ```
// ->
@ -187,7 +187,7 @@ mod tests {
extract_variable,
r#"
fn foo() {
foo(<|>1 + 1<|>);
foo($01 + 1$0);
}"#,
r#"
fn foo() {
@ -200,7 +200,7 @@ fn foo() {
#[test]
fn extract_var_in_comment_is_not_applicable() {
mark::check!(extract_var_in_comment_is_not_applicable);
check_assist_not_applicable(extract_variable, "fn main() { 1 + /* <|>comment<|> */ 1; }");
check_assist_not_applicable(extract_variable, "fn main() { 1 + /* $0comment$0 */ 1; }");
}
#[test]
@ -210,7 +210,7 @@ fn foo() {
extract_variable,
r#"
fn foo() {
<|>1 + 1<|>;
$01 + 1$0;
}"#,
r#"
fn foo() {
@ -221,7 +221,7 @@ fn foo() {
extract_variable,
"
fn foo() {
<|>{ let x = 0; x }<|>
$0{ let x = 0; x }$0
something_else();
}",
"
@ -238,7 +238,7 @@ fn foo() {
extract_variable,
"
fn foo() {
<|>1<|> + 1;
$01$0 + 1;
}",
"
fn foo() {
@ -255,7 +255,7 @@ fn foo() {
extract_variable,
r#"
fn foo() {
bar(<|>1 + 1<|>)
bar($01 + 1$0)
}
"#,
r#"
@ -269,7 +269,7 @@ fn foo() {
extract_variable,
r#"
fn foo() {
<|>bar(1 + 1)<|>
$0bar(1 + 1)$0
}
"#,
r#"
@ -289,7 +289,7 @@ fn foo() {
fn main() {
let x = true;
let tuple = match x {
true => (<|>2 + 2<|>, true)
true => ($02 + 2$0, true)
_ => (0, false)
};
}
@ -316,7 +316,7 @@ fn main() {
let tuple = match x {
true => {
let y = 1;
(<|>2 + y<|>, true)
($02 + y$0, true)
}
_ => (0, false)
};
@ -344,7 +344,7 @@ fn main() {
extract_variable,
"
fn main() {
let lambda = |x: u32| <|>x * 2<|>;
let lambda = |x: u32| $0x * 2$0;
}
",
"
@ -361,7 +361,7 @@ fn main() {
extract_variable,
"
fn main() {
let lambda = |x: u32| { <|>x * 2<|> };
let lambda = |x: u32| { $0x * 2$0 };
}
",
"
@ -378,7 +378,7 @@ fn main() {
extract_variable,
"
fn main() {
let o = <|>Some(true)<|>;
let o = $0Some(true)$0;
}
",
"
@ -396,7 +396,7 @@ fn main() {
extract_variable,
"
fn main() {
let v = <|>bar.foo()<|>;
let v = $0bar.foo()$0;
}
",
"
@ -414,7 +414,7 @@ fn main() {
extract_variable,
"
fn foo() -> u32 {
<|>return 2 + 2<|>;
$0return 2 + 2$0;
}
",
"
@ -434,7 +434,7 @@ fn foo() -> u32 {
fn foo() -> u32 {
<|>return 2 + 2<|>;
$0return 2 + 2$0;
}
",
"
@ -452,7 +452,7 @@ fn foo() -> u32 {
"
fn foo() -> u32 {
<|>return 2 + 2<|>;
$0return 2 + 2$0;
}
",
"
@ -473,7 +473,7 @@ fn foo() -> u32 {
// bar
<|>return 2 + 2<|>;
$0return 2 + 2$0;
}
",
"
@ -497,7 +497,7 @@ fn foo() -> u32 {
"
fn main() {
let result = loop {
<|>break 2 + 2<|>;
$0break 2 + 2$0;
};
}
",
@ -518,7 +518,7 @@ fn main() {
extract_variable,
"
fn main() {
let v = <|>0f32 as u32<|>;
let v = $00f32 as u32$0;
}
",
"
@ -540,7 +540,7 @@ struct S {
}
fn main() {
S { foo: <|>1 + 1<|> }
S { foo: $01 + 1$0 }
}
"#,
r#"
@ -558,18 +558,18 @@ fn main() {
#[test]
fn test_extract_var_for_return_not_applicable() {
check_assist_not_applicable(extract_variable, "fn foo() { <|>return<|>; } ");
check_assist_not_applicable(extract_variable, "fn foo() { $0return$0; } ");
}
#[test]
fn test_extract_var_for_break_not_applicable() {
check_assist_not_applicable(extract_variable, "fn main() { loop { <|>break<|>; }; }");
check_assist_not_applicable(extract_variable, "fn main() { loop { $0break$0; }; }");
}
// FIXME: This is not quite correct, but good enough(tm) for the sorting heuristic
#[test]
fn extract_var_target() {
check_assist_target(extract_variable, "fn foo() -> u32 { <|>return 2 + 2<|>; }", "2 + 2");
check_assist_target(extract_variable, "fn foo() -> u32 { $0return 2 + 2$0; }", "2 + 2");
check_assist_target(
extract_variable,
@ -577,7 +577,7 @@ fn main() {
fn main() {
let x = true;
let tuple = match x {
true => (<|>2 + 2<|>, true)
true => ($02 + 2$0, true)
_ => (0, false)
};
}

View file

@ -21,7 +21,7 @@ use crate::{
//
// fn handle(action: Action) {
// match action {
// <|>
// $0
// }
// }
// ```
@ -231,7 +231,7 @@ mod tests {
Cs(i32, Option<i32>),
}
fn main() {
match A::As<|> {
match A::As$0 {
A::As,
A::Bs{x,y:Some(_)} => {}
A::Cs(_, Some(_)) => {}
@ -249,7 +249,7 @@ mod tests {
fill_match_arms,
r#"
fn main() {
match (0, false)<|> {
match (0, false)$0 {
}
}
"#,
@ -267,7 +267,7 @@ mod tests {
Cs(i32, Option<i32>),
}
fn main() {
match A::As<|> {
match A::As$0 {
A::Bs { x, y: Some(_) } => {}
A::Cs(_, Some(_)) => {}
}
@ -297,7 +297,7 @@ mod tests {
r#"
enum A { As, Bs, Cs(Option<i32>) }
fn main() {
match A::As<|> {
match A::As$0 {
A::Cs(_) | A::Bs => {}
}
}
@ -322,7 +322,7 @@ fn main() {
enum A { As, Bs, Cs, Ds(String), Es(B) }
enum B { Xs, Ys }
fn main() {
match A::As<|> {
match A::As$0 {
A::Bs if 0 < 1 => {}
A::Ds(_value) => { let x = 1; }
A::Es(B::Xs) => (),
@ -352,7 +352,7 @@ fn main() {
r#"
enum A { As, Bs, Cs(Option<i32>) }
fn main() {
match A::As<|> {
match A::As$0 {
A::As(_) => {}
a @ A::Bs(_) => {}
}
@ -380,7 +380,7 @@ enum A { As, Bs, Cs(String), Ds(String, String), Es { x: usize, y: usize } }
fn main() {
let a = A::As;
match a<|> {}
match a$0 {}
}
"#,
r#"
@ -411,7 +411,7 @@ fn main() {
fn main() {
let a = A::One;
let b = B::One;
match (a<|>, b) {}
match (a$0, b) {}
}
"#,
r#"
@ -443,7 +443,7 @@ fn main() {
fn main() {
let a = A::One;
let b = B::One;
match (&a<|>, &b) {}
match (&a$0, &b) {}
}
"#,
r#"
@ -475,7 +475,7 @@ fn main() {
fn main() {
let a = A::One;
let b = B::One;
match (a<|>, b) {
match (a$0, b) {
(A::Two, B::One) => {}
}
}
@ -494,7 +494,7 @@ fn main() {
fn main() {
let a = A::One;
let b = B::One;
match (a<|>, b) {
match (a$0, b) {
(A::Two, B::One) => {}
(A::One, B::One) => {}
(A::One, B::Two) => {}
@ -517,7 +517,7 @@ fn main() {
fn main() {
let a = A::One;
match (a<|>, ) {
match (a$0, ) {
}
}
"#,
@ -532,7 +532,7 @@ fn main() {
enum A { As }
fn foo(a: &A) {
match a<|> {
match a$0 {
}
}
"#,
@ -555,7 +555,7 @@ fn main() {
}
fn foo(a: &mut A) {
match a<|> {
match a$0 {
}
}
"#,
@ -581,7 +581,7 @@ fn main() {
enum E { X, Y }
fn main() {
match E::X<|> {}
match E::X$0 {}
}
"#,
"match E::X {}",
@ -597,7 +597,7 @@ fn main() {
fn main() {
match E::X {
<|>_ => {}
$0_ => {}
}
}
"#,
@ -624,7 +624,7 @@ fn main() {
fn main() {
match X {
<|>
$0
}
}
"#,
@ -650,7 +650,7 @@ fn main() {
enum A { One, Two }
fn foo(a: A) {
match a {
// foo bar baz<|>
// foo bar baz$0
A::One => {}
// This is where the rest should be
}
@ -678,7 +678,7 @@ fn main() {
enum A { One, Two }
fn foo(a: A) {
match a {
// foo bar baz<|>
// foo bar baz$0
}
}
"#,
@ -702,7 +702,7 @@ fn main() {
r#"
enum A { One, Two, }
fn foo(a: A) {
match a<|> {
match a$0 {
_ => (),
}
}
@ -724,7 +724,7 @@ fn main() {
mark::check!(option_order);
let before = r#"
fn foo(opt: Option<i32>) {
match opt<|> {
match opt$0 {
}
}
"#;

View file

@ -18,7 +18,7 @@ use crate::{utils::vis_offset, AssistContext, AssistId, AssistKind, Assists};
// fn frobnicate() {}
// }
// fn main() {
// m::frobnicate<|>() {}
// m::frobnicate$0() {}
// }
// ```
// ->
@ -218,14 +218,14 @@ mod tests {
check_assist(
fix_visibility,
r"mod foo { fn foo() {} }
fn main() { foo::foo<|>() } ",
fn main() { foo::foo$0() } ",
r"mod foo { $0pub(crate) fn foo() {} }
fn main() { foo::foo() } ",
);
check_assist_not_applicable(
fix_visibility,
r"mod foo { pub fn foo() {} }
fn main() { foo::foo<|>() } ",
fn main() { foo::foo$0() } ",
)
}
@ -234,38 +234,38 @@ mod tests {
check_assist(
fix_visibility,
r"mod foo { struct Foo; }
fn main() { foo::Foo<|> } ",
fn main() { foo::Foo$0 } ",
r"mod foo { $0pub(crate) struct Foo; }
fn main() { foo::Foo } ",
);
check_assist_not_applicable(
fix_visibility,
r"mod foo { pub struct Foo; }
fn main() { foo::Foo<|> } ",
fn main() { foo::Foo$0 } ",
);
check_assist(
fix_visibility,
r"mod foo { enum Foo; }
fn main() { foo::Foo<|> } ",
fn main() { foo::Foo$0 } ",
r"mod foo { $0pub(crate) enum Foo; }
fn main() { foo::Foo } ",
);
check_assist_not_applicable(
fix_visibility,
r"mod foo { pub enum Foo; }
fn main() { foo::Foo<|> } ",
fn main() { foo::Foo$0 } ",
);
check_assist(
fix_visibility,
r"mod foo { union Foo; }
fn main() { foo::Foo<|> } ",
fn main() { foo::Foo$0 } ",
r"mod foo { $0pub(crate) union Foo; }
fn main() { foo::Foo } ",
);
check_assist_not_applicable(
fix_visibility,
r"mod foo { pub union Foo; }
fn main() { foo::Foo<|> } ",
fn main() { foo::Foo$0 } ",
);
}
@ -276,7 +276,7 @@ mod tests {
r"
//- /main.rs
mod foo;
fn main() { foo::Foo<|> }
fn main() { foo::Foo$0 }
//- /foo.rs
struct Foo;
@ -291,7 +291,7 @@ struct Foo;
check_assist(
fix_visibility,
r"mod foo { pub struct Foo { bar: (), } }
fn main() { foo::Foo { <|>bar: () }; } ",
fn main() { foo::Foo { $0bar: () }; } ",
r"mod foo { pub struct Foo { $0pub(crate) bar: (), } }
fn main() { foo::Foo { bar: () }; } ",
);
@ -300,7 +300,7 @@ struct Foo;
r"
//- /lib.rs
mod foo;
fn main() { foo::Foo { <|>bar: () }; }
fn main() { foo::Foo { $0bar: () }; }
//- /foo.rs
pub struct Foo { bar: () }
",
@ -310,14 +310,14 @@ pub struct Foo { bar: () }
check_assist_not_applicable(
fix_visibility,
r"mod foo { pub struct Foo { pub bar: (), } }
fn main() { foo::Foo { <|>bar: () }; } ",
fn main() { foo::Foo { $0bar: () }; } ",
);
check_assist_not_applicable(
fix_visibility,
r"
//- /lib.rs
mod foo;
fn main() { foo::Foo { <|>bar: () }; }
fn main() { foo::Foo { $0bar: () }; }
//- /foo.rs
pub struct Foo { pub bar: () }
",
@ -331,14 +331,14 @@ pub struct Foo { pub bar: () }
check_assist_not_applicable(
fix_visibility,
r"mod foo { pub enum Foo { Bar { bar: () } } }
fn main() { foo::Foo::Bar { <|>bar: () }; } ",
fn main() { foo::Foo::Bar { $0bar: () }; } ",
);
check_assist_not_applicable(
fix_visibility,
r"
//- /lib.rs
mod foo;
fn main() { foo::Foo::Bar { <|>bar: () }; }
fn main() { foo::Foo::Bar { $0bar: () }; }
//- /foo.rs
pub enum Foo { Bar { bar: () } }
",
@ -346,14 +346,14 @@ pub enum Foo { Bar { bar: () } }
check_assist_not_applicable(
fix_visibility,
r"mod foo { pub struct Foo { pub bar: (), } }
fn main() { foo::Foo { <|>bar: () }; } ",
fn main() { foo::Foo { $0bar: () }; } ",
);
check_assist_not_applicable(
fix_visibility,
r"
//- /lib.rs
mod foo;
fn main() { foo::Foo { <|>bar: () }; }
fn main() { foo::Foo { $0bar: () }; }
//- /foo.rs
pub struct Foo { pub bar: () }
",
@ -367,7 +367,7 @@ pub struct Foo { pub bar: () }
check_assist(
fix_visibility,
r"mod foo { pub union Foo { bar: (), } }
fn main() { foo::Foo { <|>bar: () }; } ",
fn main() { foo::Foo { $0bar: () }; } ",
r"mod foo { pub union Foo { $0pub(crate) bar: (), } }
fn main() { foo::Foo { bar: () }; } ",
);
@ -376,7 +376,7 @@ pub struct Foo { pub bar: () }
r"
//- /lib.rs
mod foo;
fn main() { foo::Foo { <|>bar: () }; }
fn main() { foo::Foo { $0bar: () }; }
//- /foo.rs
pub union Foo { bar: () }
",
@ -386,14 +386,14 @@ pub union Foo { bar: () }
check_assist_not_applicable(
fix_visibility,
r"mod foo { pub union Foo { pub bar: (), } }
fn main() { foo::Foo { <|>bar: () }; } ",
fn main() { foo::Foo { $0bar: () }; } ",
);
check_assist_not_applicable(
fix_visibility,
r"
//- /lib.rs
mod foo;
fn main() { foo::Foo { <|>bar: () }; }
fn main() { foo::Foo { $0bar: () }; }
//- /foo.rs
pub union Foo { pub bar: () }
",
@ -405,14 +405,14 @@ pub union Foo { pub bar: () }
check_assist(
fix_visibility,
r"mod foo { const FOO: () = (); }
fn main() { foo::FOO<|> } ",
fn main() { foo::FOO$0 } ",
r"mod foo { $0pub(crate) const FOO: () = (); }
fn main() { foo::FOO } ",
);
check_assist_not_applicable(
fix_visibility,
r"mod foo { pub const FOO: () = (); }
fn main() { foo::FOO<|> } ",
fn main() { foo::FOO$0 } ",
);
}
@ -421,14 +421,14 @@ pub union Foo { pub bar: () }
check_assist(
fix_visibility,
r"mod foo { static FOO: () = (); }
fn main() { foo::FOO<|> } ",
fn main() { foo::FOO$0 } ",
r"mod foo { $0pub(crate) static FOO: () = (); }
fn main() { foo::FOO } ",
);
check_assist_not_applicable(
fix_visibility,
r"mod foo { pub static FOO: () = (); }
fn main() { foo::FOO<|> } ",
fn main() { foo::FOO$0 } ",
);
}
@ -437,14 +437,14 @@ pub union Foo { pub bar: () }
check_assist(
fix_visibility,
r"mod foo { trait Foo { fn foo(&self) {} } }
fn main() { let x: &dyn foo::<|>Foo; } ",
fn main() { let x: &dyn foo::$0Foo; } ",
r"mod foo { $0pub(crate) trait Foo { fn foo(&self) {} } }
fn main() { let x: &dyn foo::Foo; } ",
);
check_assist_not_applicable(
fix_visibility,
r"mod foo { pub trait Foo { fn foo(&self) {} } }
fn main() { let x: &dyn foo::Foo<|>; } ",
fn main() { let x: &dyn foo::Foo$0; } ",
);
}
@ -453,14 +453,14 @@ pub union Foo { pub bar: () }
check_assist(
fix_visibility,
r"mod foo { type Foo = (); }
fn main() { let x: foo::Foo<|>; } ",
fn main() { let x: foo::Foo$0; } ",
r"mod foo { $0pub(crate) type Foo = (); }
fn main() { let x: foo::Foo; } ",
);
check_assist_not_applicable(
fix_visibility,
r"mod foo { pub type Foo = (); }
fn main() { let x: foo::Foo<|>; } ",
fn main() { let x: foo::Foo$0; } ",
);
}
@ -469,7 +469,7 @@ pub union Foo { pub bar: () }
check_assist(
fix_visibility,
r"mod foo { mod bar { fn bar() {} } }
fn main() { foo::bar<|>::bar(); } ",
fn main() { foo::bar$0::bar(); } ",
r"mod foo { $0pub(crate) mod bar { fn bar() {} } }
fn main() { foo::bar::bar(); } ",
);
@ -479,7 +479,7 @@ pub union Foo { pub bar: () }
r"
//- /main.rs
mod foo;
fn main() { foo::bar<|>::baz(); }
fn main() { foo::bar$0::baz(); }
//- /foo.rs
mod bar {
@ -495,7 +495,7 @@ mod bar {
check_assist_not_applicable(
fix_visibility,
r"mod foo { pub mod bar { pub fn bar() {} } }
fn main() { foo::bar<|>::bar(); } ",
fn main() { foo::bar$0::bar(); } ",
);
}
@ -506,7 +506,7 @@ mod bar {
r"
//- /main.rs
mod foo;
fn main() { foo::bar<|>::baz(); }
fn main() { foo::bar$0::baz(); }
//- /foo.rs
mod bar;
@ -525,7 +525,7 @@ pub fn baz() {}
r"
//- /main.rs
mod foo;
fn main() { foo::bar<|>>::baz(); }
fn main() { foo::bar$0>::baz(); }
//- /foo.rs
mod bar {
@ -545,7 +545,7 @@ mod bar {
fix_visibility,
r"
//- /main.rs crate:a deps:foo
foo::Bar<|>
foo::Bar$0
//- /lib.rs crate:foo
struct Bar;
",
@ -560,7 +560,7 @@ struct Bar;
fix_visibility,
r"
//- /main.rs crate:a deps:foo
foo::Bar<|>
foo::Bar$0
//- /lib.rs crate:foo
pub(crate) struct Bar;
",
@ -572,7 +572,7 @@ pub(crate) struct Bar;
r"
//- /main.rs crate:a deps:foo
fn main() {
foo::Foo { <|>bar: () };
foo::Foo { $0bar: () };
}
//- /lib.rs crate:foo
pub struct Foo { pub(crate) bar: () }
@ -593,7 +593,7 @@ pub struct Foo { pub(crate) bar: () }
use bar::Baz;
mod bar { pub(super) struct Baz; }
}
foo::Baz<|>
foo::Baz$0
",
r"
mod foo {

View file

@ -8,7 +8,7 @@ use crate::{AssistContext, AssistId, AssistKind, Assists};
//
// ```
// fn main() {
// let _ = 90 +<|> 2;
// let _ = 90 +$0 2;
// }
// ```
// ->
@ -77,42 +77,34 @@ mod tests {
#[test]
fn flip_binexpr_target_is_the_op() {
check_assist_target(flip_binexpr, "fn f() { let res = 1 ==<|> 2; }", "==")
check_assist_target(flip_binexpr, "fn f() { let res = 1 ==$0 2; }", "==")
}
#[test]
fn flip_binexpr_not_applicable_for_assignment() {
check_assist_not_applicable(flip_binexpr, "fn f() { let mut _x = 1; _x +=<|> 2 }")
check_assist_not_applicable(flip_binexpr, "fn f() { let mut _x = 1; _x +=$0 2 }")
}
#[test]
fn flip_binexpr_works_for_eq() {
check_assist(
flip_binexpr,
"fn f() { let res = 1 ==<|> 2; }",
"fn f() { let res = 2 == 1; }",
)
check_assist(flip_binexpr, "fn f() { let res = 1 ==$0 2; }", "fn f() { let res = 2 == 1; }")
}
#[test]
fn flip_binexpr_works_for_gt() {
check_assist(flip_binexpr, "fn f() { let res = 1 ><|> 2; }", "fn f() { let res = 2 < 1; }")
check_assist(flip_binexpr, "fn f() { let res = 1 >$0 2; }", "fn f() { let res = 2 < 1; }")
}
#[test]
fn flip_binexpr_works_for_lteq() {
check_assist(
flip_binexpr,
"fn f() { let res = 1 <=<|> 2; }",
"fn f() { let res = 2 >= 1; }",
)
check_assist(flip_binexpr, "fn f() { let res = 1 <=$0 2; }", "fn f() { let res = 2 >= 1; }")
}
#[test]
fn flip_binexpr_works_for_complex_expr() {
check_assist(
flip_binexpr,
"fn f() { let res = (1 + 1) ==<|> (2 + 2); }",
"fn f() { let res = (1 + 1) ==$0 (2 + 2); }",
"fn f() { let res = (2 + 2) == (1 + 1); }",
)
}
@ -125,7 +117,7 @@ mod tests {
fn dyn_eq(&self, other: &dyn Diagnostic) -> bool {
match other.downcast_ref::<Self>() {
None => false,
Some(it) => it ==<|> self,
Some(it) => it ==$0 self,
}
}
"#,

View file

@ -8,7 +8,7 @@ use crate::{AssistContext, AssistId, AssistKind, Assists};
//
// ```
// fn main() {
// ((1, 2),<|> (3, 4));
// ((1, 2),$0 (3, 4));
// }
// ```
// ->
@ -49,14 +49,14 @@ mod tests {
fn flip_comma_works_for_function_parameters() {
check_assist(
flip_comma,
"fn foo(x: i32,<|> y: Result<(), ()>) {}",
"fn foo(x: i32,$0 y: Result<(), ()>) {}",
"fn foo(y: Result<(), ()>, x: i32) {}",
)
}
#[test]
fn flip_comma_target() {
check_assist_target(flip_comma, "fn foo(x: i32,<|> y: Result<(), ()>) {}", ",")
check_assist_target(flip_comma, "fn foo(x: i32,$0 y: Result<(), ()>) {}", ",")
}
#[test]
@ -68,7 +68,7 @@ mod tests {
check_assist_target(
flip_comma,
"pub enum Test { \
A,<|> \
A,$0 \
}",
",",
);
@ -76,7 +76,7 @@ mod tests {
check_assist_target(
flip_comma,
"pub struct Test { \
foo: usize,<|> \
foo: usize,$0 \
}",
",",
);

View file

@ -11,7 +11,7 @@ use crate::{AssistContext, AssistId, AssistKind, Assists};
// Flips two trait bounds.
//
// ```
// fn foo<T: Clone +<|> Copy>() { }
// fn foo<T: Clone +$0 Copy>() { }
// ```
// ->
// ```
@ -52,19 +52,19 @@ mod tests {
#[test]
fn flip_trait_bound_assist_available() {
check_assist_target(flip_trait_bound, "struct S<T> where T: A <|>+ B + C { }", "+")
check_assist_target(flip_trait_bound, "struct S<T> where T: A $0+ B + C { }", "+")
}
#[test]
fn flip_trait_bound_not_applicable_for_single_trait_bound() {
check_assist_not_applicable(flip_trait_bound, "struct S<T> where T: <|>A { }")
check_assist_not_applicable(flip_trait_bound, "struct S<T> where T: $0A { }")
}
#[test]
fn flip_trait_bound_works_for_struct() {
check_assist(
flip_trait_bound,
"struct S<T> where T: A <|>+ B { }",
"struct S<T> where T: A $0+ B { }",
"struct S<T> where T: B + A { }",
)
}
@ -73,21 +73,21 @@ mod tests {
fn flip_trait_bound_works_for_trait_impl() {
check_assist(
flip_trait_bound,
"impl X for S<T> where T: A +<|> B { }",
"impl X for S<T> where T: A +$0 B { }",
"impl X for S<T> where T: B + A { }",
)
}
#[test]
fn flip_trait_bound_works_for_fn() {
check_assist(flip_trait_bound, "fn f<T: A <|>+ B>(t: T) { }", "fn f<T: B + A>(t: T) { }")
check_assist(flip_trait_bound, "fn f<T: A $0+ B>(t: T) { }", "fn f<T: B + A>(t: T) { }")
}
#[test]
fn flip_trait_bound_works_for_fn_where_clause() {
check_assist(
flip_trait_bound,
"fn f<T>(t: T) where T: A +<|> B { }",
"fn f<T>(t: T) where T: A +$0 B { }",
"fn f<T>(t: T) where T: B + A { }",
)
}
@ -96,7 +96,7 @@ mod tests {
fn flip_trait_bound_works_for_lifetime() {
check_assist(
flip_trait_bound,
"fn f<T>(t: T) where T: A <|>+ 'static { }",
"fn f<T>(t: T) where T: A $0+ 'static { }",
"fn f<T>(t: T) where T: 'static + A { }",
)
}
@ -105,7 +105,7 @@ mod tests {
fn flip_trait_bound_works_for_complex_bounds() {
check_assist(
flip_trait_bound,
"struct S<T> where T: A<T> <|>+ b_mod::B<T> + C<T> { }",
"struct S<T> where T: A<T> $0+ b_mod::B<T> + C<T> { }",
"struct S<T> where T: b_mod::B<T> + A<T> + C<T> { }",
)
}
@ -114,7 +114,7 @@ mod tests {
fn flip_trait_bound_works_for_long_bounds() {
check_assist(
flip_trait_bound,
"struct S<T> where T: A + B + C + D + E + F +<|> G + H + I + J { }",
"struct S<T> where T: A + B + C + D + E + F +$0 G + H + I + J { }",
"struct S<T> where T: A + B + C + D + E + G + F + H + I + J { }",
)
}

View file

@ -12,7 +12,7 @@ use crate::{AssistContext, AssistId, AssistKind, Assists};
// ```
// enum Version {
// Undefined,
// Minor<|>,
// Minor$0,
// Major,
// }
// ```
@ -108,7 +108,7 @@ mod tests {
r#"
enum Variant {
Undefined,
Minor<|>,
Minor$0,
Major,
}"#,
r#"enum Variant {
@ -132,7 +132,7 @@ impl Default for Variant {
r#"
enum Variant {
Undefined,
Minor<|>,
Minor$0,
Major,
}
@ -151,7 +151,7 @@ impl Default for Variant {
r#"
enum Variant {
Undefined,
Minor(u32)<|>,
Minor(u32)$0,
Major,
}"#,
);
@ -161,7 +161,7 @@ enum Variant {
fn test_generate_default_from_variant_with_one_variant() {
check_assist(
generate_default_from_enum_variant,
r#"enum Variant { Undefi<|>ned }"#,
r#"enum Variant { Undefi$0ned }"#,
r#"
enum Variant { Undefined }

View file

@ -13,7 +13,7 @@ use crate::{AssistContext, AssistId, AssistKind, Assists};
// ```
// struct Point {
// x: u32,
// y: u32,<|>
// y: u32,$0
// }
// ```
// ->
@ -76,12 +76,12 @@ mod tests {
fn add_derive_new() {
check_assist(
generate_derive,
"struct Foo { a: i32, <|>}",
"struct Foo { a: i32, $0}",
"#[derive($0)]\nstruct Foo { a: i32, }",
);
check_assist(
generate_derive,
"struct Foo { <|> a: i32, }",
"struct Foo { $0 a: i32, }",
"#[derive($0)]\nstruct Foo { a: i32, }",
);
}
@ -90,7 +90,7 @@ mod tests {
fn add_derive_existing() {
check_assist(
generate_derive,
"#[derive(Clone)]\nstruct Foo { a: i32<|>, }",
"#[derive(Clone)]\nstruct Foo { a: i32$0, }",
"#[derive(Clone$0)]\nstruct Foo { a: i32, }",
);
}
@ -102,7 +102,7 @@ mod tests {
"
/// `Foo` is a pretty important struct.
/// It does stuff.
struct Foo { a: i32<|>, }
struct Foo { a: i32$0, }
",
"
/// `Foo` is a pretty important struct.
@ -121,7 +121,7 @@ struct Foo { a: i32, }
struct SomeThingIrrelevant;
/// `Foo` is a pretty important struct.
/// It does stuff.
struct Foo { a: i32<|>, }
struct Foo { a: i32$0, }
struct EvenMoreIrrelevant;
",
"/// `Foo` is a pretty important struct.

View file

@ -10,7 +10,7 @@ use crate::{AssistContext, AssistId, AssistKind, Assists};
// Adds a From impl for an enum variant with one tuple field.
//
// ```
// enum A { <|>One(u32) }
// enum A { $0One(u32) }
// ```
// ->
// ```
@ -101,7 +101,7 @@ mod tests {
fn test_generate_from_impl_for_enum() {
check_assist(
generate_from_impl_for_enum,
"enum A { <|>One(u32) }",
"enum A { $0One(u32) }",
r#"enum A { One(u32) }
impl From<u32> for A {
@ -116,7 +116,7 @@ impl From<u32> for A {
fn test_generate_from_impl_for_enum_complicated_path() {
check_assist(
generate_from_impl_for_enum,
r#"enum A { <|>One(foo::bar::baz::Boo) }"#,
r#"enum A { $0One(foo::bar::baz::Boo) }"#,
r#"enum A { One(foo::bar::baz::Boo) }
impl From<foo::bar::baz::Boo> for A {
@ -135,17 +135,17 @@ impl From<foo::bar::baz::Boo> for A {
#[test]
fn test_add_from_impl_no_element() {
check_not_applicable("enum A { <|>One }");
check_not_applicable("enum A { $0One }");
}
#[test]
fn test_add_from_impl_more_than_one_element_in_tuple() {
check_not_applicable("enum A { <|>One(u32, String) }");
check_not_applicable("enum A { $0One(u32, String) }");
}
#[test]
fn test_add_from_impl_struct_variant() {
check_not_applicable("enum A { <|>One { x: u32 } }");
check_not_applicable("enum A { $0One { x: u32 } }");
}
#[test]
@ -153,7 +153,7 @@ impl From<foo::bar::baz::Boo> for A {
mark::check!(test_add_from_impl_already_exists);
check_not_applicable(
r#"
enum A { <|>One(u32), }
enum A { $0One(u32), }
impl From<u32> for A {
fn from(v: u32) -> Self {
@ -168,7 +168,7 @@ impl From<u32> for A {
fn test_add_from_impl_different_variant_impl_exists() {
check_assist(
generate_from_impl_for_enum,
r#"enum A { <|>One(u32), Two(String), }
r#"enum A { $0One(u32), Two(String), }
impl From<String> for A {
fn from(v: String) -> Self {

View file

@ -23,7 +23,7 @@ use crate::{
// struct Baz;
// fn baz() -> Baz { Baz }
// fn foo() {
// bar<|>("", baz());
// bar$0("", baz());
// }
//
// ```
@ -342,7 +342,7 @@ mod tests {
generate_function,
r"
fn foo() {
bar<|>();
bar$0();
}
",
r"
@ -366,7 +366,7 @@ fn bar() ${0:-> ()} {
r"
impl Foo {
fn foo() {
bar<|>();
bar$0();
}
}
",
@ -391,7 +391,7 @@ fn bar() ${0:-> ()} {
generate_function,
r"
fn foo1() {
bar<|>();
bar$0();
}
fn foo2() {}
@ -417,7 +417,7 @@ fn foo2() {}
r"
mod baz {
fn foo() {
bar<|>();
bar$0();
}
}
",
@ -443,7 +443,7 @@ mod baz {
struct Baz;
fn baz() -> Baz { todo!() }
fn foo() {
bar<|>(baz());
bar$0(baz());
}
",
r"
@ -468,7 +468,7 @@ fn bar(baz: Baz) ${0:-> ()} {
struct Baz;
impl Baz {
fn foo(&self) -> Baz {
ba<|>r(self.baz())
ba$0r(self.baz())
}
fn baz(&self) -> Baz {
Baz
@ -499,7 +499,7 @@ fn bar(baz: Baz) ${0:-> ()} {
generate_function,
r#"
fn foo() {
<|>bar("bar")
$0bar("bar")
}
"#,
r#"
@ -520,7 +520,7 @@ fn bar(arg: &str) ${0:-> ()} {
generate_function,
r#"
fn foo() {
<|>bar('x')
$0bar('x')
}
"#,
r#"
@ -541,7 +541,7 @@ fn bar(arg: char) ${0:-> ()} {
generate_function,
r"
fn foo() {
<|>bar(42)
$0bar(42)
}
",
r"
@ -562,7 +562,7 @@ fn bar(arg: i32) ${0:-> ()} {
generate_function,
r"
fn foo() {
<|>bar(42 as u8)
$0bar(42 as u8)
}
",
r"
@ -586,7 +586,7 @@ fn bar(arg: u8) ${0:-> ()} {
r"
fn foo() {
let x = 42;
bar<|>(x as u8)
bar$0(x as u8)
}
",
r"
@ -609,7 +609,7 @@ fn bar(x: u8) ${0:-> ()} {
r"
fn foo() {
let worble = ();
<|>bar(worble)
$0bar(worble)
}
",
r"
@ -635,7 +635,7 @@ fn foo() -> impl Foo {
todo!()
}
fn baz() {
<|>bar(foo())
$0bar(foo())
}
",
r"
@ -663,7 +663,7 @@ struct Baz;
fn baz() -> Baz { todo!() }
fn foo() {
bar<|>(&baz())
bar$0(&baz())
}
",
r"
@ -691,7 +691,7 @@ mod Baz {
pub fn baz() -> Bof { Bof }
}
fn foo() {
<|>bar(Baz::baz())
$0bar(Baz::baz())
}
",
r"
@ -718,7 +718,7 @@ fn bar(baz: Baz::Bof) ${0:-> ()} {
generate_function,
r"
fn foo<T>(t: T) {
<|>bar(t)
$0bar(t)
}
",
r"
@ -745,7 +745,7 @@ impl Baz {
fn new() -> Self { Baz }
}
fn foo() {
<|>bar(Baz::new);
$0bar(Baz::new);
}
",
r"
@ -773,7 +773,7 @@ fn bar(arg: fn() -> Baz) ${0:-> ()} {
r"
fn foo() {
let closure = |x: i64| x - 1;
<|>bar(closure)
$0bar(closure)
}
",
r"
@ -795,7 +795,7 @@ fn bar(closure: impl Fn(i64) -> i64) ${0:-> ()} {
generate_function,
r"
fn foo() {
<|>bar(baz)
$0bar(baz)
}
",
r"
@ -818,7 +818,7 @@ fn bar(baz: ()) ${0:-> ()} {
struct Baz;
fn baz() -> Baz { Baz }
fn foo() {
<|>bar(baz(), baz())
$0bar(baz(), baz())
}
",
r"
@ -843,7 +843,7 @@ fn bar(baz_1: Baz, baz_2: Baz) ${0:-> ()} {
struct Baz;
fn baz() -> Baz { Baz }
fn foo() {
<|>bar(baz(), baz(), "foo", "bar")
$0bar(baz(), baz(), "foo", "bar")
}
"#,
r#"
@ -868,7 +868,7 @@ fn bar(baz_1: Baz, baz_2: Baz, arg_1: &str, arg_2: &str) ${0:-> ()} {
mod bar {}
fn foo() {
bar::my_fn<|>()
bar::my_fn$0()
}
",
r"
@ -899,7 +899,7 @@ mod foo {
fn bar() {
use foo::Foo;
let foo = Foo;
baz<|>(foo)
baz$0(foo)
}
",
"
@ -929,7 +929,7 @@ mod bar {
}
fn foo() {
bar::my_fn<|>()
bar::my_fn$0()
}
",
r"
@ -958,7 +958,7 @@ mod bar {
}
fn foo() {
bar::baz::my_fn<|>()
bar::baz::my_fn$0()
}
",
r"
@ -986,7 +986,7 @@ fn foo() {
mod foo;
fn main() {
foo::bar<|>()
foo::bar$0()
}
//- /foo.rs
",
@ -1005,7 +1005,7 @@ pub(crate) fn bar() ${0:-> ()} {
generate_function,
r"
fn foo() {
bar<|>();
bar$0();
}
fn bar() {}
@ -1022,7 +1022,7 @@ fn bar() {}
generate_function,
r"
fn foo() {
bar(b<|>az);
bar(b$0az);
}
fn bar(baz: ()) {}
@ -1039,7 +1039,7 @@ fn bar(baz: ()) {}
struct Foo;
impl Foo {
fn foo(&self) {
self.bar()<|>;
self.bar()$0;
}
}
",

View file

@ -10,7 +10,7 @@ use crate::{AssistContext, AssistId, AssistKind, Assists};
//
// ```
// struct Ctx<T: Clone> {
// data: T,<|>
// data: T,$0
// }
// ```
// ->
@ -87,24 +87,24 @@ mod tests {
fn test_add_impl() {
check_assist(
generate_impl,
"struct Foo {<|>}\n",
"struct Foo {$0}\n",
"struct Foo {}\n\nimpl Foo {\n $0\n}\n",
);
check_assist(
generate_impl,
"struct Foo<T: Clone> {<|>}",
"struct Foo<T: Clone> {$0}",
"struct Foo<T: Clone> {}\n\nimpl<T: Clone> Foo<T> {\n $0\n}",
);
check_assist(
generate_impl,
"struct Foo<'a, T: Foo<'a>> {<|>}",
"struct Foo<'a, T: Foo<'a>> {$0}",
"struct Foo<'a, T: Foo<'a>> {}\n\nimpl<'a, T: Foo<'a>> Foo<'a, T> {\n $0\n}",
);
check_assist(
generate_impl,
r#"
#[cfg(feature = "foo")]
struct Foo<'a, T: Foo<'a>> {<|>}"#,
struct Foo<'a, T: Foo<'a>> {$0}"#,
r#"
#[cfg(feature = "foo")]
struct Foo<'a, T: Foo<'a>> {}
@ -119,7 +119,7 @@ mod tests {
generate_impl,
r#"
#[cfg(not(feature = "foo"))]
struct Foo<'a, T: Foo<'a>> {<|>}"#,
struct Foo<'a, T: Foo<'a>> {$0}"#,
r#"
#[cfg(not(feature = "foo"))]
struct Foo<'a, T: Foo<'a>> {}
@ -138,7 +138,7 @@ mod tests {
"
struct SomeThingIrrelevant;
/// Has a lifetime parameter
struct Foo<'a, T: Foo<'a>> {<|>}
struct Foo<'a, T: Foo<'a>> {$0}
struct EvenMoreIrrelevant;
",
"/// Has a lifetime parameter

View file

@ -14,7 +14,7 @@ use crate::{AssistContext, AssistId, AssistKind, Assists};
//
// ```
// struct Ctx<T: Clone> {
// data: T,<|>
// data: T,$0
// }
// ```
// ->
@ -182,7 +182,7 @@ mod tests {
// Check output of generation
check_assist(
generate_new,
"struct Foo {<|>}",
"struct Foo {$0}",
"struct Foo {}
impl Foo {
@ -192,7 +192,7 @@ impl Foo {
);
check_assist(
generate_new,
"struct Foo<T: Clone> {<|>}",
"struct Foo<T: Clone> {$0}",
"struct Foo<T: Clone> {}
impl<T: Clone> Foo<T> {
@ -202,7 +202,7 @@ impl<T: Clone> Foo<T> {
);
check_assist(
generate_new,
"struct Foo<'a, T: Foo<'a>> {<|>}",
"struct Foo<'a, T: Foo<'a>> {$0}",
"struct Foo<'a, T: Foo<'a>> {}
impl<'a, T: Foo<'a>> Foo<'a, T> {
@ -212,7 +212,7 @@ impl<'a, T: Foo<'a>> Foo<'a, T> {
);
check_assist(
generate_new,
"struct Foo { baz: String <|>}",
"struct Foo { baz: String $0}",
"struct Foo { baz: String }
impl Foo {
@ -222,7 +222,7 @@ impl Foo {
);
check_assist(
generate_new,
"struct Foo { baz: String, qux: Vec<i32> <|>}",
"struct Foo { baz: String, qux: Vec<i32> $0}",
"struct Foo { baz: String, qux: Vec<i32> }
impl Foo {
@ -234,7 +234,7 @@ impl Foo {
// Check that visibility modifiers don't get brought in for fields
check_assist(
generate_new,
"struct Foo { pub baz: String, pub qux: Vec<i32> <|>}",
"struct Foo { pub baz: String, pub qux: Vec<i32> $0}",
"struct Foo { pub baz: String, pub qux: Vec<i32> }
impl Foo {
@ -246,7 +246,7 @@ impl Foo {
// Check that it reuses existing impls
check_assist(
generate_new,
"struct Foo {<|>}
"struct Foo {$0}
impl Foo {}
",
@ -259,7 +259,7 @@ impl Foo {
);
check_assist(
generate_new,
"struct Foo {<|>}
"struct Foo {$0}
impl Foo {
fn qux(&self) {}
@ -277,7 +277,7 @@ impl Foo {
check_assist(
generate_new,
"struct Foo {<|>}
"struct Foo {$0}
impl Foo {
fn qux(&self) {}
@ -302,7 +302,7 @@ impl Foo {
// Check visibility of new fn based on struct
check_assist(
generate_new,
"pub struct Foo {<|>}",
"pub struct Foo {$0}",
"pub struct Foo {}
impl Foo {
@ -312,7 +312,7 @@ impl Foo {
);
check_assist(
generate_new,
"pub(crate) struct Foo {<|>}",
"pub(crate) struct Foo {$0}",
"pub(crate) struct Foo {}
impl Foo {
@ -327,7 +327,7 @@ impl Foo {
check_assist_not_applicable(
generate_new,
"
struct Foo {<|>}
struct Foo {$0}
impl Foo {
fn new() -> Self {
@ -339,7 +339,7 @@ impl Foo {
check_assist_not_applicable(
generate_new,
"
struct Foo {<|>}
struct Foo {$0}
impl Foo {
fn New() -> Self {
@ -356,7 +356,7 @@ impl Foo {
"
struct SomeThingIrrelevant;
/// Has a lifetime parameter
struct Foo<'a, T: Foo<'a>> {<|>}
struct Foo<'a, T: Foo<'a>> {$0}
struct EvenMoreIrrelevant;
",
"/// Has a lifetime parameter
@ -381,7 +381,7 @@ impl<N: AstNode> AstId<N> {
}
pub struct Source<T> {
pub file_id: HirFileId,<|>
pub file_id: HirFileId,$0
pub ast: T,
}

View file

@ -10,7 +10,7 @@ use crate::{AssistContext, AssistId, AssistKind, Assists};
// type specified. This assists is useable in a functions or closures tail expression or return type position.
//
// ```
// fn foo() { 4<|>2i32 }
// fn foo() { 4$02i32 }
// ```
// ->
// ```
@ -131,7 +131,7 @@ mod tests {
mark::check!(existing_infer_ret_type);
check_assist(
infer_function_return_type,
r#"fn foo() -> <|>_ {
r#"fn foo() -> $0_ {
45
}"#,
r#"fn foo() -> i32 {
@ -146,7 +146,7 @@ mod tests {
check_assist(
infer_function_return_type,
r#"fn foo() {
|| -> _ {<|>45};
|| -> _ {$045};
}"#,
r#"fn foo() {
|| -> i32 {45};
@ -159,7 +159,7 @@ mod tests {
mark::check!(cursor_in_ret_position);
check_assist(
infer_function_return_type,
r#"fn foo() <|>{
r#"fn foo() $0{
45
}"#,
r#"fn foo() -> i32 {
@ -174,7 +174,7 @@ mod tests {
check_assist(
infer_function_return_type,
r#"fn foo() {
|| <|>45
|| $045
}"#,
r#"fn foo() {
|| -> i32 {45}
@ -188,7 +188,7 @@ mod tests {
check_assist(
infer_function_return_type,
r#"fn foo() {
45<|>
45$0
}"#,
r#"fn foo() -> i32 {
45
@ -202,7 +202,7 @@ mod tests {
infer_function_return_type,
r#"fn foo() {
if true {
3<|>
3$0
} else {
5
}
@ -223,7 +223,7 @@ mod tests {
check_assist_not_applicable(
infer_function_return_type,
r#"fn foo() -> i32 {
( 45<|> + 32 ) * 123
( 45$0 + 32 ) * 123
}"#,
);
}
@ -233,7 +233,7 @@ mod tests {
check_assist_not_applicable(
infer_function_return_type,
r#"fn foo() {
let x = <|>3;
let x = $03;
( 45 + 32 ) * 123
}"#,
);
@ -244,7 +244,7 @@ mod tests {
check_assist_not_applicable(
infer_function_return_type,
r#"fn foo() {
(<|>)
($0)
}"#,
);
}
@ -256,7 +256,7 @@ mod tests {
infer_function_return_type,
r#"fn foo() {
|x: i32| {
x<|>
x$0
};
}"#,
r#"fn foo() {
@ -272,7 +272,7 @@ mod tests {
check_assist(
infer_function_return_type,
r#"fn foo() {
|x: i32| { x<|> };
|x: i32| { x$0 };
}"#,
r#"fn foo() {
|x: i32| -> i32 { x };
@ -286,7 +286,7 @@ mod tests {
check_assist(
infer_function_return_type,
r#"fn foo() {
|x: i32| x<|>;
|x: i32| x$0;
}"#,
r#"fn foo() {
|x: i32| -> i32 {x};
@ -301,7 +301,7 @@ mod tests {
r#"fn foo() {
|| {
if true {
3<|>
3$0
} else {
5
}
@ -325,7 +325,7 @@ mod tests {
check_assist_not_applicable(
infer_function_return_type,
r#"fn foo() {
|| -> i32 { 3<|> }
|| -> i32 { 3$0 }
}"#,
);
}
@ -336,7 +336,7 @@ mod tests {
infer_function_return_type,
r#"fn foo() {
|| -> i32 {
let x = 3<|>;
let x = 3$0;
6
}
}"#,

View file

@ -18,7 +18,7 @@ use crate::{
// ```
// fn add(a: u32, b: u32) -> u32 { a + b }
// fn main() {
// let x = add<|>(1, 2);
// let x = add$0(1, 2);
// }
// ```
// ->
@ -104,7 +104,7 @@ mod tests {
r#"
fn foo() { println!("Hello, World!"); }
fn main() {
fo<|>o();
fo$0o();
}
"#,
r#"
@ -125,7 +125,7 @@ fn main() {
r#"
fn foo(name: String) { println!("Hello, {}!", name); }
fn main() {
foo<|>(String::from("Michael"));
foo$0(String::from("Michael"));
}
"#,
r#"
@ -148,7 +148,7 @@ fn main() {
struct Foo;
impl Foo { fn bar(&self) {} }
fn main() { Foo.bar<|>(); }
fn main() { Foo.bar$0(); }
",
);
}
@ -160,7 +160,7 @@ fn main() { Foo.bar<|>(); }
inline_function,
r#"
fn add(a: u32, b: u32) -> u32 { a + b }
fn main() { let x = add<|>(42); }
fn main() { let x = add$0(42); }
"#,
);
}
@ -177,7 +177,7 @@ fn foo(a: u32, b: u32) -> u32 {
}
fn main() {
let x = foo<|>(1, 2);
let x = foo$0(1, 2);
}
"#,
r#"

View file

@ -16,7 +16,7 @@ use crate::{
//
// ```
// fn main() {
// let x<|> = 1 + 2;
// let x$0 = 1 + 2;
// x * 4;
// }
// ```
@ -146,7 +146,7 @@ mod tests {
r"
fn bar(a: usize) {}
fn foo() {
let a<|> = 1;
let a$0 = 1;
a + 1;
if a > 10 {
}
@ -180,7 +180,7 @@ fn foo() {
r"
fn bar(a: usize) {}
fn foo() {
let a<|> = 1 + 1;
let a$0 = 1 + 1;
a + 1;
if a > 10 {
}
@ -214,7 +214,7 @@ fn foo() {
r"
fn bar(a: usize) {}
fn foo() {
let a<|> = bar(1);
let a$0 = bar(1);
a + 1;
if a > 10 {
}
@ -248,7 +248,7 @@ fn foo() {
r"
fn bar(a: usize): usize { a }
fn foo() {
let a<|> = bar(1) as u64;
let a$0 = bar(1) as u64;
a + 1;
if a > 10 {
}
@ -281,7 +281,7 @@ fn foo() {
inline_local_variable,
r"
fn foo() {
let a<|> = { 10 + 1 };
let a$0 = { 10 + 1 };
a + 1;
if a > 10 {
}
@ -313,7 +313,7 @@ fn foo() {
inline_local_variable,
r"
fn foo() {
let a<|> = ( 10 + 1 );
let a$0 = ( 10 + 1 );
a + 1;
if a > 10 {
}
@ -346,7 +346,7 @@ fn foo() {
inline_local_variable,
r"
fn foo() {
let mut a<|> = 1 + 1;
let mut a$0 = 1 + 1;
a + 1;
}",
);
@ -358,7 +358,7 @@ fn foo() {
inline_local_variable,
r"
fn foo() {
let a<|> = bar(10 + 1);
let a$0 = bar(10 + 1);
let b = a * 10;
let c = a as usize;
}",
@ -377,7 +377,7 @@ fn foo() {
r"
fn foo() {
let x = vec![1, 2, 3];
let a<|> = x[0];
let a$0 = x[0];
let b = a * 10;
let c = a as usize;
}",
@ -397,7 +397,7 @@ fn foo() {
r"
fn foo() {
let bar = vec![1];
let a<|> = bar.len();
let a$0 = bar.len();
let b = a * 10;
let c = a as usize;
}",
@ -421,7 +421,7 @@ struct Bar {
fn foo() {
let bar = Bar { foo: 1 };
let a<|> = bar.foo;
let a$0 = bar.foo;
let b = a * 10;
let c = a as usize;
}",
@ -445,7 +445,7 @@ fn foo() {
r"
fn foo() -> Option<usize> {
let bar = Some(1);
let a<|> = bar?;
let a$0 = bar?;
let b = a * 10;
let c = a as usize;
None
@ -467,7 +467,7 @@ fn foo() -> Option<usize> {
r"
fn foo() {
let bar = 10;
let a<|> = &bar;
let a$0 = &bar;
let b = a * 10;
}",
r"
@ -484,7 +484,7 @@ fn foo() {
inline_local_variable,
r"
fn foo() {
let a<|> = (10, 20);
let a$0 = (10, 20);
let b = a[0];
}",
r"
@ -500,7 +500,7 @@ fn foo() {
inline_local_variable,
r"
fn foo() {
let a<|> = [1, 2, 3];
let a$0 = [1, 2, 3];
let b = a.len();
}",
r"
@ -516,7 +516,7 @@ fn foo() {
inline_local_variable,
r"
fn foo() {
let a<|> = (10 + 20);
let a$0 = (10 + 20);
let b = a * 10;
let c = a as usize;
}",
@ -535,7 +535,7 @@ fn foo() {
r"
fn foo() {
let d = 10;
let a<|> = d;
let a$0 = d;
let b = a * 10;
let c = a as usize;
}",
@ -554,7 +554,7 @@ fn foo() {
inline_local_variable,
r"
fn foo() {
let a<|> = { 10 };
let a$0 = { 10 };
let b = a * 10;
let c = a as usize;
}",
@ -572,7 +572,7 @@ fn foo() {
inline_local_variable,
r"
fn foo() {
let a<|> = 10 + 20;
let a$0 = 10 + 20;
let b = a * 10;
let c = (a, 20);
let d = [a, 10];
@ -594,7 +594,7 @@ fn foo() {
inline_local_variable,
r"
fn foo() {
let a<|> = vec![10, 20];
let a$0 = vec![10, 20];
for i in a {}
}",
r"
@ -610,7 +610,7 @@ fn foo() {
inline_local_variable,
r"
fn foo() {
let a<|> = 1 > 0;
let a$0 = 1 > 0;
while a {}
}",
r"
@ -626,7 +626,7 @@ fn foo() {
inline_local_variable,
r"
fn foo() {
let a<|> = 1 + 1;
let a$0 = 1 + 1;
loop {
break a;
}
@ -646,7 +646,7 @@ fn foo() {
inline_local_variable,
r"
fn foo() {
let a<|> = 1 > 0;
let a$0 = 1 > 0;
return a;
}",
r"
@ -662,7 +662,7 @@ fn foo() {
inline_local_variable,
r"
fn foo() {
let a<|> = 1 > 0;
let a$0 = 1 > 0;
match a {}
}",
r"
@ -680,7 +680,7 @@ fn foo() {
r"
struct S { foo: i32}
fn main() {
let <|>foo = 92;
let $0foo = 92;
S { foo }
}
",
@ -700,7 +700,7 @@ fn main() {
inline_local_variable,
r"
fn foo() {
let <|>a = 0;
let $0a = 0;
}
",
)
@ -713,7 +713,7 @@ fn foo() {
inline_local_variable,
r"
fn main() {
let x = <|>1 + 2;
let x = $01 + 2;
x * 4;
}
",

View file

@ -14,7 +14,7 @@ static ASSIST_LABEL: &str = "Introduce named lifetime";
// Change an anonymous lifetime to a named lifetime.
//
// ```
// impl Cursor<'_<|>> {
// impl Cursor<'_$0> {
// fn node(self) -> &SyntaxNode {
// match self {
// Cursor::Replace(node) | Cursor::Before(node) => node,
@ -33,7 +33,7 @@ static ASSIST_LABEL: &str = "Introduce named lifetime";
// }
// ```
// FIXME: How can we handle renaming any one of multiple anonymous lifetimes?
// FIXME: should also add support for the case fun(f: &Foo) -> &<|>Foo
// FIXME: should also add support for the case fun(f: &Foo) -> &$0Foo
pub(crate) fn introduce_named_lifetime(acc: &mut Assists, ctx: &AssistContext) -> Option<()> {
let lifetime =
ctx.find_node_at_offset::<ast::Lifetime>().filter(|lifetime| lifetime.text() == "'_")?;
@ -150,7 +150,7 @@ mod tests {
fn test_example_case() {
check_assist(
introduce_named_lifetime,
r#"impl Cursor<'_<|>> {
r#"impl Cursor<'_$0> {
fn node(self) -> &SyntaxNode {
match self {
Cursor::Replace(node) | Cursor::Before(node) => node,
@ -171,7 +171,7 @@ mod tests {
fn test_example_case_simplified() {
check_assist(
introduce_named_lifetime,
r#"impl Cursor<'_<|>> {"#,
r#"impl Cursor<'_$0> {"#,
r#"impl<'a> Cursor<'a> {"#,
);
}
@ -180,7 +180,7 @@ mod tests {
fn test_example_case_cursor_after_tick() {
check_assist(
introduce_named_lifetime,
r#"impl Cursor<'<|>_> {"#,
r#"impl Cursor<'$0_> {"#,
r#"impl<'a> Cursor<'a> {"#,
);
}
@ -189,7 +189,7 @@ mod tests {
fn test_impl_with_other_type_param() {
check_assist(
introduce_named_lifetime,
"impl<I> fmt::Display for SepByBuilder<'_<|>, I>
"impl<I> fmt::Display for SepByBuilder<'_$0, I>
where
I: Iterator,
I::Item: fmt::Display,
@ -206,28 +206,28 @@ mod tests {
fn test_example_case_cursor_before_tick() {
check_assist(
introduce_named_lifetime,
r#"impl Cursor<<|>'_> {"#,
r#"impl Cursor<$0'_> {"#,
r#"impl<'a> Cursor<'a> {"#,
);
}
#[test]
fn test_not_applicable_cursor_position() {
check_assist_not_applicable(introduce_named_lifetime, r#"impl Cursor<'_><|> {"#);
check_assist_not_applicable(introduce_named_lifetime, r#"impl Cursor<|><'_> {"#);
check_assist_not_applicable(introduce_named_lifetime, r#"impl Cursor<'_>$0 {"#);
check_assist_not_applicable(introduce_named_lifetime, r#"impl Cursor$0<'_> {"#);
}
#[test]
fn test_not_applicable_lifetime_already_name() {
check_assist_not_applicable(introduce_named_lifetime, r#"impl Cursor<'a<|>> {"#);
check_assist_not_applicable(introduce_named_lifetime, r#"fn my_fun<'a>() -> X<'a<|>>"#);
check_assist_not_applicable(introduce_named_lifetime, r#"impl Cursor<'a$0> {"#);
check_assist_not_applicable(introduce_named_lifetime, r#"fn my_fun<'a>() -> X<'a$0>"#);
}
#[test]
fn test_with_type_parameter() {
check_assist(
introduce_named_lifetime,
r#"impl<T> Cursor<T, '_<|>>"#,
r#"impl<T> Cursor<T, '_$0>"#,
r#"impl<T, 'a> Cursor<T, 'a>"#,
);
}
@ -236,7 +236,7 @@ mod tests {
fn test_with_existing_lifetime_name_conflict() {
check_assist(
introduce_named_lifetime,
r#"impl<'a, 'b> Cursor<'a, 'b, '_<|>>"#,
r#"impl<'a, 'b> Cursor<'a, 'b, '_$0>"#,
r#"impl<'a, 'b, 'c> Cursor<'a, 'b, 'c>"#,
);
}
@ -245,7 +245,7 @@ mod tests {
fn test_function_return_value_anon_lifetime_param() {
check_assist(
introduce_named_lifetime,
r#"fn my_fun() -> X<'_<|>>"#,
r#"fn my_fun() -> X<'_$0>"#,
r#"fn my_fun<'a>() -> X<'a>"#,
);
}
@ -254,7 +254,7 @@ mod tests {
fn test_function_return_value_anon_reference_lifetime() {
check_assist(
introduce_named_lifetime,
r#"fn my_fun() -> &'_<|> X"#,
r#"fn my_fun() -> &'_$0 X"#,
r#"fn my_fun<'a>() -> &'a X"#,
);
}
@ -263,7 +263,7 @@ mod tests {
fn test_function_param_anon_lifetime() {
check_assist(
introduce_named_lifetime,
r#"fn my_fun(x: X<'_<|>>)"#,
r#"fn my_fun(x: X<'_$0>)"#,
r#"fn my_fun<'a>(x: X<'a>)"#,
);
}
@ -272,7 +272,7 @@ mod tests {
fn test_function_add_lifetime_to_params() {
check_assist(
introduce_named_lifetime,
r#"fn my_fun(f: &Foo) -> X<'_<|>>"#,
r#"fn my_fun(f: &Foo) -> X<'_$0>"#,
r#"fn my_fun<'a>(f: &'a Foo) -> X<'a>"#,
);
}
@ -281,7 +281,7 @@ mod tests {
fn test_function_add_lifetime_to_params_in_presence_of_other_lifetime() {
check_assist(
introduce_named_lifetime,
r#"fn my_fun<'other>(f: &Foo, b: &'other Bar) -> X<'_<|>>"#,
r#"fn my_fun<'other>(f: &Foo, b: &'other Bar) -> X<'_$0>"#,
r#"fn my_fun<'other, 'a>(f: &'a Foo, b: &'other Bar) -> X<'a>"#,
);
}
@ -291,7 +291,7 @@ mod tests {
// this is not permitted under lifetime elision rules
check_assist_not_applicable(
introduce_named_lifetime,
r#"fn my_fun(f: &Foo, b: &Bar) -> X<'_<|>>"#,
r#"fn my_fun(f: &Foo, b: &Bar) -> X<'_$0>"#,
);
}
@ -299,7 +299,7 @@ mod tests {
fn test_function_add_lifetime_to_self_ref_param() {
check_assist(
introduce_named_lifetime,
r#"fn my_fun<'other>(&self, f: &Foo, b: &'other Bar) -> X<'_<|>>"#,
r#"fn my_fun<'other>(&self, f: &Foo, b: &'other Bar) -> X<'_$0>"#,
r#"fn my_fun<'other, 'a>(&'a self, f: &Foo, b: &'other Bar) -> X<'a>"#,
);
}
@ -308,7 +308,7 @@ mod tests {
fn test_function_add_lifetime_to_param_with_non_ref_self() {
check_assist(
introduce_named_lifetime,
r#"fn my_fun<'other>(self, f: &Foo, b: &'other Bar) -> X<'_<|>>"#,
r#"fn my_fun<'other>(self, f: &Foo, b: &'other Bar) -> X<'_$0>"#,
r#"fn my_fun<'other, 'a>(self, f: &'a Foo, b: &'other Bar) -> X<'a>"#,
);
}

View file

@ -18,7 +18,7 @@ use crate::{
//
// ```
// fn main() {
// if<|> !y { A } else { B }
// if$0 !y { A } else { B }
// }
// ```
// ->
@ -72,7 +72,7 @@ mod tests {
fn invert_if_composite_condition() {
check_assist(
invert_if,
"fn f() { i<|>f x == 3 || x == 4 || x == 5 { 1 } else { 3 * 2 } }",
"fn f() { i$0f x == 3 || x == 4 || x == 5 { 1 } else { 3 * 2 } }",
"fn f() { if !(x == 3 || x == 4 || x == 5) { 3 * 2 } else { 1 } }",
)
}
@ -81,7 +81,7 @@ mod tests {
fn invert_if_remove_not_parentheses() {
check_assist(
invert_if,
"fn f() { i<|>f !(x == 3 || x == 4 || x == 5) { 3 * 2 } else { 1 } }",
"fn f() { i$0f !(x == 3 || x == 4 || x == 5) { 3 * 2 } else { 1 } }",
"fn f() { if x == 3 || x == 4 || x == 5 { 1 } else { 3 * 2 } }",
)
}
@ -90,7 +90,7 @@ mod tests {
fn invert_if_remove_inequality() {
check_assist(
invert_if,
"fn f() { i<|>f x != 3 { 1 } else { 3 + 2 } }",
"fn f() { i$0f x != 3 { 1 } else { 3 + 2 } }",
"fn f() { if x == 3 { 3 + 2 } else { 1 } }",
)
}
@ -99,7 +99,7 @@ mod tests {
fn invert_if_remove_not() {
check_assist(
invert_if,
"fn f() { <|>if !cond { 3 * 2 } else { 1 } }",
"fn f() { $0if !cond { 3 * 2 } else { 1 } }",
"fn f() { if cond { 1 } else { 3 * 2 } }",
)
}
@ -108,21 +108,21 @@ mod tests {
fn invert_if_general_case() {
check_assist(
invert_if,
"fn f() { i<|>f cond { 3 * 2 } else { 1 } }",
"fn f() { i$0f cond { 3 * 2 } else { 1 } }",
"fn f() { if !cond { 1 } else { 3 * 2 } }",
)
}
#[test]
fn invert_if_doesnt_apply_with_cursor_not_on_if() {
check_assist_not_applicable(invert_if, "fn f() { if !<|>cond { 3 * 2 } else { 1 } }")
check_assist_not_applicable(invert_if, "fn f() { if !$0cond { 3 * 2 } else { 1 } }")
}
#[test]
fn invert_if_doesnt_apply_with_if_let() {
check_assist_not_applicable(
invert_if,
"fn f() { i<|>f let Some(_) = Some(1) { 1 } else { 0 } }",
"fn f() { i$0f let Some(_) = Some(1) { 1 } else { 0 } }",
)
}
@ -130,7 +130,7 @@ mod tests {
fn invert_if_option_case() {
check_assist(
invert_if,
"fn f() { if<|> doc_style.is_some() { Class::DocComment } else { Class::Comment } }",
"fn f() { if$0 doc_style.is_some() { Class::DocComment } else { Class::Comment } }",
"fn f() { if doc_style.is_none() { Class::Comment } else { Class::DocComment } }",
)
}
@ -139,7 +139,7 @@ mod tests {
fn invert_if_result_case() {
check_assist(
invert_if,
"fn f() { i<|>f doc_style.is_err() { Class::Err } else { Class::Ok } }",
"fn f() { i$0f doc_style.is_err() { Class::Err } else { Class::Ok } }",
"fn f() { if doc_style.is_ok() { Class::Ok } else { Class::Err } }",
)
}

View file

@ -15,7 +15,7 @@ use crate::{
// Merges two imports with a common prefix.
//
// ```
// use std::<|>fmt::Formatter;
// use std::$0fmt::Formatter;
// use std::io;
// ```
// ->
@ -75,7 +75,7 @@ mod tests {
check_assist(
merge_imports,
r"
use std::fmt<|>::{Display, Debug};
use std::fmt$0::{Display, Debug};
use std::fmt::{Display, Debug};
",
r"
@ -89,7 +89,7 @@ use std::fmt::{Debug, Display};
check_assist(
merge_imports,
r"
use std::fmt<|>::Debug;
use std::fmt$0::Debug;
use std::fmt::Display;
",
r"
@ -104,7 +104,7 @@ use std::fmt::{Debug, Display};
merge_imports,
r"
use std::fmt::Debug;
use std::fmt<|>::Display;
use std::fmt$0::Display;
",
r"
use std::fmt::{Debug, Display};
@ -117,7 +117,7 @@ use std::fmt::{Debug, Display};
check_assist(
merge_imports,
r"
use std::fmt<|>;
use std::fmt$0;
use std::fmt::Display;
",
r"
@ -131,7 +131,7 @@ use std::fmt::{self, Display};
check_assist(
merge_imports,
r"
use std::{fmt, <|>fmt::Display};
use std::{fmt, $0fmt::Display};
",
r"
use std::{fmt::{self, Display}};
@ -144,7 +144,7 @@ use std::{fmt::{self, Display}};
check_assist_not_applicable(
merge_imports,
r"
pub use std::fmt<|>::Debug;
pub use std::fmt$0::Debug;
use std::fmt::Display;
",
);
@ -155,7 +155,7 @@ use std::fmt::Display;
check_assist_not_applicable(
merge_imports,
r"
use std::fmt<|>::Debug;
use std::fmt$0::Debug;
pub use std::fmt::Display;
",
);
@ -166,7 +166,7 @@ pub use std::fmt::Display;
check_assist_not_applicable(
merge_imports,
r"
pub(crate) use std::fmt<|>::Debug;
pub(crate) use std::fmt$0::Debug;
pub use std::fmt::Display;
",
);
@ -177,7 +177,7 @@ pub use std::fmt::Display;
check_assist_not_applicable(
merge_imports,
r"
pub use std::fmt<|>::Debug;
pub use std::fmt$0::Debug;
pub(crate) use std::fmt::Display;
",
);
@ -188,7 +188,7 @@ pub(crate) use std::fmt::Display;
check_assist(
merge_imports,
r"
pub use std::fmt<|>::Debug;
pub use std::fmt$0::Debug;
pub use std::fmt::Display;
",
r"
@ -202,7 +202,7 @@ pub use std::fmt::{Debug, Display};
check_assist(
merge_imports,
r"
pub(crate) use std::fmt<|>::Debug;
pub(crate) use std::fmt$0::Debug;
pub(crate) use std::fmt::Display;
",
r"
@ -216,7 +216,7 @@ pub(crate) use std::fmt::{Debug, Display};
check_assist(
merge_imports,
r"
use std::{fmt<|>::Debug, fmt::Display};
use std::{fmt$0::Debug, fmt::Display};
",
r"
use std::{fmt::{Debug, Display}};
@ -229,7 +229,7 @@ use std::{fmt::{Debug, Display}};
check_assist(
merge_imports,
r"
use std::{fmt::Debug, fmt<|>::Display};
use std::{fmt::Debug, fmt$0::Display};
",
r"
use std::{fmt::{Debug, Display}};
@ -242,7 +242,7 @@ use std::{fmt::{Debug, Display}};
check_assist(
merge_imports,
r"
use std<|>::cell::*;
use std$0::cell::*;
use std::str;
",
r"
@ -256,7 +256,7 @@ use std::{cell::*, str};
check_assist(
merge_imports,
r"
use std<|>::cell::*;
use std$0::cell::*;
use std::str::*;
",
r"
@ -270,7 +270,7 @@ use std::{cell::*, str::*};
check_assist(
merge_imports,
r"
use foo<|>::bar;
use foo$0::bar;
use foo::baz;
/// Doc comment
@ -289,7 +289,7 @@ use foo::{bar, baz};
merge_imports,
r"
use {
foo<|>::bar,
foo$0::bar,
foo::baz,
};
",
@ -304,7 +304,7 @@ use {
r"
use {
foo::baz,
foo<|>::bar,
foo$0::bar,
};
",
r"
@ -321,7 +321,7 @@ use {
merge_imports,
r"
use foo::bar::baz;
use foo::<|>{
use foo::$0{
FooBar,
};
",
@ -336,7 +336,7 @@ use foo::{FooBar, bar::baz};
check_assist_not_applicable(
merge_imports,
r"
use std::<|>
use std::$0
fn main() {}",
);
}

View file

@ -17,7 +17,7 @@ use crate::{AssistContext, AssistId, AssistKind, Assists, TextRange};
//
// fn handle(action: Action) {
// match action {
// <|>Action::Move(..) => foo(),
// $0Action::Move(..) => foo(),
// Action::Stop => foo(),
// }
// }
@ -106,7 +106,7 @@ mod tests {
fn main() {
let x = X::A;
let y = match x {
X::A => { 1i32<|> }
X::A => { 1i32$0 }
X::B => { 1i32 }
X::C => { 2i32 }
}
@ -138,7 +138,7 @@ mod tests {
fn main() {
let x = X::A;
let y = match x {
X::A | X::B => {<|> 1i32 },
X::A | X::B => {$0 1i32 },
X::C | X::D => { 1i32 },
X::E => { 2i32 },
}
@ -171,7 +171,7 @@ mod tests {
let x = X::A;
let y = match x {
X::A => { 1i32 },
X::B => { 2i<|>32 },
X::B => { 2i$032 },
_ => { 2i32 }
}
}
@ -200,7 +200,7 @@ mod tests {
fn main() {
match X::A {
X::A<|> => 92,
X::A$0 => 92,
X::B => 92,
X::C => 92,
X::D => 62,
@ -237,7 +237,7 @@ mod tests {
fn main() {
let x = X::A;
let y = match x {
X::A(a) if a > 5 => { <|>1i32 },
X::A(a) if a > 5 => { $01i32 },
X::B => { 1i32 },
X::C => { 2i32 }
}

View file

@ -12,7 +12,7 @@ use crate::{AssistContext, AssistId, AssistKind, Assists};
// Moves inline type bounds to a where clause.
//
// ```
// fn apply<T, U, <|>F: FnOnce(T) -> U>(f: F, x: T) -> U {
// fn apply<T, U, $0F: FnOnce(T) -> U>(f: F, x: T) -> U {
// f(x)
// }
// ```
@ -103,7 +103,7 @@ mod tests {
check_assist(
move_bounds_to_where_clause,
r#"
fn foo<T: u32, <|>F: FnOnce(T) -> T>() {}
fn foo<T: u32, $0F: FnOnce(T) -> T>() {}
"#,
r#"
fn foo<T, F>() where T: u32, F: FnOnce(T) -> T {}
@ -116,7 +116,7 @@ mod tests {
check_assist(
move_bounds_to_where_clause,
r#"
impl<U: u32, <|>T> A<U, T> {}
impl<U: u32, $0T> A<U, T> {}
"#,
r#"
impl<U, T> A<U, T> where U: u32 {}
@ -129,7 +129,7 @@ mod tests {
check_assist(
move_bounds_to_where_clause,
r#"
struct A<<|>T: Iterator<Item = u32>> {}
struct A<$0T: Iterator<Item = u32>> {}
"#,
r#"
struct A<T> where T: Iterator<Item = u32> {}
@ -142,7 +142,7 @@ mod tests {
check_assist(
move_bounds_to_where_clause,
r#"
struct Pair<<|>T: u32>(T, T);
struct Pair<$0T: u32>(T, T);
"#,
r#"
struct Pair<T>(T, T) where T: u32;

View file

@ -14,7 +14,7 @@ use crate::{AssistContext, AssistId, AssistKind, Assists};
//
// fn handle(action: Action) {
// match action {
// Action::Move { distance } <|>if distance > 10 => foo(),
// Action::Move { distance } $0if distance > 10 => foo(),
// _ => (),
// }
// }
@ -74,7 +74,7 @@ pub(crate) fn move_guard_to_arm_body(acc: &mut Assists, ctx: &AssistContext) ->
//
// fn handle(action: Action) {
// match action {
// Action::Move { distance } => <|>if distance > 10 { foo() },
// Action::Move { distance } => $0if distance > 10 { foo() },
// _ => (),
// }
// }
@ -158,7 +158,7 @@ mod tests {
r#"
fn main() {
match 92 {
x <|>if x > 10 => false,
x $0if x > 10 => false,
_ => true
}
}
@ -174,7 +174,7 @@ fn main() {
r#"
fn main() {
match 92 {
x <|>if x > 10 => false,
x $0if x > 10 => false,
_ => true
}
}
@ -199,7 +199,7 @@ fn main() {
r#"
fn main() {
match 92 {
<|>x @ 4 | x @ 5 if x > 5 => true,
$0x @ 4 | x @ 5 if x > 5 => true,
_ => false
}
}
@ -224,7 +224,7 @@ fn main() {
r#"
fn main() {
match 92 {
x => if x > 10 { <|>false },
x => if x > 10 { $0false },
_ => true
}
}
@ -248,7 +248,7 @@ fn main() {
fn main() {
match 92 {
x => {
<|>if x > 10 {
$0if x > 10 {
false
}
},
@ -274,7 +274,7 @@ fn main() {
r#"
fn main() {
match 92 {
x => if let 62 = x { <|>false },
x => if let 62 = x { $0false },
_ => true
}
}
@ -289,7 +289,7 @@ fn main() {
r#"
fn main() {
match 92 {
x => if x > 10 { <|> },
x => if x > 10 { $0 },
_ => true
}
}
@ -313,7 +313,7 @@ fn main() {
fn main() {
match 92 {
x => if x > 10 {
92;<|>
92;$0
false
},
_ => true
@ -343,7 +343,7 @@ fn main() {
match 92 {
x => {
if x > 10 {
92;<|>
92;$0
false
}
}

View file

@ -13,7 +13,7 @@ use crate::{AssistContext, AssistId, AssistKind, Assists};
// Moves inline module's contents to a separate file.
//
// ```
// mod <|>foo {
// mod $0foo {
// fn t() {}
// }
// ```
@ -78,7 +78,7 @@ mod tests {
check_assist(
move_module_to_file,
r#"
mod <|>tests {
mod $0tests {
#[test] fn t() {}
}
"#,
@ -99,7 +99,7 @@ mod tests;
//- /main.rs
mod submod;
//- /submod.rs
<|>mod inner {
$0mod inner {
fn f() {}
}
fn g() {}
@ -122,7 +122,7 @@ fn f() {}
//- /main.rs
mod submodule;
//- /submodule/mod.rs
mod inner<|> {
mod inner$0 {
fn f() {}
}
fn g() {}
@ -140,6 +140,6 @@ fn f() {}
#[test]
fn available_before_curly() {
mark::check!(available_before_curly);
check_assist_not_applicable(move_module_to_file, r#"mod m { <|> }"#);
check_assist_not_applicable(move_module_to_file, r#"mod m { $0 }"#);
}
}

View file

@ -18,7 +18,7 @@ use crate::{
// let mut foo = 6;
//
// if true {
// <|>foo = 5;
// $0foo = 5;
// } else {
// foo = 4;
// }
@ -175,7 +175,7 @@ fn foo() {
let mut a = 1;
if true {
<|>a = 2;
$0a = 2;
} else {
a = 3;
}
@ -203,7 +203,7 @@ fn foo() {
match 1 {
1 => {
<|>a = 2;
$0a = 2;
},
2 => {
a = 3;
@ -241,7 +241,7 @@ fn foo() {
let mut a = 1;
if true {
<|>a = 2;
$0a = 2;
b = a;
} else {
a = 3;
@ -260,7 +260,7 @@ fn foo() {
let mut a = 1;
if true {
<|>a = 2;
$0a = 2;
} else if false {
a = 3;
} else {
@ -292,7 +292,7 @@ fn foo() {
if true {
let b = 2;
<|>a = 2;
$0a = 2;
} else {
let b = 3;
a = 3;
@ -322,7 +322,7 @@ fn foo() {
let mut a = 1;
let b = if true {
<|>a = 2
$0a = 2
} else {
a = 3
};
@ -339,7 +339,7 @@ fn foo() {
let mut a = 1;
if true {
<|>a = 2;
$0a = 2;
} else {}
}"#,
)
@ -355,7 +355,7 @@ fn foo() {
match 1 {
1 => {
<|>a = 2;
$0a = 2;
},
2 => {
a = 3;
@ -378,7 +378,7 @@ fn foo() {
let mut a = A(1);
if true {
<|>a.0 = 2;
$0a.0 = 2;
} else {
a.0 = 3;
}

View file

@ -22,7 +22,7 @@ use crate::{
//
// ```
// fn main() {
// let map = HashMap<|>::new();
// let map = HashMap$0::new();
// }
// # pub mod std { pub mod collections { pub struct HashMap { } } }
// ```
@ -221,7 +221,7 @@ mod tests {
use std::fmt;
<|>Formatter
$0Formatter
",
r"
mod std {
@ -242,7 +242,7 @@ mod tests {
check_assist(
qualify_path,
r"
<|>PubStruct
$0PubStruct
pub mod PubMod {
pub struct PubStruct;
@ -266,7 +266,7 @@ mod tests {
macro_rules! foo {
($i:ident) => { fn foo(a: $i) {} }
}
foo!(Pub<|>Struct);
foo!(Pub$0Struct);
pub mod PubMod {
pub struct PubStruct;
@ -290,7 +290,7 @@ mod tests {
check_assist(
qualify_path,
r"
PubSt<|>ruct
PubSt$0ruct
pub mod PubMod1 {
pub struct PubStruct;
@ -325,7 +325,7 @@ mod tests {
r"
use PubMod::PubStruct;
PubStruct<|>
PubStruct$0
pub mod PubMod {
pub struct PubStruct;
@ -339,7 +339,7 @@ mod tests {
check_assist_not_applicable(
qualify_path,
r"
PrivateStruct<|>
PrivateStruct$0
pub mod PubMod {
struct PrivateStruct;
@ -353,7 +353,7 @@ mod tests {
check_assist_not_applicable(
qualify_path,
"
PubStruct<|>",
PubStruct$0",
);
}
@ -362,7 +362,7 @@ mod tests {
check_assist_not_applicable(
qualify_path,
r"
use PubStruct<|>;
use PubStruct$0;
pub mod PubMod {
pub struct PubStruct;
@ -375,7 +375,7 @@ mod tests {
check_assist(
qualify_path,
r"
test_function<|>
test_function$0
pub mod PubMod {
pub fn test_function() {};
@ -404,7 +404,7 @@ macro_rules! foo {
//- /main.rs crate:main deps:crate_with_macro
fn main() {
foo<|>
foo$0
}
",
r"
@ -421,7 +421,7 @@ fn main() {
qualify_path,
r"
struct AssistInfo {
group_label: Option<<|>GroupLabel>,
group_label: Option<$0GroupLabel>,
}
mod m { pub struct GroupLabel; }
@ -445,7 +445,7 @@ fn main() {
use mod1::mod2;
fn main() {
mod2::mod3::TestStruct<|>
mod2::mod3::TestStruct$0
}
",
);
@ -462,7 +462,7 @@ fn main() {
use test_mod::test_function;
fn main() {
test_function<|>
test_function$0
}
",
);
@ -481,7 +481,7 @@ fn main() {
}
fn main() {
TestStruct::test_function<|>
TestStruct::test_function$0
}
",
r"
@ -513,7 +513,7 @@ fn main() {
}
fn main() {
TestStruct::TEST_CONST<|>
TestStruct::TEST_CONST$0
}
",
r"
@ -547,7 +547,7 @@ fn main() {
}
fn main() {
test_mod::TestStruct::test_function<|>
test_mod::TestStruct::test_function$0
}
",
r"
@ -594,7 +594,7 @@ fn main() {
use test_mod::TestTrait2;
fn main() {
test_mod::TestEnum::test_function<|>;
test_mod::TestEnum::test_function$0;
}
",
)
@ -617,7 +617,7 @@ fn main() {
}
fn main() {
test_mod::TestStruct::TEST_CONST<|>
test_mod::TestStruct::TEST_CONST$0
}
",
r"
@ -664,7 +664,7 @@ fn main() {
use test_mod::TestTrait2;
fn main() {
test_mod::TestEnum::TEST_CONST<|>;
test_mod::TestEnum::TEST_CONST$0;
}
",
)
@ -688,7 +688,7 @@ fn main() {
fn main() {
let test_struct = test_mod::TestStruct {};
test_struct.test_meth<|>od()
test_struct.test_meth$0od()
}
",
r"
@ -727,7 +727,7 @@ fn main() {
fn main() {
let test_struct = test_mod::TestStruct {};
test_struct.test_meth<|>od(42)
test_struct.test_meth$0od(42)
}
",
r"
@ -766,7 +766,7 @@ fn main() {
fn main() {
let test_struct = test_mod::TestStruct {};
test_struct.test_meth<|>od()
test_struct.test_meth$0od()
}
",
r"
@ -796,7 +796,7 @@ fn main() {
//- /main.rs crate:main deps:dep
fn main() {
let test_struct = dep::test_mod::TestStruct {};
test_struct.test_meth<|>od()
test_struct.test_meth$0od()
}
//- /dep.rs crate:dep
pub mod test_mod {
@ -825,7 +825,7 @@ fn main() {
r"
//- /main.rs crate:main deps:dep
fn main() {
dep::test_mod::TestStruct::test_func<|>tion
dep::test_mod::TestStruct::test_func$0tion
}
//- /dep.rs crate:dep
pub mod test_mod {
@ -853,7 +853,7 @@ fn main() {
r"
//- /main.rs crate:main deps:dep
fn main() {
dep::test_mod::TestStruct::CONST<|>
dep::test_mod::TestStruct::CONST$0
}
//- /dep.rs crate:dep
pub mod test_mod {
@ -882,7 +882,7 @@ fn main() {
//- /main.rs crate:main deps:dep
fn main() {
let test_struct = dep::test_mod::TestStruct {};
test_struct.test_func<|>tion()
test_struct.test_func$0tion()
}
//- /dep.rs crate:dep
pub mod test_mod {
@ -906,7 +906,7 @@ fn main() {
//- /main.rs crate:main deps:dep
fn main() {
let test_struct = dep::test_mod::TestStruct {};
test_struct.test_meth<|>od()
test_struct.test_meth$0od()
}
//- /dep.rs crate:dep
pub mod test_mod {
@ -949,7 +949,7 @@ fn main() {
use test_mod::TestTrait2;
fn main() {
let one = test_mod::TestEnum::One;
one.test<|>_method();
one.test$0_method();
}
",
)
@ -965,7 +965,7 @@ pub struct Struct;
//- /main.rs crate:main deps:dep
fn main() {
Struct<|>
Struct$0
}
",
r"
@ -992,7 +992,7 @@ pub fn panic_fmt() {}
//- /main.rs crate:main deps:dep
struct S;
impl f<|>mt::Display for S {}
impl f$0mt::Display for S {}
",
r"
struct S;
@ -1019,7 +1019,7 @@ mac!();
//- /main.rs crate:main deps:dep
fn main() {
Cheese<|>;
Cheese$0;
}
",
r"
@ -1042,7 +1042,7 @@ pub struct fmt;
//- /main.rs crate:main deps:dep
fn main() {
FMT<|>;
FMT$0;
}
",
r"
@ -1062,7 +1062,7 @@ fn main() {
pub mod generic { pub struct Thing<'a, T>(&'a T); }
//- /main.rs crate:main deps:dep
fn foo() -> Thin<|>g<'static, ()> {}
fn foo() -> Thin$0g<'static, ()> {}
fn main() {}
",
@ -1083,7 +1083,7 @@ fn main() {}
pub mod generic { pub struct Thing<'a, T>(&'a T); }
//- /main.rs crate:main deps:dep
fn foo() -> Thin<|>g::<'static, ()> {}
fn foo() -> Thin$0g::<'static, ()> {}
fn main() {}
",
@ -1108,7 +1108,7 @@ fn main() {}
}
fn main() {
TestStruct::<()>::TEST_CONST<|>
TestStruct::<()>::TEST_CONST$0
}
",
r"
@ -1142,7 +1142,7 @@ fn main() {}
}
fn main() {
test_mod::TestStruct::<()>::TEST_CONST<|>
test_mod::TestStruct::<()>::TEST_CONST$0
}
",
r"
@ -1180,7 +1180,7 @@ fn main() {}
fn main() {
let test_struct = test_mod::TestStruct {};
test_struct.test_meth<|>od::<()>()
test_struct.test_meth$0od::<()>()
}
",
r"

View file

@ -11,7 +11,7 @@ use crate::{AssistContext, AssistId, AssistKind, Assists};
//
// ```
// fn main() {
// "Hello,<|> World!";
// "Hello,$0 World!";
// }
// ```
// ->
@ -53,7 +53,7 @@ pub(crate) fn make_raw_string(acc: &mut Assists, ctx: &AssistContext) -> Option<
//
// ```
// fn main() {
// r#"Hello,<|> "World!""#;
// r#"Hello,$0 "World!""#;
// }
// ```
// ->
@ -95,7 +95,7 @@ pub(crate) fn make_usual_string(acc: &mut Assists, ctx: &AssistContext) -> Optio
//
// ```
// fn main() {
// r#"Hello,<|> World!"#;
// r#"Hello,$0 World!"#;
// }
// ```
// ->
@ -123,7 +123,7 @@ pub(crate) fn add_hash(acc: &mut Assists, ctx: &AssistContext) -> Option<()> {
//
// ```
// fn main() {
// r#"Hello,<|> World!"#;
// r#"Hello,$0 World!"#;
// }
// ```
// ->
@ -194,7 +194,7 @@ mod tests {
make_raw_string,
r#"
fn f() {
let s = <|>"random\nstring";
let s = $0"random\nstring";
}
"#,
r#""random\nstring""#,
@ -207,7 +207,7 @@ mod tests {
make_raw_string,
r#"
fn f() {
let s = <|>"random\nstring";
let s = $0"random\nstring";
}
"#,
r##"
@ -225,7 +225,7 @@ string"#;
make_raw_string,
r#"
fn f() {
format!(<|>"x = {}", 92)
format!($0"x = {}", 92)
}
"#,
r##"
@ -242,7 +242,7 @@ string"#;
make_raw_string,
r###"
fn f() {
let s = <|>"#random##\nstring";
let s = $0"#random##\nstring";
}
"###,
r####"
@ -260,7 +260,7 @@ string"#;
make_raw_string,
r###"
fn f() {
let s = <|>"#random\"##\nstring";
let s = $0"#random\"##\nstring";
}
"###,
r####"
@ -278,7 +278,7 @@ string"###;
make_raw_string,
r#"
fn f() {
let s = <|>"random string";
let s = $0"random string";
}
"#,
r##"
@ -295,7 +295,7 @@ string"###;
make_raw_string,
r#"
fn f() {
let s = "foo<|>
let s = "foo$0
}
"#,
)
@ -307,7 +307,7 @@ string"###;
make_usual_string,
r#"
fn main() {
let s = r#"bar<|>
let s = r#"bar$0
}
"#,
)
@ -319,7 +319,7 @@ string"###;
add_hash,
r#"
fn f() {
let s = <|>r"random string";
let s = $0r"random string";
}
"#,
r#"r"random string""#,
@ -332,7 +332,7 @@ string"###;
add_hash,
r#"
fn f() {
let s = <|>r"random string";
let s = $0r"random string";
}
"#,
r##"
@ -349,7 +349,7 @@ string"###;
add_hash,
r##"
fn f() {
let s = <|>r#"random"string"#;
let s = $0r#"random"string"#;
}
"##,
r###"
@ -366,7 +366,7 @@ string"###;
add_hash,
r#"
fn f() {
let s = <|>"random string";
let s = $0"random string";
}
"#,
);
@ -378,7 +378,7 @@ string"###;
remove_hash,
r##"
fn f() {
let s = <|>r#"random string"#;
let s = $0r#"random string"#;
}
"##,
r##"r#"random string"#"##,
@ -389,7 +389,7 @@ string"###;
fn remove_hash_works() {
check_assist(
remove_hash,
r##"fn f() { let s = <|>r#"random string"#; }"##,
r##"fn f() { let s = $0r#"random string"#; }"##,
r#"fn f() { let s = r"random string"; }"#,
)
}
@ -401,7 +401,7 @@ string"###;
remove_hash,
r##"
fn f() {
let s = <|>r#"random"str"ing"#;
let s = $0r#"random"str"ing"#;
}
"##,
)
@ -413,7 +413,7 @@ string"###;
remove_hash,
r###"
fn f() {
let s = <|>r##"random string"##;
let s = $0r##"random string"##;
}
"###,
r##"
@ -426,12 +426,12 @@ string"###;
#[test]
fn remove_hash_doesnt_work() {
check_assist_not_applicable(remove_hash, r#"fn f() { let s = <|>"random string"; }"#);
check_assist_not_applicable(remove_hash, r#"fn f() { let s = $0"random string"; }"#);
}
#[test]
fn remove_hash_no_hash_doesnt_work() {
check_assist_not_applicable(remove_hash, r#"fn f() { let s = <|>r"random string"; }"#);
check_assist_not_applicable(remove_hash, r#"fn f() { let s = $0r"random string"; }"#);
}
#[test]
@ -440,7 +440,7 @@ string"###;
make_usual_string,
r##"
fn f() {
let s = <|>r#"random string"#;
let s = $0r#"random string"#;
}
"##,
r##"r#"random string"#"##,
@ -453,7 +453,7 @@ string"###;
make_usual_string,
r##"
fn f() {
let s = <|>r#"random string"#;
let s = $0r#"random string"#;
}
"##,
r#"
@ -470,7 +470,7 @@ string"###;
make_usual_string,
r##"
fn f() {
let s = <|>r#"random"str"ing"#;
let s = $0r#"random"str"ing"#;
}
"##,
r#"
@ -487,7 +487,7 @@ string"###;
make_usual_string,
r###"
fn f() {
let s = <|>r##"random string"##;
let s = $0r##"random string"##;
}
"###,
r##"
@ -504,7 +504,7 @@ string"###;
make_usual_string,
r#"
fn f() {
let s = <|>"random string";
let s = $0"random string";
}
"#,
);

View file

@ -11,7 +11,7 @@ use crate::{AssistContext, AssistId, AssistKind, Assists};
//
// ```
// fn main() {
// <|>dbg!(92);
// $0dbg!(92);
// }
// ```
// ->
@ -161,19 +161,19 @@ mod tests {
#[test]
fn test_remove_dbg() {
check_assist(remove_dbg, "<|>dbg!(1 + 1)", "1 + 1");
check_assist(remove_dbg, "$0dbg!(1 + 1)", "1 + 1");
check_assist(remove_dbg, "dbg!<|>((1 + 1))", "(1 + 1)");
check_assist(remove_dbg, "dbg!$0((1 + 1))", "(1 + 1)");
check_assist(remove_dbg, "dbg!(1 <|>+ 1)", "1 + 1");
check_assist(remove_dbg, "dbg!(1 $0+ 1)", "1 + 1");
check_assist(remove_dbg, "let _ = <|>dbg!(1 + 1)", "let _ = 1 + 1");
check_assist(remove_dbg, "let _ = $0dbg!(1 + 1)", "let _ = 1 + 1");
check_assist(
remove_dbg,
"
fn foo(n: usize) {
if let Some(_) = dbg!(n.<|>checked_sub(4)) {
if let Some(_) = dbg!(n.$0checked_sub(4)) {
// ...
}
}
@ -187,20 +187,20 @@ fn foo(n: usize) {
",
);
check_assist(remove_dbg, "<|>dbg!(Foo::foo_test()).bar()", "Foo::foo_test().bar()");
check_assist(remove_dbg, "$0dbg!(Foo::foo_test()).bar()", "Foo::foo_test().bar()");
}
#[test]
fn test_remove_dbg_with_brackets_and_braces() {
check_assist(remove_dbg, "dbg![<|>1 + 1]", "1 + 1");
check_assist(remove_dbg, "dbg!{<|>1 + 1}", "1 + 1");
check_assist(remove_dbg, "dbg![$01 + 1]", "1 + 1");
check_assist(remove_dbg, "dbg!{$01 + 1}", "1 + 1");
}
#[test]
fn test_remove_dbg_not_applicable() {
check_assist_not_applicable(remove_dbg, "<|>vec![1, 2, 3]");
check_assist_not_applicable(remove_dbg, "<|>dbg(5, 6, 7)");
check_assist_not_applicable(remove_dbg, "<|>dbg!(5, 6, 7");
check_assist_not_applicable(remove_dbg, "$0vec![1, 2, 3]");
check_assist_not_applicable(remove_dbg, "$0dbg(5, 6, 7)");
check_assist_not_applicable(remove_dbg, "$0dbg!(5, 6, 7");
}
#[test]
@ -209,7 +209,7 @@ fn foo(n: usize) {
remove_dbg,
"
fn foo(n: usize) {
if let Some(_) = dbg!(n.<|>checked_sub(4)) {
if let Some(_) = dbg!(n.$0checked_sub(4)) {
// ...
}
}
@ -226,7 +226,7 @@ fn foo(n: usize) {
// the ast::MacroCall to include the semicolon at the end
check_assist(
remove_dbg,
r#"let res = <|>dbg!(1 * 20); // needless comment"#,
r#"let res = $0dbg!(1 * 20); // needless comment"#,
r#"let res = 1 * 20; // needless comment"#,
);
}
@ -238,7 +238,7 @@ fn foo(n: usize) {
"
fn main() {
let mut a = 1;
while dbg!<|>(a) < 10000 {
while dbg!$0(a) < 10000 {
a += 1;
}
}
@ -258,31 +258,31 @@ fn main() {
fn test_remove_dbg_keep_expression() {
check_assist(
remove_dbg,
r#"let res = <|>dbg!(a + b).foo();"#,
r#"let res = $0dbg!(a + b).foo();"#,
r#"let res = (a + b).foo();"#,
);
check_assist(remove_dbg, r#"let res = <|>dbg!(2 + 2) * 5"#, r#"let res = (2 + 2) * 5"#);
check_assist(remove_dbg, r#"let res = <|>dbg![2 + 2] * 5"#, r#"let res = (2 + 2) * 5"#);
check_assist(remove_dbg, r#"let res = $0dbg!(2 + 2) * 5"#, r#"let res = (2 + 2) * 5"#);
check_assist(remove_dbg, r#"let res = $0dbg![2 + 2] * 5"#, r#"let res = (2 + 2) * 5"#);
}
#[test]
fn test_remove_dbg_method_chaining() {
check_assist(
remove_dbg,
r#"let res = <|>dbg!(foo().bar()).baz();"#,
r#"let res = $0dbg!(foo().bar()).baz();"#,
r#"let res = foo().bar().baz();"#,
);
check_assist(
remove_dbg,
r#"let res = <|>dbg!(foo.bar()).baz();"#,
r#"let res = $0dbg!(foo.bar()).baz();"#,
r#"let res = foo.bar().baz();"#,
);
}
#[test]
fn test_remove_dbg_field_chaining() {
check_assist(remove_dbg, r#"let res = <|>dbg!(foo.bar).baz;"#, r#"let res = foo.bar.baz;"#);
check_assist(remove_dbg, r#"let res = $0dbg!(foo.bar).baz;"#, r#"let res = foo.bar.baz;"#);
}
#[test]
@ -295,7 +295,7 @@ fn square(x: u32) -> u32 {
}
fn main() {
let x = square(dbg<|>!(5 + 10));
let x = square(dbg$0!(5 + 10));
println!("{}", x);
}"#,
"dbg!(5 + 10)",
@ -309,7 +309,7 @@ fn square(x: u32) -> u32 {
}
fn main() {
let x = square(dbg<|>!(5 + 10));
let x = square(dbg$0!(5 + 10));
println!("{}", x);
}"#,
r#"
@ -328,7 +328,7 @@ fn main() {
fn test_remove_dbg_try_expr() {
check_assist(
remove_dbg,
r#"let res = <|>dbg!(result?).foo();"#,
r#"let res = $0dbg!(result?).foo();"#,
r#"let res = result?.foo();"#,
);
}
@ -337,7 +337,7 @@ fn main() {
fn test_remove_dbg_await_expr() {
check_assist(
remove_dbg,
r#"let res = <|>dbg!(fut.await).foo();"#,
r#"let res = $0dbg!(fut.await).foo();"#,
r#"let res = fut.await.foo();"#,
);
}
@ -346,7 +346,7 @@ fn main() {
fn test_remove_dbg_as_cast() {
check_assist(
remove_dbg,
r#"let res = <|>dbg!(3 as usize).foo();"#,
r#"let res = $0dbg!(3 as usize).foo();"#,
r#"let res = (3 as usize).foo();"#,
);
}
@ -355,12 +355,12 @@ fn main() {
fn test_remove_dbg_index_expr() {
check_assist(
remove_dbg,
r#"let res = <|>dbg!(array[3]).foo();"#,
r#"let res = $0dbg!(array[3]).foo();"#,
r#"let res = array[3].foo();"#,
);
check_assist(
remove_dbg,
r#"let res = <|>dbg!(tuple.3).foo();"#,
r#"let res = $0dbg!(tuple.3).foo();"#,
r#"let res = tuple.3.foo();"#,
);
}
@ -369,12 +369,12 @@ fn main() {
fn test_remove_dbg_range_expr() {
check_assist(
remove_dbg,
r#"let res = <|>dbg!(foo..bar).foo();"#,
r#"let res = $0dbg!(foo..bar).foo();"#,
r#"let res = (foo..bar).foo();"#,
);
check_assist(
remove_dbg,
r#"let res = <|>dbg!(foo..=bar).foo();"#,
r#"let res = $0dbg!(foo..=bar).foo();"#,
r#"let res = (foo..=bar).foo();"#,
);
}
@ -384,7 +384,7 @@ fn main() {
check_assist(
remove_dbg,
r#"fn foo() {
if <|>dbg!(x || y) {}
if $0dbg!(x || y) {}
}"#,
r#"fn foo() {
if x || y {}
@ -393,7 +393,7 @@ fn main() {
check_assist(
remove_dbg,
r#"fn foo() {
while let foo = <|>dbg!(&x) {}
while let foo = $0dbg!(&x) {}
}"#,
r#"fn foo() {
while let foo = &x {}
@ -402,7 +402,7 @@ fn main() {
check_assist(
remove_dbg,
r#"fn foo() {
if let foo = <|>dbg!(&x) {}
if let foo = $0dbg!(&x) {}
}"#,
r#"fn foo() {
if let foo = &x {}
@ -411,7 +411,7 @@ fn main() {
check_assist(
remove_dbg,
r#"fn foo() {
match <|>dbg!(&x) {}
match $0dbg!(&x) {}
}"#,
r#"fn foo() {
match &x {}

View file

@ -8,7 +8,7 @@ use crate::{AssistContext, AssistId, AssistKind, Assists};
//
// ```
// impl Walrus {
// fn feed(&mut<|> self, amount: u32) {}
// fn feed(&mut$0 self, amount: u32) {}
// }
// ```
// ->

View file

@ -16,7 +16,7 @@ use crate::{
// Removes unused function parameter.
//
// ```
// fn frobnicate(x: i32<|>) {}
// fn frobnicate(x: i32$0) {}
//
// fn main() {
// frobnicate(92);
@ -123,7 +123,7 @@ mod tests {
remove_unused_param,
r#"
fn a() { foo(9, 2) }
fn foo(x: i32, <|>y: i32) { x; }
fn foo(x: i32, $0y: i32) { x; }
fn b() { foo(9, 2,) }
"#,
r#"
@ -139,7 +139,7 @@ fn b() { foo(9, ) }
check_assist(
remove_unused_param,
r#"
fn foo(<|>x: i32, y: i32) { y; }
fn foo($0x: i32, y: i32) { y; }
fn a() { foo(1, 2) }
fn b() { foo(1, 2,) }
"#,
@ -156,7 +156,7 @@ fn b() { foo(2,) }
check_assist(
remove_unused_param,
r#"
fn foo(<|>x: i32) { 0; }
fn foo($0x: i32) { 0; }
fn a() { foo(1) }
fn b() { foo(1, ) }
"#,
@ -173,7 +173,7 @@ fn b() { foo( ) }
check_assist(
remove_unused_param,
r#"
fn foo(x: i32, <|>y: i32, z: i32) { x; }
fn foo(x: i32, $0y: i32, z: i32) { x; }
fn a() { foo(1, 2, 3) }
fn b() { foo(1, 2, 3,) }
"#,
@ -190,7 +190,7 @@ fn b() { foo(1, 3,) }
check_assist(
remove_unused_param,
r#"
mod bar { pub fn foo(x: i32, <|>y: i32) { x; } }
mod bar { pub fn foo(x: i32, $0y: i32) { x; } }
fn b() { bar::foo(9, 2) }
"#,
r#"
@ -205,7 +205,7 @@ fn b() { bar::foo(9) }
check_assist(
remove_unused_param,
r#"
pub fn foo<T>(x: T, <|>y: i32) { x; }
pub fn foo<T>(x: T, $0y: i32) { x; }
fn b() { foo::<i32>(9, 2) }
"#,
r#"
@ -220,7 +220,7 @@ fn b() { foo::<i32>(9) }
check_assist(
remove_unused_param,
r#"
pub fn foo<T>(x: i32, <|>y: T) { x; }
pub fn foo<T>(x: i32, $0y: T) { x; }
fn b() { foo::<i32>(9, 2) }
fn b2() { foo(9, 2) }
"#,
@ -238,7 +238,7 @@ fn b2() { foo(9) }
check_assist_not_applicable(
remove_unused_param,
r#"
fn foo(x: i32, <|>y: i32) { y; }
fn foo(x: i32, $0y: i32) { y; }
fn main() { foo(9, 2) }
"#,
);
@ -250,7 +250,7 @@ fn main() { foo(9, 2) }
remove_unused_param,
r#"
//- /main.rs
fn foo(x: i32, <|>y: i32) { x; }
fn foo(x: i32, $0y: i32) { x; }
mod foo;

View file

@ -15,7 +15,7 @@ use crate::{AssistContext, AssistId, AssistKind, Assists};
//
// ```
// struct Foo {foo: i32, bar: i32};
// const test: Foo = <|>Foo {bar: 0, foo: 1}
// const test: Foo = $0Foo {bar: 0, foo: 1}
// ```
// ->
// ```
@ -126,7 +126,7 @@ struct Foo {
bar: i32,
}
const test: Foo = <|>Foo { foo: 0, bar: 0 };
const test: Foo = $0Foo { foo: 0, bar: 0 };
"#,
)
}
@ -137,7 +137,7 @@ const test: Foo = <|>Foo { foo: 0, bar: 0 };
reorder_fields,
r#"
struct Foo {};
const test: Foo = <|>Foo {}
const test: Foo = $0Foo {}
"#,
)
}
@ -148,7 +148,7 @@ const test: Foo = <|>Foo {}
reorder_fields,
r#"
struct Foo {foo: i32, bar: i32};
const test: Foo = <|>Foo {bar: 0, foo: 1}
const test: Foo = $0Foo {bar: 0, foo: 1}
"#,
r#"
struct Foo {foo: i32, bar: i32};
@ -166,7 +166,7 @@ struct Foo { foo: i64, bar: i64, baz: i64 }
fn f(f: Foo) -> {
match f {
<|>Foo { baz: 0, ref mut bar, .. } => (),
$0Foo { baz: 0, ref mut bar, .. } => (),
_ => ()
}
}
@ -197,7 +197,7 @@ struct Foo {
impl Foo {
fn new() -> Foo {
let foo = String::new();
<|>Foo {
$0Foo {
bar: foo.clone(),
extra: "Extra field",
foo,

View file

@ -22,7 +22,7 @@ use crate::{
//
// ```
// # trait Debug { fn fmt(&self, f: &mut Formatter) -> Result<()>; }
// #[derive(Deb<|>ug, Display)]
// #[derive(Deb$0ug, Display)]
// struct S;
// ```
// ->
@ -219,7 +219,7 @@ mod fmt {
}
}
#[derive(Debu<|>g)]
#[derive(Debu$0g)]
struct Foo {
bar: String,
}
@ -261,7 +261,7 @@ mod foo {
}
}
#[derive(<|>Bar)]
#[derive($0Bar)]
struct Foo {
bar: String,
}
@ -300,7 +300,7 @@ impl foo::Bar for Foo {
check_assist(
replace_derive_with_manual_impl,
"
#[derive(Debu<|>g)]
#[derive(Debu$0g)]
struct Foo {
bar: String,
}
@ -322,7 +322,7 @@ impl Debug for Foo {
check_assist(
replace_derive_with_manual_impl,
"
#[derive(Debug<|>)]
#[derive(Debug$0)]
pub struct Foo {
bar: String,
}
@ -344,7 +344,7 @@ impl Debug for Foo {
check_assist(
replace_derive_with_manual_impl,
"
#[derive(Display, Debug<|>, Serialize)]
#[derive(Display, Debug$0, Serialize)]
struct Foo {}
",
"
@ -363,7 +363,7 @@ impl Debug for Foo {
check_assist_not_applicable(
replace_derive_with_manual_impl,
"
#[derive(<|>)]
#[derive($0)]
struct Foo {}
",
)
@ -374,7 +374,7 @@ struct Foo {}
check_assist_not_applicable(
replace_derive_with_manual_impl,
"
#[derive<|>(Debug)]
#[derive$0(Debug)]
struct Foo {}
",
);
@ -382,7 +382,7 @@ struct Foo {}
check_assist_not_applicable(
replace_derive_with_manual_impl,
"
#[derive(Debug)<|>]
#[derive(Debug)$0]
struct Foo {}
",
)
@ -393,7 +393,7 @@ struct Foo {}
check_assist_not_applicable(
replace_derive_with_manual_impl,
"
#[allow(non_camel_<|>case_types)]
#[allow(non_camel_$0case_types)]
struct Foo {}
",
)

View file

@ -20,7 +20,7 @@ use crate::{utils::unwrap_trivial_block, AssistContext, AssistId, AssistKind, As
// enum Action { Move { distance: u32 }, Stop }
//
// fn handle(action: Action) {
// <|>if let Action::Move { distance } = action {
// $0if let Action::Move { distance } = action {
// foo(distance)
// } else {
// bar()
@ -89,7 +89,7 @@ pub(crate) fn replace_if_let_with_match(acc: &mut Assists, ctx: &AssistContext)
// enum Action { Move { distance: u32 }, Stop }
//
// fn handle(action: Action) {
// <|>match action {
// $0match action {
// Action::Move { distance } => foo(distance),
// _ => bar(),
// }
@ -179,7 +179,7 @@ mod tests {
r#"
impl VariantData {
pub fn is_struct(&self) -> bool {
if <|>let VariantData::Struct(..) = *self {
if $0let VariantData::Struct(..) = *self {
true
} else {
false
@ -204,7 +204,7 @@ impl VariantData {
replace_if_let_with_match,
r#"
fn foo() {
if <|>let VariantData::Struct(..) = a {
if $0let VariantData::Struct(..) = a {
bar(
123
)
@ -233,7 +233,7 @@ fn foo() {
r#"
impl VariantData {
pub fn is_struct(&self) -> bool {
if <|>let VariantData::Struct(..) = *self {
if $0let VariantData::Struct(..) = *self {
true
} else {
false
@ -257,7 +257,7 @@ enum Option<T> { Some(T), None }
use Option::*;
fn foo(x: Option<i32>) {
<|>if let Some(x) = x {
$0if let Some(x) = x {
println!("{}", x)
} else {
println!("none")
@ -287,7 +287,7 @@ enum Result<T, E> { Ok(T), Err(E) }
use Result::*;
fn foo(x: Result<i32, ()>) {
<|>if let Ok(x) = x {
$0if let Ok(x) = x {
println!("{}", x)
} else {
println!("none")
@ -315,7 +315,7 @@ fn foo(x: Result<i32, ()>) {
r#"
fn main() {
if true {
<|>if let Ok(rel_path) = path.strip_prefix(root_path) {
$0if let Ok(rel_path) = path.strip_prefix(root_path) {
let rel_path = RelativePathBuf::from_path(rel_path).ok()?;
Some((*id, rel_path))
} else {
@ -347,7 +347,7 @@ fn main() {
r#"
impl VariantData {
pub fn is_struct(&self) -> bool {
<|>match *self {
$0match *self {
VariantData::Struct(..) => true,
_ => false,
}
@ -372,7 +372,7 @@ impl VariantData {
replace_match_with_if_let,
r#"
fn foo() {
<|>match a {
$0match a {
VariantData::Struct(..) => {
bar(
123
@ -401,7 +401,7 @@ fn foo() {
r#"
impl VariantData {
pub fn is_struct(&self) -> bool {
<|>match *self {
$0match *self {
VariantData::Struct(..) => true,
_ => false,
}
@ -423,7 +423,7 @@ enum Option<T> { Some(T), None }
use Option::*;
fn foo(x: Option<i32>) {
<|>match x {
$0match x {
Some(x) => println!("{}", x),
None => println!("none"),
}
@ -453,7 +453,7 @@ enum Result<T, E> { Ok(T), Err(E) }
use Result::*;
fn foo(x: Result<i32, ()>) {
<|>match x {
$0match x {
Ok(x) => println!("{}", x),
Err(_) => println!("none"),
}
@ -481,7 +481,7 @@ fn foo(x: Result<i32, ()>) {
r#"
fn main() {
if true {
<|>match path.strip_prefix(root_path) {
$0match path.strip_prefix(root_path) {
Ok(rel_path) => {
let rel_path = RelativePathBuf::from_path(rel_path).ok()?;
Some((*id, rel_path))
@ -512,7 +512,7 @@ fn main() {
replace_match_with_if_let,
r#"
fn main() {
<|>match path.strip_prefix(root_path) {
$0match path.strip_prefix(root_path) {
Ok(rel_path) => println!("{}", rel_path),
_ => (),
}

View file

@ -7,7 +7,7 @@ use crate::{AssistContext, AssistId, AssistKind, Assists};
// Replaces `impl Trait` function argument with the named generic.
//
// ```
// fn foo(bar: <|>impl Bar) {}
// fn foo(bar: $0impl Bar) {}
// ```
// ->
// ```
@ -56,7 +56,7 @@ mod tests {
check_assist(
replace_impl_trait_with_generic,
r#"
fn foo<G>(bar: <|>impl Bar) {}
fn foo<G>(bar: $0impl Bar) {}
"#,
r#"
fn foo<G, B: Bar>(bar: B) {}
@ -69,7 +69,7 @@ mod tests {
check_assist(
replace_impl_trait_with_generic,
r#"
fn foo(bar: <|>impl Bar) {}
fn foo(bar: $0impl Bar) {}
"#,
r#"
fn foo<B: Bar>(bar: B) {}
@ -82,7 +82,7 @@ mod tests {
check_assist(
replace_impl_trait_with_generic,
r#"
fn foo<G>(foo: impl Foo, bar: <|>impl Bar) {}
fn foo<G>(foo: impl Foo, bar: $0impl Bar) {}
"#,
r#"
fn foo<G, B: Bar>(foo: impl Foo, bar: B) {}
@ -95,7 +95,7 @@ mod tests {
check_assist(
replace_impl_trait_with_generic,
r#"
fn foo<>(bar: <|>impl Bar) {}
fn foo<>(bar: $0impl Bar) {}
"#,
r#"
fn foo<B: Bar>(bar: B) {}
@ -109,7 +109,7 @@ mod tests {
replace_impl_trait_with_generic,
r#"
fn foo<
>(bar: <|>impl Bar) {}
>(bar: $0impl Bar) {}
"#,
r#"
fn foo<B: Bar
@ -124,7 +124,7 @@ mod tests {
check_assist(
replace_impl_trait_with_generic,
r#"
fn foo<B>(bar: <|>impl Bar) {}
fn foo<B>(bar: $0impl Bar) {}
"#,
r#"
fn foo<B, C: Bar>(bar: C) {}
@ -141,7 +141,7 @@ mod tests {
G: Foo,
F,
H,
>(bar: <|>impl Bar) {}
>(bar: $0impl Bar) {}
"#,
r#"
fn foo<
@ -158,7 +158,7 @@ mod tests {
check_assist(
replace_impl_trait_with_generic,
r#"
fn foo(bar: <|>impl Foo + Bar) {}
fn foo(bar: $0impl Foo + Bar) {}
"#,
r#"
fn foo<F: Foo + Bar>(bar: F) {}

View file

@ -20,7 +20,7 @@ use ide_db::ty_filter::TryEnum;
// # enum Option<T> { Some(T), None }
//
// fn main(action: Action) {
// <|>let x = compute();
// $0let x = compute();
// }
//
// fn compute() -> Option<i32> { None }
@ -85,7 +85,7 @@ mod tests {
enum E<T> { X(T), Y(T) }
fn main() {
<|>let x = E::X(92);
$0let x = E::X(92);
}
",
r"

View file

@ -9,7 +9,7 @@ use crate::{AssistContext, AssistId, AssistKind, Assists};
// Adds a use statement for a given fully-qualified name.
//
// ```
// fn process(map: std::collections::<|>HashMap<String, String>) {}
// fn process(map: std::collections::$0HashMap<String, String>) {}
// ```
// ->
// ```
@ -127,7 +127,7 @@ mod tests {
r"use std::fs;
fn main() {
std::f<|>s::Path
std::f$0s::Path
}",
r"use std::fs;
@ -142,7 +142,7 @@ fn main() {
check_assist(
replace_qualified_name_with_use,
r"
std::fmt::Debug<|>
std::fmt::Debug$0
",
r"
use std::fmt::Debug;
@ -156,7 +156,7 @@ Debug
check_assist(
replace_qualified_name_with_use,
r"
std::fmt::Debug<|>
std::fmt::Debug$0
fn main() {
}
@ -180,7 +180,7 @@ fn main() {
fn main() {
}
std::fmt::Debug<|>
std::fmt::Debug$0
",
r"
use std::fmt::Debug;
@ -198,7 +198,7 @@ Debug
check_assist(
replace_qualified_name_with_use,
r"
std::fmt<|>::Debug
std::fmt$0::Debug
",
r"
use std::fmt;
@ -215,7 +215,7 @@ fmt::Debug
r"
use stdx;
impl std::fmt::Debug<|> for Foo {
impl std::fmt::Debug$0 for Foo {
}
",
r"
@ -234,7 +234,7 @@ impl Debug for Foo {
check_assist(
replace_qualified_name_with_use,
r"
impl std::fmt::Debug<|> for Foo {
impl std::fmt::Debug$0 for Foo {
}
",
r"
@ -251,7 +251,7 @@ impl Debug for Foo {
check_assist(
replace_qualified_name_with_use,
r"
impl std::fmt::Debug<|> for Foo {
impl std::fmt::Debug$0 for Foo {
}
",
r"
@ -270,7 +270,7 @@ impl Debug for Foo {
r"
use std::fmt;
impl std::io<|> for Foo {
impl std::io$0 for Foo {
}
",
r"
@ -289,7 +289,7 @@ impl io for Foo {
r"
use std::fmt;
impl std::fmt::Debug<|> for Foo {
impl std::fmt::Debug$0 for Foo {
}
",
r"
@ -308,7 +308,7 @@ impl Debug for Foo {
r"
use std::fmt::Debug;
impl std::fmt<|> for Foo {
impl std::fmt$0 for Foo {
}
",
r"
@ -327,7 +327,7 @@ impl fmt for Foo {
r"
use std::fmt::{Debug, nested::{Display}};
impl std::fmt::nested<|> for Foo {
impl std::fmt::nested$0 for Foo {
}
",
r"
@ -346,7 +346,7 @@ impl nested for Foo {
r"
use std::fmt::{Debug, nested::{self, Display}};
impl std::fmt::nested<|> for Foo {
impl std::fmt::nested$0 for Foo {
}
",
r"
@ -365,7 +365,7 @@ impl nested for Foo {
r"
use std::fmt::{Debug, nested::{Display}};
impl std::fmt::nested::Debug<|> for Foo {
impl std::fmt::nested::Debug$0 for Foo {
}
",
r"
@ -384,7 +384,7 @@ impl Debug for Foo {
r"
use std::fmt::Debug;
impl std::fmt::nested::Display<|> for Foo {
impl std::fmt::nested::Display$0 for Foo {
}
",
r"
@ -403,7 +403,7 @@ impl Display for Foo {
r"
use std::fmt::nested::Debug;
impl std::fmt::Display<|> for Foo {
impl std::fmt::Display$0 for Foo {
}
",
r"
@ -425,7 +425,7 @@ use crate::{
AssocItem,
};
fn foo() { crate::ty::lower<|>::trait_env() }
fn foo() { crate::ty::lower$0::trait_env() }
",
r"
use crate::{AssocItem, ty::{Substs, Ty, lower}};
@ -442,7 +442,7 @@ fn foo() { lower::trait_env() }
r"
use std::fmt as foo;
impl foo::Debug<|> for Foo {
impl foo::Debug$0 for Foo {
}
",
r"
@ -462,7 +462,7 @@ impl Debug for Foo {
check_assist_not_applicable(
replace_qualified_name_with_use,
r"
impl foo<|> for Foo {
impl foo$0 for Foo {
}
",
);
@ -473,7 +473,7 @@ impl foo<|> for Foo {
check_assist_not_applicable(
replace_qualified_name_with_use,
r"
use std::fmt<|>;
use std::fmt$0;
",
);
}
@ -485,7 +485,7 @@ use std::fmt<|>;
r"
mod foo {
mod bar {
std::fmt::Debug<|>
std::fmt::Debug$0
}
}
",
@ -509,7 +509,7 @@ mod foo {
#![allow(dead_code)]
fn main() {
std::fmt::Debug<|>
std::fmt::Debug$0
}
",
r"
@ -530,7 +530,7 @@ fn main() {
replace_qualified_name_with_use,
r"
fn main() {
std::fmt::Debug<|>;
std::fmt::Debug$0;
let x: std::fmt::Debug = std::fmt::Debug;
}
",
@ -552,7 +552,7 @@ fn main() {
r"
mod m {
fn f() {
std::fmt::Debug<|>;
std::fmt::Debug$0;
let x: std::fmt::Debug = std::fmt::Debug;
}
fn g() {
@ -590,7 +590,7 @@ fn f() {
replace_qualified_name_with_use,
r"
fn main() {
std::fmt::Debug<|>;
std::fmt::Debug$0;
}
mod sub {
@ -623,7 +623,7 @@ mod sub {
use std::fmt::Display;
fn main() {
std::fmt<|>;
std::fmt$0;
}
",
r"
@ -643,7 +643,7 @@ fn main() {
r"
pub use std::fmt;
impl std::io<|> for Foo {
impl std::io$0 for Foo {
}
",
r"
@ -663,7 +663,7 @@ impl io for Foo {
r"
pub(crate) use std::fmt;
impl std::io<|> for Foo {
impl std::io$0 for Foo {
}
",
r"

View file

@ -8,7 +8,7 @@ use crate::{AssistContext, AssistId, AssistKind, Assists};
//
// ```
// fn main() {
// find("{<|>");
// find("{$0");
// }
// ```
// ->
@ -48,7 +48,7 @@ mod tests {
replace_string_with_char,
r#"
fn f() {
let s = "<|>c";
let s = "$0c";
}
"#,
r#""c""#,
@ -61,7 +61,7 @@ mod tests {
replace_string_with_char,
r#"
fn f() {
let s = "<|>c";
let s = "$0c";
}
"#,
r##"
@ -78,7 +78,7 @@ mod tests {
replace_string_with_char,
r#"
fn f() {
let s = "<|>😀";
let s = "$0😀";
}
"#,
r##"
@ -95,7 +95,7 @@ mod tests {
replace_string_with_char,
r#"
fn f() {
let s = "<|>test";
let s = "$0test";
}
"#,
)
@ -107,7 +107,7 @@ mod tests {
replace_string_with_char,
r#"
fn f() {
format!(<|>"x", 92)
format!($0"x", 92)
}
"#,
r##"
@ -124,7 +124,7 @@ mod tests {
replace_string_with_char,
r#"
fn f() {
find(<|>"x");
find($0"x");
}
"#,
r##"

View file

@ -23,7 +23,7 @@ use ide_db::ty_filter::TryEnum;
// enum Result<T, E> { Ok(T), Err(E) }
// fn main() {
// let x: Result<i32, i32> = Result::Ok(92);
// let y = x.<|>unwrap();
// let y = x.$0unwrap();
// }
// ```
// ->
@ -101,7 +101,7 @@ enum Result<T, E> { Ok(T), Err(E) }
fn i<T>(a: T) -> T { a }
fn main() {
let x: Result<i32, i32> = Result::Ok(92);
let y = i(x).<|>unwrap();
let y = i(x).$0unwrap();
}
",
r"
@ -127,7 +127,7 @@ enum Option<T> { Some(T), None }
fn i<T>(a: T) -> T { a }
fn main() {
let x = Option::Some(92);
let y = i(x).<|>unwrap();
let y = i(x).$0unwrap();
}
",
r"
@ -153,7 +153,7 @@ enum Result<T, E> { Ok(T), Err(E) }
fn i<T>(a: T) -> T { a }
fn main() {
let x: Result<i32, i32> = Result::Ok(92);
let y = i(x).<|>unwrap().count_zeroes();
let y = i(x).$0unwrap().count_zeroes();
}
",
r"
@ -179,7 +179,7 @@ enum Option<T> { Some(T), None }
fn i<T>(a: T) -> T { a }
fn main() {
let x = Option::Some(92);
let y = i(x).<|>unwrap();
let y = i(x).$0unwrap();
}
",
r"i(x).unwrap()",

View file

@ -9,7 +9,7 @@ use crate::{AssistContext, AssistId, AssistKind, Assists};
// Wraps the tail of import into braces.
//
// ```
// use std::<|>collections::HashMap;
// use std::$0collections::HashMap;
// ```
// ->
// ```
@ -43,7 +43,7 @@ mod tests {
fn test_split_import() {
check_assist(
split_import,
"use crate::<|>db::RootDatabase;",
"use crate::$0db::RootDatabase;",
"use crate::{db::RootDatabase};",
)
}
@ -52,19 +52,19 @@ mod tests {
fn split_import_works_with_trees() {
check_assist(
split_import,
"use crate:<|>:db::{RootDatabase, FileSymbol}",
"use crate:$0:db::{RootDatabase, FileSymbol}",
"use crate::{db::{RootDatabase, FileSymbol}}",
)
}
#[test]
fn split_import_target() {
check_assist_target(split_import, "use crate::<|>db::{RootDatabase, FileSymbol}", "::");
check_assist_target(split_import, "use crate::$0db::{RootDatabase, FileSymbol}", "::");
}
#[test]
fn issue4044() {
check_assist_not_applicable(split_import, "use crate::<|>:::self;")
check_assist_not_applicable(split_import, "use crate::$0:::self;")
}
#[test]
@ -72,7 +72,7 @@ mod tests {
check_assist_not_applicable(
split_import,
r"
use std::<|>
use std::$0
fn main() {}",
);
}

View file

@ -10,7 +10,7 @@ use crate::{utils::test_related_attribute, AssistContext, AssistId, AssistKind,
// Adds `#[ignore]` attribute to the test.
//
// ```
// <|>#[test]
// $0#[test]
// fn arithmetics {
// assert_eq!(2 + 2, 5);
// }
@ -69,7 +69,7 @@ mod tests {
check_assist(
toggle_ignore,
r#"
#[test<|>]
#[test$0]
fn test() {}
"#,
r#"
@ -85,7 +85,7 @@ mod tests {
check_assist(
toggle_ignore,
r#"
#[test<|>]
#[test$0]
#[ignore]
fn test() {}
"#,

View file

@ -14,7 +14,7 @@ use crate::{utils::unwrap_trivial_block, AssistContext, AssistId, AssistKind, As
//
// ```
// fn foo() {
// if true {<|>
// if true {$0
// println!("foo");
// }
// }
@ -124,7 +124,7 @@ mod tests {
unwrap_block,
r#"
fn main() {
<|>{
$0{
92
}
}
@ -143,7 +143,7 @@ fn main() {
unwrap_block,
r#"
fn main() {
<|>{
$0{
92;
}
()
@ -161,7 +161,7 @@ fn main() {
unwrap_block,
r#"
fn main() {
<|>{
$0{
92
}
()
@ -183,7 +183,7 @@ fn main() {
r#"
fn main() {
bar();
if true {<|>
if true {$0
foo();
//comment
@ -217,7 +217,7 @@ fn main() {
//comment
bar();
} else {<|>
} else {$0
println!("bar");
}
}
@ -249,7 +249,7 @@ fn main() {
//comment
//bar();
} else if false {<|>
} else if false {$0
println!("bar");
} else {
println!("foo");
@ -285,7 +285,7 @@ fn main() {
//bar();
} else if false {
println!("bar");
} else if true {<|>
} else if true {$0
println!("foo");
}
}
@ -323,7 +323,7 @@ fn main() {
println!("bar");
} else if true {
println!("foo");
} else {<|>
} else {$0
println!("else");
}
}
@ -361,7 +361,7 @@ fn main() {
//bar();
} else if false {
println!("bar");
} else if true {<|>
} else if true {$0
println!("foo");
} else {
println!("else");
@ -391,7 +391,7 @@ fn main() {
unwrap_block,
r#"
fn main() {
bar();<|>
bar();$0
if true {
foo();
@ -411,7 +411,7 @@ fn main() {
unwrap_block,
r#"
fn main() {
for i in 0..5 {<|>
for i in 0..5 {$0
if true {
foo();
@ -445,7 +445,7 @@ fn main() {
r#"
fn main() {
for i in 0..5 {
if true {<|>
if true {$0
foo();
//comment
@ -475,7 +475,7 @@ fn main() {
unwrap_block,
r#"
fn main() {
loop {<|>
loop {$0
if true {
foo();
@ -508,7 +508,7 @@ fn main() {
unwrap_block,
r#"
fn main() {
while true {<|>
while true {$0
if true {
foo();
@ -542,7 +542,7 @@ fn main() {
r#"
fn main() {
match rel_path {
Ok(rel_path) => {<|>
Ok(rel_path) => {$0
let rel_path = RelativePathBuf::from_path(rel_path).ok()?;
Some((*id, rel_path))
}
@ -567,7 +567,7 @@ fn main() {
fn main() {
while true {
if true {
foo();<|>
foo();$0
//comment
bar();

View file

@ -13,7 +13,7 @@ use crate::{AssistContext, AssistId, AssistKind, Assists};
// Wrap the function's return type into Result.
//
// ```
// fn foo() -> i32<|> { 42i32 }
// fn foo() -> i32$0 { 42i32 }
// ```
// ->
// ```
@ -282,7 +282,7 @@ mod tests {
check_assist(
wrap_return_type_in_result,
r#"
fn foo() -> i3<|>2 {
fn foo() -> i3$02 {
let test = "test";
return 42i32;
}
@ -302,7 +302,7 @@ fn foo() -> Result<i32, ${0:_}> {
wrap_return_type_in_result,
r#"
fn foo() {
|| -> i32<|> {
|| -> i32$0 {
let test = "test";
return 42i32;
};
@ -325,7 +325,7 @@ fn foo() {
wrap_return_type_in_result,
r#"
fn foo() -> i32 {
let test = "test";<|>
let test = "test";$0
return 42i32;
}
"#,
@ -339,7 +339,7 @@ fn foo() -> i32 {
r#"
fn foo() {
|| -> i32 {
let test = "test";<|>
let test = "test";$0
return 42i32;
};
}
@ -349,7 +349,7 @@ fn foo() {
#[test]
fn wrap_return_type_in_result_closure_non_block() {
check_assist_not_applicable(wrap_return_type_in_result, r#"fn foo() { || -> i<|>32 3; }"#);
check_assist_not_applicable(wrap_return_type_in_result, r#"fn foo() { || -> i$032 3; }"#);
}
#[test]
@ -357,7 +357,7 @@ fn foo() {
check_assist_not_applicable(
wrap_return_type_in_result,
r#"
fn foo() -> std::result::Result<i32<|>, String> {
fn foo() -> std::result::Result<i32$0, String> {
let test = "test";
return 42i32;
}
@ -371,7 +371,7 @@ fn foo() -> std::result::Result<i32<|>, String> {
check_assist_not_applicable(
wrap_return_type_in_result,
r#"
fn foo() -> Result<i32<|>, String> {
fn foo() -> Result<i32$0, String> {
let test = "test";
return 42i32;
}
@ -385,7 +385,7 @@ fn foo() -> Result<i32<|>, String> {
wrap_return_type_in_result,
r#"
fn foo() {
|| -> Result<i32<|>, String> {
|| -> Result<i32$0, String> {
let test = "test";
return 42i32;
};
@ -399,7 +399,7 @@ fn foo() {
check_assist(
wrap_return_type_in_result,
r#"
fn foo() -> <|>i32 {
fn foo() -> $0i32 {
let test = "test";
return 42i32;
}
@ -418,7 +418,7 @@ fn foo() -> Result<i32, ${0:_}> {
check_assist(
wrap_return_type_in_result,
r#"
fn foo() -><|> i32 {
fn foo() ->$0 i32 {
let test = "test";
42i32
}
@ -438,7 +438,7 @@ fn foo() -> Result<i32, ${0:_}> {
wrap_return_type_in_result,
r#"
fn foo() {
|| -><|> i32 {
|| ->$0 i32 {
let test = "test";
42i32
};
@ -459,7 +459,7 @@ fn foo() {
fn wrap_return_type_in_result_simple_with_tail_only() {
check_assist(
wrap_return_type_in_result,
r#"fn foo() -> i32<|> { 42i32 }"#,
r#"fn foo() -> i32$0 { 42i32 }"#,
r#"fn foo() -> Result<i32, ${0:_}> { Ok(42i32) }"#,
);
}
@ -469,7 +469,7 @@ fn foo() {
check_assist(
wrap_return_type_in_result,
r#"
fn foo() -> i32<|> {
fn foo() -> i32$0 {
if true {
42i32
} else {
@ -495,7 +495,7 @@ fn foo() -> Result<i32, ${0:_}> {
wrap_return_type_in_result,
r#"
fn foo() {
|| -> i32<|> {
|| -> i32$0 {
if true {
42i32
} else {
@ -523,7 +523,7 @@ fn foo() {
check_assist(
wrap_return_type_in_result,
r#"
fn foo() -> i32<|> {
fn foo() -> i32$0 {
if true {
if false {
1
@ -556,7 +556,7 @@ fn foo() -> Result<i32, ${0:_}> {
check_assist(
wrap_return_type_in_result,
r#"
async fn foo() -> i<|>32 {
async fn foo() -> i$032 {
if true {
if false {
1.await
@ -588,7 +588,7 @@ async fn foo() -> Result<i32, ${0:_}> {
fn wrap_return_type_in_result_simple_with_array() {
check_assist(
wrap_return_type_in_result,
r#"fn foo() -> [i32;<|> 3] { [1, 2, 3] }"#,
r#"fn foo() -> [i32;$0 3] { [1, 2, 3] }"#,
r#"fn foo() -> Result<[i32; 3], ${0:_}> { Ok([1, 2, 3]) }"#,
);
}
@ -598,7 +598,7 @@ async fn foo() -> Result<i32, ${0:_}> {
check_assist(
wrap_return_type_in_result,
r#"
fn foo() -<|>> i32 {
fn foo() -$0> i32 {
if true {
if false {
1 as i32
@ -631,7 +631,7 @@ fn foo() -> Result<i32, ${0:_}> {
check_assist(
wrap_return_type_in_result,
r#"
fn foo() -> i32<|> {
fn foo() -> i32$0 {
let my_var = 5;
match my_var {
5 => 42i32,
@ -656,7 +656,7 @@ fn foo() -> Result<i32, ${0:_}> {
check_assist(
wrap_return_type_in_result,
r#"
fn foo() -> i32<|> {
fn foo() -> i32$0 {
let my_var = 5;
loop {
println!("test");
@ -683,7 +683,7 @@ fn foo() -> Result<i32, ${0:_}> {
check_assist(
wrap_return_type_in_result,
r#"
fn foo() -> i32<|> {
fn foo() -> i32$0 {
let my_var = let x = loop {
break 1;
};
@ -706,7 +706,7 @@ fn foo() -> Result<i32, ${0:_}> {
check_assist(
wrap_return_type_in_result,
r#"
fn foo() -> i32<|> {
fn foo() -> i32$0 {
let my_var = 5;
let res = match my_var {
5 => 42i32,
@ -730,7 +730,7 @@ fn foo() -> Result<i32, ${0:_}> {
check_assist(
wrap_return_type_in_result,
r#"
fn foo() -> i32<|> {
fn foo() -> i32$0 {
let my_var = 5;
let res = if my_var == 5 {
42i32
@ -759,7 +759,7 @@ fn foo() -> Result<i32, ${0:_}> {
check_assist(
wrap_return_type_in_result,
r#"
fn foo() -> i32<|> {
fn foo() -> i32$0 {
let my_var = 5;
match my_var {
5 => {
@ -808,7 +808,7 @@ fn foo() -> Result<i32, ${0:_}> {
check_assist(
wrap_return_type_in_result,
r#"
fn foo() -> i<|>32 {
fn foo() -> i$032 {
let test = "test";
if test == "test" {
return 24i32;
@ -833,7 +833,7 @@ fn foo() -> Result<i32, ${0:_}> {
check_assist(
wrap_return_type_in_result,
r#"
fn foo(the_field: u32) -><|> u32 {
fn foo(the_field: u32) ->$0 u32 {
let true_closure = || { return true; };
if the_field < 5 {
let mut i = 0;
@ -865,7 +865,7 @@ fn foo(the_field: u32) -> Result<u32, ${0:_}> {
check_assist(
wrap_return_type_in_result,
r#"
fn foo(the_field: u32) -> u32<|> {
fn foo(the_field: u32) -> u32$0 {
let true_closure = || {
return true;
};
@ -912,7 +912,7 @@ fn foo(the_field: u32) -> Result<u32, ${0:_}> {
check_assist(
wrap_return_type_in_result,
r#"
fn foo() -> i32<|> {
fn foo() -> i32$0 {
let test = "test";
if test == "test" {
return 24i32;
@ -946,7 +946,7 @@ fn foo() -> Result<i32, ${0:_}> {
check_assist(
wrap_return_type_in_result,
r#"
fn foo() -> i32<|> {
fn foo() -> i32$0 {
let test = "test";
if test == "test" {
return 24i32;
@ -984,7 +984,7 @@ fn foo() -> Result<i32, ${0:_}> {
check_assist(
wrap_return_type_in_result,
r#"
fn foo() -> i3<|>2 {
fn foo() -> i3$02 {
let test = "test";
let other = 5;
if test == "test" {
@ -1030,7 +1030,7 @@ fn foo() -> Result<i32, ${0:_}> {
check_assist(
wrap_return_type_in_result,
r#"
fn foo(the_field: u32) -> u32<|> {
fn foo(the_field: u32) -> u32$0 {
if the_field < 5 {
let mut i = 0;
loop {
@ -1070,7 +1070,7 @@ fn foo(the_field: u32) -> Result<u32, ${0:_}> {
check_assist(
wrap_return_type_in_result,
r#"
fn foo(the_field: u32) -> u3<|>2 {
fn foo(the_field: u32) -> u3$02 {
if the_field < 5 {
let mut i = 0;
match i {
@ -1098,7 +1098,7 @@ fn foo(the_field: u32) -> Result<u32, ${0:_}> {
check_assist(
wrap_return_type_in_result,
r#"
fn foo(the_field: u32) -> u32<|> {
fn foo(the_field: u32) -> u32$0 {
if the_field < 5 {
let mut i = 0;
if i == 5 {
@ -1128,7 +1128,7 @@ fn foo(the_field: u32) -> Result<u32, ${0:_}> {
check_assist(
wrap_return_type_in_result,
r#"
fn foo(the_field: u32) -> <|>u32 {
fn foo(the_field: u32) -> $0u32 {
if the_field < 5 {
let mut i = 0;
if i == 5 {

View file

@ -166,7 +166,7 @@ fn check(handler: Handler, before: &str, expected: ExpectedResult, assist_label:
#[test]
fn assist_order_field_struct() {
let before = "struct Foo { <|>bar: u32 }";
let before = "struct Foo { $0bar: u32 }";
let (before_cursor_pos, before) = extract_offset(before);
let (db, file_id) = with_single_file(&before);
let frange = FileRange { file_id, range: TextRange::empty(before_cursor_pos) };
@ -181,7 +181,7 @@ fn assist_order_field_struct() {
fn assist_order_if_expr() {
let before = "
pub fn test_some_range(a: int) -> bool {
if let 2..6 = <|>5<|> {
if let 2..6 = $05$0 {
true
} else {
false
@ -201,7 +201,7 @@ fn assist_order_if_expr() {
fn assist_filter_works() {
let before = "
pub fn test_some_range(a: int) -> bool {
if let 2..6 = <|>5<|> {
if let 2..6 = $05$0 {
true
} else {
false

View file

@ -8,7 +8,7 @@ fn doctest_add_explicit_type() {
"add_explicit_type",
r#####"
fn main() {
let x<|> = 92;
let x$0 = 92;
}
"#####,
r#####"
@ -25,7 +25,7 @@ fn doctest_add_hash() {
"add_hash",
r#####"
fn main() {
r#"Hello,<|> World!"#;
r#"Hello,$0 World!"#;
}
"#####,
r#####"
@ -49,7 +49,7 @@ trait Trait {
impl Trait for () {
type X = ();
fn foo(&self) {}<|>
fn foo(&self) {}$0
}
"#####,
@ -81,7 +81,7 @@ trait Trait<T> {
fn bar(&self) {}
}
impl Trait<u32> for () {<|>
impl Trait<u32> for () {$0
}
"#####,
@ -110,7 +110,7 @@ fn doctest_add_turbo_fish() {
r#####"
fn make<T>() -> T { todo!() }
fn main() {
let x = make<|>();
let x = make$0();
}
"#####,
r#####"
@ -128,7 +128,7 @@ fn doctest_apply_demorgan() {
"apply_demorgan",
r#####"
fn main() {
if x != 4 ||<|> !y {}
if x != 4 ||$0 !y {}
}
"#####,
r#####"
@ -145,7 +145,7 @@ fn doctest_auto_import() {
"auto_import",
r#####"
fn main() {
let map = HashMap<|>::new();
let map = HashMap$0::new();
}
pub mod std { pub mod collections { pub struct HashMap { } } }
"#####,
@ -165,7 +165,7 @@ fn doctest_change_visibility() {
check_doc_test(
"change_visibility",
r#####"
<|>fn frobnicate() {}
$0fn frobnicate() {}
"#####,
r#####"
pub(crate) fn frobnicate() {}
@ -178,7 +178,7 @@ fn doctest_convert_integer_literal() {
check_doc_test(
"convert_integer_literal",
r#####"
const _: i32 = 10<|>;
const _: i32 = 10$0;
"#####,
r#####"
const _: i32 = 0b1010;
@ -192,7 +192,7 @@ fn doctest_convert_to_guarded_return() {
"convert_to_guarded_return",
r#####"
fn main() {
<|>if cond {
$0if cond {
foo();
bar();
}
@ -220,7 +220,7 @@ mod foo {
pub struct Baz;
}
use foo::*<|>;
use foo::*$0;
fn qux(bar: Bar, baz: Baz) {}
"#####,
@ -242,7 +242,7 @@ fn doctest_extract_struct_from_enum_variant() {
check_doc_test(
"extract_struct_from_enum_variant",
r#####"
enum A { <|>One(u32, u32) }
enum A { $0One(u32, u32) }
"#####,
r#####"
struct One(pub u32, pub u32);
@ -258,7 +258,7 @@ fn doctest_extract_variable() {
"extract_variable",
r#####"
fn main() {
<|>(1 + 2)<|> * 4;
$0(1 + 2)$0 * 4;
}
"#####,
r#####"
@ -279,7 +279,7 @@ enum Action { Move { distance: u32 }, Stop }
fn handle(action: Action) {
match action {
<|>
$0
}
}
"#####,
@ -305,7 +305,7 @@ mod m {
fn frobnicate() {}
}
fn main() {
m::frobnicate<|>() {}
m::frobnicate$0() {}
}
"#####,
r#####"
@ -325,7 +325,7 @@ fn doctest_flip_binexpr() {
"flip_binexpr",
r#####"
fn main() {
let _ = 90 +<|> 2;
let _ = 90 +$0 2;
}
"#####,
r#####"
@ -342,7 +342,7 @@ fn doctest_flip_comma() {
"flip_comma",
r#####"
fn main() {
((1, 2),<|> (3, 4));
((1, 2),$0 (3, 4));
}
"#####,
r#####"
@ -358,7 +358,7 @@ fn doctest_flip_trait_bound() {
check_doc_test(
"flip_trait_bound",
r#####"
fn foo<T: Clone +<|> Copy>() { }
fn foo<T: Clone +$0 Copy>() { }
"#####,
r#####"
fn foo<T: Copy + Clone>() { }
@ -373,7 +373,7 @@ fn doctest_generate_default_from_enum_variant() {
r#####"
enum Version {
Undefined,
Minor<|>,
Minor$0,
Major,
}
"#####,
@ -400,7 +400,7 @@ fn doctest_generate_derive() {
r#####"
struct Point {
x: u32,
y: u32,<|>
y: u32,$0
}
"#####,
r#####"
@ -418,7 +418,7 @@ fn doctest_generate_from_impl_for_enum() {
check_doc_test(
"generate_from_impl_for_enum",
r#####"
enum A { <|>One(u32) }
enum A { $0One(u32) }
"#####,
r#####"
enum A { One(u32) }
@ -440,7 +440,7 @@ fn doctest_generate_function() {
struct Baz;
fn baz() -> Baz { Baz }
fn foo() {
bar<|>("", baz());
bar$0("", baz());
}
"#####,
@ -465,7 +465,7 @@ fn doctest_generate_impl() {
"generate_impl",
r#####"
struct Ctx<T: Clone> {
data: T,<|>
data: T,$0
}
"#####,
r#####"
@ -486,7 +486,7 @@ fn doctest_generate_new() {
"generate_new",
r#####"
struct Ctx<T: Clone> {
data: T,<|>
data: T,$0
}
"#####,
r#####"
@ -507,7 +507,7 @@ fn doctest_infer_function_return_type() {
check_doc_test(
"infer_function_return_type",
r#####"
fn foo() { 4<|>2i32 }
fn foo() { 4$02i32 }
"#####,
r#####"
fn foo() -> i32 { 42i32 }
@ -522,7 +522,7 @@ fn doctest_inline_function() {
r#####"
fn add(a: u32, b: u32) -> u32 { a + b }
fn main() {
let x = add<|>(1, 2);
let x = add$0(1, 2);
}
"#####,
r#####"
@ -544,7 +544,7 @@ fn doctest_inline_local_variable() {
"inline_local_variable",
r#####"
fn main() {
let x<|> = 1 + 2;
let x$0 = 1 + 2;
x * 4;
}
"#####,
@ -561,7 +561,7 @@ fn doctest_introduce_named_lifetime() {
check_doc_test(
"introduce_named_lifetime",
r#####"
impl Cursor<'_<|>> {
impl Cursor<'_$0> {
fn node(self) -> &SyntaxNode {
match self {
Cursor::Replace(node) | Cursor::Before(node) => node,
@ -587,7 +587,7 @@ fn doctest_invert_if() {
"invert_if",
r#####"
fn main() {
if<|> !y { A } else { B }
if$0 !y { A } else { B }
}
"#####,
r#####"
@ -604,7 +604,7 @@ fn doctest_make_raw_string() {
"make_raw_string",
r#####"
fn main() {
"Hello,<|> World!";
"Hello,$0 World!";
}
"#####,
r#####"
@ -621,7 +621,7 @@ fn doctest_make_usual_string() {
"make_usual_string",
r#####"
fn main() {
r#"Hello,<|> "World!""#;
r#"Hello,$0 "World!""#;
}
"#####,
r#####"
@ -637,7 +637,7 @@ fn doctest_merge_imports() {
check_doc_test(
"merge_imports",
r#####"
use std::<|>fmt::Formatter;
use std::$0fmt::Formatter;
use std::io;
"#####,
r#####"
@ -655,7 +655,7 @@ enum Action { Move { distance: u32 }, Stop }
fn handle(action: Action) {
match action {
<|>Action::Move(..) => foo(),
$0Action::Move(..) => foo(),
Action::Stop => foo(),
}
}
@ -681,7 +681,7 @@ enum Action { Move { distance: u32 }, Stop }
fn handle(action: Action) {
match action {
Action::Move { distance } => <|>if distance > 10 { foo() },
Action::Move { distance } => $0if distance > 10 { foo() },
_ => (),
}
}
@ -704,7 +704,7 @@ fn doctest_move_bounds_to_where_clause() {
check_doc_test(
"move_bounds_to_where_clause",
r#####"
fn apply<T, U, <|>F: FnOnce(T) -> U>(f: F, x: T) -> U {
fn apply<T, U, $0F: FnOnce(T) -> U>(f: F, x: T) -> U {
f(x)
}
"#####,
@ -725,7 +725,7 @@ enum Action { Move { distance: u32 }, Stop }
fn handle(action: Action) {
match action {
Action::Move { distance } <|>if distance > 10 => foo(),
Action::Move { distance } $0if distance > 10 => foo(),
_ => (),
}
}
@ -750,7 +750,7 @@ fn doctest_move_module_to_file() {
check_doc_test(
"move_module_to_file",
r#####"
mod <|>foo {
mod $0foo {
fn t() {}
}
"#####,
@ -769,7 +769,7 @@ fn main() {
let mut foo = 6;
if true {
<|>foo = 5;
$0foo = 5;
} else {
foo = 4;
}
@ -795,7 +795,7 @@ fn doctest_qualify_path() {
"qualify_path",
r#####"
fn main() {
let map = HashMap<|>::new();
let map = HashMap$0::new();
}
pub mod std { pub mod collections { pub struct HashMap { } } }
"#####,
@ -814,7 +814,7 @@ fn doctest_remove_dbg() {
"remove_dbg",
r#####"
fn main() {
<|>dbg!(92);
$0dbg!(92);
}
"#####,
r#####"
@ -831,7 +831,7 @@ fn doctest_remove_hash() {
"remove_hash",
r#####"
fn main() {
r#"Hello,<|> World!"#;
r#"Hello,$0 World!"#;
}
"#####,
r#####"
@ -848,7 +848,7 @@ fn doctest_remove_mut() {
"remove_mut",
r#####"
impl Walrus {
fn feed(&mut<|> self, amount: u32) {}
fn feed(&mut$0 self, amount: u32) {}
}
"#####,
r#####"
@ -864,7 +864,7 @@ fn doctest_remove_unused_param() {
check_doc_test(
"remove_unused_param",
r#####"
fn frobnicate(x: i32<|>) {}
fn frobnicate(x: i32$0) {}
fn main() {
frobnicate(92);
@ -886,7 +886,7 @@ fn doctest_reorder_fields() {
"reorder_fields",
r#####"
struct Foo {foo: i32, bar: i32};
const test: Foo = <|>Foo {bar: 0, foo: 1}
const test: Foo = $0Foo {bar: 0, foo: 1}
"#####,
r#####"
struct Foo {foo: i32, bar: i32};
@ -901,7 +901,7 @@ fn doctest_replace_derive_with_manual_impl() {
"replace_derive_with_manual_impl",
r#####"
trait Debug { fn fmt(&self, f: &mut Formatter) -> Result<()>; }
#[derive(Deb<|>ug, Display)]
#[derive(Deb$0ug, Display)]
struct S;
"#####,
r#####"
@ -926,7 +926,7 @@ fn doctest_replace_if_let_with_match() {
enum Action { Move { distance: u32 }, Stop }
fn handle(action: Action) {
<|>if let Action::Move { distance } = action {
$0if let Action::Move { distance } = action {
foo(distance)
} else {
bar()
@ -951,7 +951,7 @@ fn doctest_replace_impl_trait_with_generic() {
check_doc_test(
"replace_impl_trait_with_generic",
r#####"
fn foo(bar: <|>impl Bar) {}
fn foo(bar: $0impl Bar) {}
"#####,
r#####"
fn foo<B: Bar>(bar: B) {}
@ -967,7 +967,7 @@ fn doctest_replace_let_with_if_let() {
enum Option<T> { Some(T), None }
fn main(action: Action) {
<|>let x = compute();
$0let x = compute();
}
fn compute() -> Option<i32> { None }
@ -993,7 +993,7 @@ fn doctest_replace_match_with_if_let() {
enum Action { Move { distance: u32 }, Stop }
fn handle(action: Action) {
<|>match action {
$0match action {
Action::Move { distance } => foo(distance),
_ => bar(),
}
@ -1018,7 +1018,7 @@ fn doctest_replace_qualified_name_with_use() {
check_doc_test(
"replace_qualified_name_with_use",
r#####"
fn process(map: std::collections::<|>HashMap<String, String>) {}
fn process(map: std::collections::$0HashMap<String, String>) {}
"#####,
r#####"
use std::collections::HashMap;
@ -1034,7 +1034,7 @@ fn doctest_replace_string_with_char() {
"replace_string_with_char",
r#####"
fn main() {
find("{<|>");
find("{$0");
}
"#####,
r#####"
@ -1053,7 +1053,7 @@ fn doctest_replace_unwrap_with_match() {
enum Result<T, E> { Ok(T), Err(E) }
fn main() {
let x: Result<i32, i32> = Result::Ok(92);
let y = x.<|>unwrap();
let y = x.$0unwrap();
}
"#####,
r#####"
@ -1074,7 +1074,7 @@ fn doctest_split_import() {
check_doc_test(
"split_import",
r#####"
use std::<|>collections::HashMap;
use std::$0collections::HashMap;
"#####,
r#####"
use std::{collections::HashMap};
@ -1087,7 +1087,7 @@ fn doctest_toggle_ignore() {
check_doc_test(
"toggle_ignore",
r#####"
<|>#[test]
$0#[test]
fn arithmetics {
assert_eq!(2 + 2, 5);
}
@ -1108,7 +1108,7 @@ fn doctest_unwrap_block() {
"unwrap_block",
r#####"
fn foo() {
if true {<|>
if true {$0
println!("foo");
}
}
@ -1126,7 +1126,7 @@ fn doctest_wrap_return_type_in_result() {
check_doc_test(
"wrap_return_type_in_result",
r#####"
fn foo() -> i32<|> { 42i32 }
fn foo() -> i32$0 { 42i32 }
"#####,
r#####"
fn foo() -> Result<i32, ${0:_}> { Ok(42i32) }

View file

@ -413,7 +413,7 @@ mod tests {
fn empty_derive_completion() {
check(
r#"
#[derive(<|>)]
#[derive($0)]
struct Test {}
"#,
expect![[r#"
@ -434,7 +434,7 @@ struct Test {}
fn no_completion_for_incorrect_derive() {
check(
r#"
#[derive{<|>)]
#[derive{$0)]
struct Test {}
"#,
expect![[r#""#]],
@ -445,7 +445,7 @@ struct Test {}
fn derive_with_input_completion() {
check(
r#"
#[derive(serde::Serialize, PartialEq, <|>)]
#[derive(serde::Serialize, PartialEq, $0)]
struct Test {}
"#,
expect![[r#"
@ -464,7 +464,7 @@ struct Test {}
#[test]
fn test_attribute_completion() {
check(
r#"#[<|>]"#,
r#"#[$0]"#,
expect![[r#"
at allow()
at automatically_derived
@ -504,13 +504,13 @@ struct Test {}
#[test]
fn test_attribute_completion_inside_nested_attr() {
check(r#"#[cfg(<|>)]"#, expect![[]])
check(r#"#[cfg($0)]"#, expect![[]])
}
#[test]
fn test_inner_attribute_completion() {
check(
r"#![<|>]",
r"#![$0]",
expect![[r#"
at allow()
at automatically_derived

View file

@ -79,7 +79,7 @@ struct S { foo: u32 }
impl S {
fn bar(&self) {}
}
fn foo(s: S) { s.<|> }
fn foo(s: S) { s.$0 }
"#,
expect![[r#"
fd foo u32
@ -94,7 +94,7 @@ fn foo(s: S) { s.<|> }
r#"
struct S { the_field: (u32,) }
impl S {
fn foo(self) { self.<|> }
fn foo(self) { self.$0 }
}
"#,
expect![[r#"
@ -110,7 +110,7 @@ impl S {
r#"
struct A { the_field: (u32, i32) }
impl A {
fn foo(&self) { self.<|> }
fn foo(&self) { self.$0 }
}
"#,
expect![[r#"
@ -126,7 +126,7 @@ impl A {
check(
r#"
struct A { the_field: u32 }
fn foo(a: A) { a.<|>() }
fn foo(a: A) { a.$0() }
"#,
expect![[""]],
);
@ -144,7 +144,7 @@ mod inner {
pub(crate) super_field: u32,
}
}
fn foo(a: inner::A) { a.<|> }
fn foo(a: inner::A) { a.$0 }
"#,
expect![[r#"
fd pub_field u32
@ -162,7 +162,7 @@ mod m {
pub(crate) fn the_method(&self) {}
}
}
fn foo(a: A) { a.<|> }
fn foo(a: A) { a.$0 }
"#,
expect![[r#"
me the_method() pub(crate) fn the_method(&self)
@ -175,7 +175,7 @@ fn foo(a: A) { a.<|> }
check(
r#"
union U { field: u8, other: u16 }
fn foo(u: U) { u.<|> }
fn foo(u: U) { u.$0 }
"#,
expect![[r#"
fd field u8
@ -195,7 +195,7 @@ impl A<u32> {
impl A<i32> {
fn the_other_method(&self) {}
}
fn foo(a: A<u32>) { a.<|> }
fn foo(a: A<u32>) { a.$0 }
"#,
expect![[r#"
me the_method() fn the_method(&self)
@ -210,7 +210,7 @@ fn foo(a: A<u32>) { a.<|> }
struct A {}
trait Trait { fn the_method(&self); }
impl Trait for A {}
fn foo(a: A) { a.<|> }
fn foo(a: A) { a.$0 }
"#,
expect![[r#"
me the_method() fn the_method(&self)
@ -225,7 +225,7 @@ fn foo(a: A) { a.<|> }
struct A {}
trait Trait { fn the_method(&self); }
impl<T> Trait for T {}
fn foo(a: &A) { a.<|> }
fn foo(a: &A) { a.$0 }
",
expect![[r#"
me the_method() fn the_method(&self)
@ -243,7 +243,7 @@ mod m {
}
use m::Trait;
impl Trait for A {}
fn foo(a: A) { a.<|> }
fn foo(a: A) { a.$0 }
",
expect![[r#"
me the_method() fn the_method(&self)
@ -260,7 +260,7 @@ impl A {
fn the_method() {}
}
fn foo(a: A) {
a.<|>
a.$0
}
"#,
expect![[""]],
@ -273,7 +273,7 @@ fn foo(a: A) {
r#"
fn foo() {
let b = (0, 3.14);
b.<|>
b.$0
}
"#,
expect![[r#"
@ -295,7 +295,7 @@ struct T(S);
impl T {
fn foo(&self) {
// FIXME: This doesn't work without the trailing `a` as `0.` is a float
self.0.a<|>
self.0.a$0
}
}
"#,
@ -311,7 +311,7 @@ impl T {
r#"
struct A { the_field: u32 }
const X: u32 = {
A { the_field: 92 }.<|>
A { the_field: 92 }.$0
};
"#,
expect![[r#"
@ -327,7 +327,7 @@ const X: u32 = {
macro_rules! m { ($e:expr) => { $e } }
struct A { the_field: u32 }
fn foo(a: A) {
m!(a.x<|>)
m!(a.x$0)
}
"#,
expect![[r#"
@ -344,7 +344,7 @@ fn foo(a: A) {
macro_rules! m { ($e:expr) => { $e } }
struct A { the_field: u32 }
fn foo(a: A) {
m!(a.<|>)
m!(a.$0)
}
"#,
expect![[r#"
@ -360,7 +360,7 @@ fn foo(a: A) {
macro_rules! m { ($e:expr) => { $e } }
struct A { the_field: u32 }
fn foo(a: A) {
m!(m!(m!(a.x<|>)))
m!(m!(m!(a.x$0)))
}
"#,
expect![[r#"
@ -386,7 +386,7 @@ macro_rules! dbg {
}
struct A { the_field: u32 }
fn foo(a: A) {
dbg!(a.<|>)
dbg!(a.$0)
}
"#,
expect![[r#"
@ -405,7 +405,7 @@ impl<T> HashSet<T> {
}
fn foo() {
let s: HashSet<_>;
s.<|>
s.$0
}
"#,
expect![[r#"
@ -421,7 +421,7 @@ fn foo() {
struct S;
impl S { fn foo(&self) {} }
macro_rules! make_s { () => { S }; }
fn main() { make_s!().f<|>; }
fn main() { make_s!().f$0; }
"#,
expect![[r#"
me foo() fn foo(&self)

View file

@ -81,7 +81,7 @@ mod tests {
r#"
fn foo(file_id: FileId) {}
fn bar(file_id: FileId) {}
fn baz(file<|>) {}
fn baz(file$0) {}
"#,
expect![[r#"
bn file_id: FileId
@ -94,7 +94,7 @@ fn baz(file<|>) {}
check(
r#"
fn foo(file_id: FileId) {}
fn baz(file<|>, x: i32) {}
fn baz(file$0, x: i32) {}
"#,
expect![[r#"
bn file_id: FileId
@ -110,7 +110,7 @@ pub(crate) trait SourceRoot {
pub fn contains(&self, file_id: FileId) -> bool;
pub fn module_map(&self) -> &ModuleMap;
pub fn lines(&self, file_id: FileId) -> &LineIndex;
pub fn syntax(&self, file<|>)
pub fn syntax(&self, file$0)
}
"#,
expect![[r#"
@ -124,7 +124,7 @@ pub(crate) trait SourceRoot {
check(
r#"
fn outer(text: String) {
fn inner(<|>)
fn inner($0)
}
"#,
expect![[r#"

View file

@ -193,7 +193,7 @@ mod tests {
#[test]
fn test_keywords_in_use_stmt() {
check(
r"use <|>",
r"use $0",
expect![[r#"
kw crate::
kw self
@ -202,7 +202,7 @@ mod tests {
);
check(
r"use a::<|>",
r"use a::$0",
expect![[r#"
kw self
kw super::
@ -210,7 +210,7 @@ mod tests {
);
check(
r"use a::{b, <|>}",
r"use a::{b, $0}",
expect![[r#"
kw self
kw super::
@ -221,7 +221,7 @@ mod tests {
#[test]
fn test_keywords_at_source_file_level() {
check(
r"m<|>",
r"m$0",
expect![[r#"
kw fn
kw use
@ -245,7 +245,7 @@ mod tests {
#[test]
fn test_keywords_in_function() {
check(
r"fn quux() { <|> }",
r"fn quux() { $0 }",
expect![[r#"
kw fn
kw use
@ -271,7 +271,7 @@ mod tests {
#[test]
fn test_keywords_inside_block() {
check(
r"fn quux() { if true { <|> } }",
r"fn quux() { if true { $0 } }",
expect![[r#"
kw fn
kw use
@ -297,7 +297,7 @@ mod tests {
#[test]
fn test_keywords_after_if() {
check(
r#"fn quux() { if true { () } <|> }"#,
r#"fn quux() { if true { () } $0 }"#,
expect![[r#"
kw fn
kw use
@ -322,7 +322,7 @@ mod tests {
);
check_edit(
"else",
r#"fn quux() { if true { () } <|> }"#,
r#"fn quux() { if true { () } $0 }"#,
r#"fn quux() { if true { () } else {$0} }"#,
);
}
@ -332,7 +332,7 @@ mod tests {
check(
r#"
fn quux() -> i32 {
match () { () => <|> }
match () { () => $0 }
}
"#,
expect![[r#"
@ -350,7 +350,7 @@ fn quux() -> i32 {
#[test]
fn test_keywords_in_trait_def() {
check(
r"trait My { <|> }",
r"trait My { $0 }",
expect![[r#"
kw fn
kw const
@ -363,7 +363,7 @@ fn quux() -> i32 {
#[test]
fn test_keywords_in_impl_def() {
check(
r"impl My { <|> }",
r"impl My { $0 }",
expect![[r#"
kw fn
kw const
@ -378,7 +378,7 @@ fn quux() -> i32 {
#[test]
fn test_keywords_in_loop() {
check(
r"fn my() { loop { <|> } }",
r"fn my() { loop { $0 } }",
expect![[r#"
kw fn
kw use
@ -406,7 +406,7 @@ fn quux() -> i32 {
#[test]
fn test_keywords_after_unsafe_in_item_list() {
check(
r"unsafe <|>",
r"unsafe $0",
expect![[r#"
kw fn
kw trait
@ -418,7 +418,7 @@ fn quux() -> i32 {
#[test]
fn test_keywords_after_unsafe_in_block_expr() {
check(
r"fn my_fn() { unsafe <|> }",
r"fn my_fn() { unsafe $0 }",
expect![[r#"
kw fn
kw trait
@ -430,19 +430,19 @@ fn quux() -> i32 {
#[test]
fn test_mut_in_ref_and_in_fn_parameters_list() {
check(
r"fn my_fn(&<|>) {}",
r"fn my_fn(&$0) {}",
expect![[r#"
kw mut
"#]],
);
check(
r"fn my_fn(<|>) {}",
r"fn my_fn($0) {}",
expect![[r#"
kw mut
"#]],
);
check(
r"fn my_fn() { let &<|> }",
r"fn my_fn() { let &$0 }",
expect![[r#"
kw mut
"#]],
@ -452,13 +452,13 @@ fn quux() -> i32 {
#[test]
fn test_where_keyword() {
check(
r"trait A <|>",
r"trait A $0",
expect![[r#"
kw where
"#]],
);
check(
r"impl A <|>",
r"impl A $0",
expect![[r#"
kw where
"#]],
@ -471,7 +471,7 @@ fn quux() -> i32 {
check(
r#"
fn test() {
let x = 2; // A comment<|>
let x = 2; // A comment$0
}
"#,
expect![[""]],
@ -479,7 +479,7 @@ fn test() {
check(
r#"
/*
Some multi-line comment<|>
Some multi-line comment$0
*/
"#,
expect![[""]],
@ -487,7 +487,7 @@ Some multi-line comment<|>
check(
r#"
/// Some doc comment
/// let test<|> = 1
/// let test$0 = 1
"#,
expect![[""]],
);
@ -501,7 +501,7 @@ Some multi-line comment<|>
use std::future::*;
struct A {}
impl Future for A {}
fn foo(a: A) { a.<|> }
fn foo(a: A) { a.$0 }
//- /std/lib.rs crate:std
pub mod future {
@ -520,7 +520,7 @@ pub mod future {
use std::future::*;
fn foo() {
let a = async {};
a.<|>
a.$0
}
//- /std/lib.rs crate:std
@ -540,7 +540,7 @@ pub mod future {
#[test]
fn after_let() {
check(
r#"fn main() { let _ = <|> }"#,
r#"fn main() { let _ = $0 }"#,
expect![[r#"
kw match
kw while
@ -557,7 +557,7 @@ pub mod future {
check(
r#"
struct Foo {
<|>
$0
pub f: i32,
}
"#,
@ -578,7 +578,7 @@ struct Foo {
}
fn foo() {
Foo {
<|>
$0
}
}
"#,
@ -595,7 +595,7 @@ struct Foo {
}
fn foo() {
Foo {
f: <|>
f: $0
}
}
"#,

View file

@ -31,7 +31,7 @@ mod tests {
macro_rules! foo { () => {} }
fn foo() {}
<|>
$0
"#,
expect![[r#"
ma foo!() macro_rules! foo

View file

@ -9,7 +9,7 @@ use crate::{CompletionItem, CompletionItemKind};
use crate::{context::CompletionContext, item::CompletionKind, Completions};
/// Complete mod declaration, i.e. `mod <|> ;`
/// Complete mod declaration, i.e. `mod $0 ;`
pub(crate) fn complete_mod(acc: &mut Completions, ctx: &CompletionContext) -> Option<()> {
let mod_under_caret = match &ctx.mod_declaration_under_caret {
Some(mod_under_caret) if mod_under_caret.item_list().is_some() => return None,
@ -159,7 +159,7 @@ mod tests {
check(
r#"
//- /lib.rs
mod <|>
mod $0
//- /foo.rs
fn foo() {}
//- /foo/ignored_foo.rs
@ -181,7 +181,7 @@ mod tests {
check(
r#"
//- /lib.rs
mod <|> {
mod $0 {
}
//- /foo.rs
@ -196,7 +196,7 @@ mod tests {
check(
r#"
//- /main.rs
mod <|>
mod $0
//- /foo.rs
fn foo() {}
//- /foo/ignored_foo.rs
@ -219,7 +219,7 @@ mod tests {
r#"
//- /main.rs
mod tests {
mod <|>;
mod $0;
}
//- /tests/foo.rs
fn foo() {}
@ -237,7 +237,7 @@ mod tests {
//- /lib.rs
mod foo;
//- /foo.rs
mod <|>;
mod $0;
//- /foo/bar.rs
fn bar() {}
//- /foo/bar/ignored_bar.rs
@ -262,7 +262,7 @@ mod tests {
mod foo;
//- /foo.rs
mod bar {
mod <|>
mod $0
}
//- /foo/bar/baz.rs
fn baz() {}
@ -288,7 +288,7 @@ mod tests {
// //- /src/bin.rs
// fn main() {}
// //- /src/bin/foo.rs
// mod <|>
// mod $0
// //- /src/bin/bar.rs
// fn bar() {}
// //- /src/bin/bar/bar_ignored.rs
@ -307,7 +307,7 @@ mod tests {
//- /src/bin.rs crate:main
fn main() {}
//- /src/bin/foo.rs
mod <|>
mod $0
//- /src/bin/bar.rs
mod foo;
fn bar() {}

View file

@ -71,7 +71,7 @@ static FOO: E = E::X;
struct Bar { f: u32 }
fn foo() {
match E::X { <|> }
match E::X { $0 }
}
"#,
expect![[r#"
@ -92,7 +92,7 @@ macro_rules! m { ($e:expr) => { $e } }
enum E { X }
fn foo() {
m!(match E::X { <|> })
m!(match E::X { $0 })
}
"#,
expect![[r#"
@ -115,7 +115,7 @@ static FOO: E = E::X;
struct Bar { f: u32 }
fn foo() {
let <|>
let $0
}
"#,
expect![[r#"
@ -133,7 +133,7 @@ enum E { X }
static FOO: E = E::X;
struct Bar { f: u32 }
fn foo(<|>) {
fn foo($0) {
}
"#,
expect![[r#"
@ -149,7 +149,7 @@ fn foo(<|>) {
struct Bar { f: u32 }
fn foo() {
let <|>
let $0
}
"#,
expect![[r#"
@ -165,7 +165,7 @@ fn foo() {
struct Foo { bar: String, baz: String }
struct Bar(String, String);
struct Baz;
fn outer(<|>) {}
fn outer($0) {}
"#,
expect![[r#"
bn Foo Foo { bar$1, baz$2 }: Foo$0
@ -182,7 +182,7 @@ struct Foo { bar: String, baz: String }
struct Bar(String, String);
struct Baz;
fn outer() {
let <|>
let $0
}
"#,
expect![[r#"
@ -201,7 +201,7 @@ struct Bar(String, String);
struct Baz;
fn outer() {
match () {
<|>
$0
}
}
"#,
@ -225,7 +225,7 @@ use foo::*;
fn outer() {
match () {
<|>
$0
}
}
"#,
@ -244,7 +244,7 @@ fn outer() {
struct Foo(i32);
fn main() {
match Foo(92) {
<|>(92) => (),
$0(92) => (),
}
}
"#,

View file

@ -1,4 +1,4 @@
//! Postfix completions, like `Ok(10).ifl<|>` => `if let Ok() = Ok(10) { <|> }`.
//! Postfix completions, like `Ok(10).ifl$0` => `if let Ok() = Ok(10) { $0 }`.
mod format_like;
@ -310,7 +310,7 @@ mod tests {
r#"
fn main() {
let bar = true;
bar.<|>
bar.$0
}
"#,
expect![[r#"
@ -342,7 +342,7 @@ fn foo(elt: bool) -> bool {
fn main() {
let bar = true;
foo(bar.<|>)
foo(bar.$0)
}
"#,
expect![[r#"
@ -368,7 +368,7 @@ fn main() {
r#"
fn main() {
let bar: u8 = 12;
bar.<|>
bar.$0
}
"#,
expect![[r#"
@ -392,7 +392,7 @@ fn main() {
check(
r#"
fn main() {
baz.l<|>
baz.l$0
res
}
"#,
@ -424,7 +424,7 @@ enum Option<T> { Some(T), None }
fn main() {
let bar = Option::Some(true);
bar.<|>
bar.$0
}
"#,
r#"
@ -449,7 +449,7 @@ enum Result<T, E> { Ok(T), Err(E) }
fn main() {
let bar = Result::Ok(true);
bar.<|>
bar.$0
}
"#,
r#"
@ -468,7 +468,7 @@ fn main() {
#[test]
fn postfix_completion_works_for_ambiguous_float_literal() {
check_edit("refm", r#"fn main() { 42.<|> }"#, r#"fn main() { &mut 42 }"#)
check_edit("refm", r#"fn main() { 42.$0 }"#, r#"fn main() { &mut 42 }"#)
}
#[test]
@ -479,7 +479,7 @@ fn main() {
macro_rules! m { ($e:expr) => { $e } }
fn main() {
let bar: u8 = 12;
m!(bar.d<|>)
m!(bar.d$0)
}
"#,
r#"
@ -494,55 +494,47 @@ fn main() {
#[test]
fn postfix_completion_for_references() {
check_edit("dbg", r#"fn main() { &&42.<|> }"#, r#"fn main() { dbg!(&&42) }"#);
check_edit("refm", r#"fn main() { &&42.<|> }"#, r#"fn main() { &&&mut 42 }"#);
check_edit("dbg", r#"fn main() { &&42.$0 }"#, r#"fn main() { dbg!(&&42) }"#);
check_edit("refm", r#"fn main() { &&42.$0 }"#, r#"fn main() { &&&mut 42 }"#);
}
#[test]
fn postfix_completion_for_format_like_strings() {
check_edit(
"format",
r#"fn main() { "{some_var:?}".<|> }"#,
r#"fn main() { "{some_var:?}".$0 }"#,
r#"fn main() { format!("{:?}", some_var) }"#,
);
check_edit(
"panic",
r#"fn main() { "Panic with {a}".<|> }"#,
r#"fn main() { "Panic with {a}".$0 }"#,
r#"fn main() { panic!("Panic with {}", a) }"#,
);
check_edit(
"println",
r#"fn main() { "{ 2+2 } { SomeStruct { val: 1, other: 32 } :?}".<|> }"#,
r#"fn main() { "{ 2+2 } { SomeStruct { val: 1, other: 32 } :?}".$0 }"#,
r#"fn main() { println!("{} {:?}", 2+2, SomeStruct { val: 1, other: 32 }) }"#,
);
check_edit(
"loge",
r#"fn main() { "{2+2}".<|> }"#,
r#"fn main() { "{2+2}".$0 }"#,
r#"fn main() { log::error!("{}", 2+2) }"#,
);
check_edit(
"logt",
r#"fn main() { "{2+2}".<|> }"#,
r#"fn main() { "{2+2}".$0 }"#,
r#"fn main() { log::trace!("{}", 2+2) }"#,
);
check_edit(
"logd",
r#"fn main() { "{2+2}".<|> }"#,
r#"fn main() { "{2+2}".$0 }"#,
r#"fn main() { log::debug!("{}", 2+2) }"#,
);
check_edit(
"logi",
r#"fn main() { "{2+2}".<|> }"#,
r#"fn main() { log::info!("{}", 2+2) }"#,
);
check_edit(
"logw",
r#"fn main() { "{2+2}".<|> }"#,
r#"fn main() { log::warn!("{}", 2+2) }"#,
);
check_edit("logi", r#"fn main() { "{2+2}".$0 }"#, r#"fn main() { log::info!("{}", 2+2) }"#);
check_edit("logw", r#"fn main() { "{2+2}".$0 }"#, r#"fn main() { log::warn!("{}", 2+2) }"#);
check_edit(
"loge",
r#"fn main() { "{2+2}".<|> }"#,
r#"fn main() { "{2+2}".$0 }"#,
r#"fn main() { log::error!("{}", 2+2) }"#,
);
}

View file

@ -1,4 +1,4 @@
//! Completion of paths, i.e. `some::prefix::<|>`.
//! Completion of paths, i.e. `some::prefix::$0`.
use hir::{Adt, HasVisibility, PathResolution, ScopeDef};
use rustc_hash::FxHashSet;
@ -38,7 +38,7 @@ pub(crate) fn complete_qualified_path(acc: &mut Completions, ctx: &CompletionCon
if let ScopeDef::Unknown = def {
if let Some(name_ref) = ctx.name_ref_syntax.as_ref() {
if name_ref.syntax().text() == name.to_string().as_str() {
// for `use self::foo<|>`, don't suggest `foo` as a completion
// for `use self::foo$0`, don't suggest `foo` as a completion
mark::hit!(dont_complete_current_use);
continue;
}
@ -173,7 +173,7 @@ mod tests {
#[test]
fn dont_complete_current_use() {
mark::check!(dont_complete_current_use);
check(r#"use self::foo<|>;"#, expect![[""]]);
check(r#"use self::foo$0;"#, expect![[""]]);
}
#[test]
@ -181,7 +181,7 @@ mod tests {
check(
r#"
mod foo { pub struct S; }
use self::{foo::*, bar<|>};
use self::{foo::*, bar$0};
"#,
expect![[r#"
st S
@ -192,18 +192,18 @@ use self::{foo::*, bar<|>};
#[test]
fn dont_complete_primitive_in_use() {
check_builtin(r#"use self::<|>;"#, expect![[""]]);
check_builtin(r#"use self::$0;"#, expect![[""]]);
}
#[test]
fn dont_complete_primitive_in_module_scope() {
check_builtin(r#"fn foo() { self::<|> }"#, expect![[""]]);
check_builtin(r#"fn foo() { self::$0 }"#, expect![[""]]);
}
#[test]
fn completes_primitives() {
check_builtin(
r#"fn main() { let _: <|> = 92; }"#,
r#"fn main() { let _: $0 = 92; }"#,
expect![[r#"
bt u32
bt bool
@ -230,7 +230,7 @@ use self::{foo::*, bar<|>};
fn completes_mod_with_same_name_as_function() {
check(
r#"
use self::my::<|>;
use self::my::$0;
mod my { pub struct Bar; }
fn my() {}
@ -245,7 +245,7 @@ fn my() {}
fn filters_visibility() {
check(
r#"
use self::my::<|>;
use self::my::$0;
mod my {
struct Bar;
@ -264,7 +264,7 @@ mod my {
fn completes_use_item_starting_with_self() {
check(
r#"
use self::m::<|>;
use self::m::$0;
mod m { pub struct Bar; }
"#,
@ -282,7 +282,7 @@ mod m { pub struct Bar; }
mod foo;
struct Spam;
//- /foo.rs
use crate::Sp<|>
use crate::Sp$0
"#,
expect![[r#"
md foo
@ -299,7 +299,7 @@ use crate::Sp<|>
mod foo;
struct Spam;
//- /foo.rs
use crate::{Sp<|>};
use crate::{Sp$0};
"#,
expect![[r#"
md foo
@ -320,7 +320,7 @@ pub mod bar {
}
}
//- /foo.rs
use crate::{bar::{baz::Sp<|>}};
use crate::{bar::{baz::Sp$0}};
"#,
expect![[r#"
st Spam
@ -333,7 +333,7 @@ use crate::{bar::{baz::Sp<|>}};
check(
r#"
enum E { Foo, Bar(i32) }
fn foo() { let _ = E::<|> }
fn foo() { let _ = E::$0 }
"#,
expect![[r#"
ev Foo ()
@ -356,7 +356,7 @@ impl S {
type T = i32;
}
fn foo() { let _ = S::<|> }
fn foo() { let _ = S::$0 }
"#,
expect![[r#"
fn a() fn a()
@ -384,7 +384,7 @@ mod m {
}
}
fn foo() { let _ = S::<|> }
fn foo() { let _ = S::$0 }
"#,
expect![[r#"
fn public_method() pub(crate) fn public_method()
@ -401,7 +401,7 @@ fn foo() { let _ = S::<|> }
enum E {};
impl E { fn m() { } }
fn foo() { let _ = E::<|> }
fn foo() { let _ = E::$0 }
"#,
expect![[r#"
fn m() fn m()
@ -416,7 +416,7 @@ fn foo() { let _ = E::<|> }
union U {};
impl U { fn m() { } }
fn foo() { let _ = U::<|> }
fn foo() { let _ = U::$0 }
"#,
expect![[r#"
fn m() fn m()
@ -429,7 +429,7 @@ fn foo() { let _ = U::<|> }
check(
r#"
//- /main.rs crate:main deps:foo
use foo::<|>;
use foo::$0;
//- /foo/lib.rs crate:foo
pub mod bar { pub struct S; }
@ -446,7 +446,7 @@ pub mod bar { pub struct S; }
r#"
trait Trait { fn m(); }
fn foo() { let _ = Trait::<|> }
fn foo() { let _ = Trait::$0 }
"#,
expect![[r#"
fn m() fn m()
@ -463,7 +463,7 @@ trait Trait { fn m(); }
struct S;
impl Trait for S {}
fn foo() { let _ = S::<|> }
fn foo() { let _ = S::$0 }
"#,
expect![[r#"
fn m() fn m()
@ -480,7 +480,7 @@ trait Trait { fn m(); }
struct S;
impl Trait for S {}
fn foo() { let _ = <S as Trait>::<|> }
fn foo() { let _ = <S as Trait>::$0 }
"#,
expect![[r#"
fn m() fn m()
@ -506,7 +506,7 @@ trait Sub: Super {
fn submethod(&self) {}
}
fn foo<T: Sub>() { T::<|> }
fn foo<T: Sub>() { T::$0 }
"#,
expect![[r#"
ta SubTy type SubTy;
@ -544,7 +544,7 @@ impl<T> Super for Wrap<T> {}
impl<T> Sub for Wrap<T> {
fn subfunc() {
// Should be able to assume `Self: Sub + Super`
Self::<|>
Self::$0
}
}
"#,
@ -570,7 +570,7 @@ impl S { fn foo() {} }
type T = S;
impl T { fn bar() {} }
fn main() { T::<|>; }
fn main() { T::$0; }
"#,
expect![[r#"
fn foo() fn foo()
@ -586,7 +586,7 @@ fn main() { T::<|>; }
#[macro_export]
macro_rules! foo { () => {} }
fn main() { let _ = crate::<|> }
fn main() { let _ = crate::$0 }
"#,
expect![[r##"
fn main() fn main()
@ -604,7 +604,7 @@ mod a {
const A: usize = 0;
mod b {
const B: usize = 0;
mod c { use super::super::<|> }
mod c { use super::super::$0 }
}
}
"#,
@ -619,7 +619,7 @@ mod a {
fn completes_reexported_items_under_correct_name() {
check(
r#"
fn foo() { self::m::<|> }
fn foo() { self::m::$0 }
mod m {
pub use super::p::wrong_fn as right_fn;
@ -642,7 +642,7 @@ mod p {
check_edit(
"RightType",
r#"
fn foo() { self::m::<|> }
fn foo() { self::m::$0 }
mod m {
pub use super::p::wrong_fn as right_fn;
@ -677,7 +677,7 @@ mod p {
check(
r#"
macro_rules! m { ($e:expr) => { $e } }
fn main() { m!(self::f<|>); }
fn main() { m!(self::f$0); }
fn foo() {}
"#,
expect![[r#"
@ -691,7 +691,7 @@ fn foo() {}
fn function_mod_share_name() {
check(
r#"
fn foo() { self::m::<|> }
fn foo() { self::m::$0 }
mod m {
pub mod z {}
@ -716,7 +716,7 @@ impl<K, V> HashMap<K, V, RandomState> {
pub fn new() -> HashMap<K, V, RandomState> { }
}
fn foo() {
HashMap::<|>
HashMap::$0
}
"#,
expect![[r#"
@ -730,7 +730,7 @@ fn foo() {
check(
r#"
mod foo { pub struct Foo; }
#[foo::<|>]
#[foo::$0]
fn f() {}
"#,
expect![[""]],
@ -749,7 +749,7 @@ fn foo(
}
fn main() {
fo<|>
fo$0
}
"#,
expect![[r#"
@ -770,7 +770,7 @@ enum Foo {
impl Foo {
fn foo(self) {
Self::<|>
Self::$0
}
}
"#,

View file

@ -99,7 +99,7 @@ impl core::default::Default for S {
fn process(f: S) {
let other = S {
foo: 5,
.<|>
.$0
};
}
"#;
@ -139,7 +139,7 @@ impl core::default::Default for S {
fn process(f: S) {
let other = S {
foo: 5,
.<|>
.$0
};
}
"#,
@ -173,7 +173,7 @@ struct S { foo: u32, bar: usize }
fn process(f: S) {
let other = S {
foo: 5,
.<|>
.$0
};
}
"#;
@ -201,7 +201,7 @@ struct S { foo: u32 }
fn process(f: S) {
match f {
S { f<|>: 92 } => (),
S { f$0: 92 } => (),
}
}
"#,
@ -219,7 +219,7 @@ enum E { S { foo: u32, bar: () } }
fn process(e: E) {
match e {
E::S { <|> } => (),
E::S { $0 } => (),
}
}
"#,
@ -239,7 +239,7 @@ struct S { foo: u32 }
fn process(f: S) {
m!(match f {
S { f<|>: 92 } => (),
S { f$0: 92 } => (),
})
}
",
@ -263,7 +263,7 @@ fn main() {
foo1: 1, foo2: 2,
bar: 3, baz: 4,
};
if let S { foo1, foo2: a, <|> } = s {}
if let S { foo1, foo2: a, $0 } = s {}
}
"#,
expect![[r#"
@ -279,7 +279,7 @@ fn main() {
r#"
struct A { the_field: u32 }
fn foo() {
A { the<|> }
A { the$0 }
}
"#,
expect![[r#"
@ -294,7 +294,7 @@ fn foo() {
r#"
enum E { A { a: u32 } }
fn foo() {
let _ = E::A { <|> }
let _ = E::A { $0 }
}
"#,
expect![[r#"
@ -311,7 +311,7 @@ struct A { a: u32 }
struct B { b: u32 }
fn foo() {
let _: A = B { <|> }
let _: A = B { $0 }
}
"#,
expect![[r#"
@ -327,7 +327,7 @@ fn foo() {
struct A<T> { a: T }
fn foo() {
let _: A<u32> = A { <|> }
let _: A<u32> = A { $0 }
}
"#,
expect![[r#"
@ -343,7 +343,7 @@ fn foo() {
macro_rules! m { ($e:expr) => { $e } }
struct A { the_field: u32 }
fn foo() {
m!(A { the<|> })
m!(A { the$0 })
}
"#,
expect![[r#"
@ -363,7 +363,7 @@ struct S {
fn main() {
let foo1 = 1;
let s = S { foo1, foo2: 5, <|> }
let s = S { foo1, foo2: 5, $0 }
}
"#,
expect![[r#"
@ -381,7 +381,7 @@ struct S { foo1: u32, foo2: u32 }
fn main() {
let foo1 = 1;
let s = S { foo1, <|> .. loop {} }
let s = S { foo1, $0 .. loop {} }
}
"#,
expect![[r#"

View file

@ -83,7 +83,7 @@ mod tests {
#[test]
fn completes_snippets_in_expressions() {
check(
r#"fn foo(x: i32) { <|> }"#,
r#"fn foo(x: i32) { $0 }"#,
expect![[r#"
sn pd
sn ppd
@ -93,8 +93,8 @@ mod tests {
#[test]
fn should_not_complete_snippets_in_path() {
check(r#"fn foo(x: i32) { ::foo<|> }"#, expect![[""]]);
check(r#"fn foo(x: i32) { ::<|> }"#, expect![[""]]);
check(r#"fn foo(x: i32) { ::foo$0 }"#, expect![[""]]);
check(r#"fn foo(x: i32) { ::$0 }"#, expect![[""]]);
}
#[test]
@ -103,7 +103,7 @@ mod tests {
r#"
#[cfg(test)]
mod tests {
<|>
$0
}
"#,
expect![[r#"

View file

@ -15,7 +15,7 @@
//! }
//!
//! impl SomeTrait for () {
//! fn f<|>
//! fn f$0
//! }
//! ```
//!
@ -27,7 +27,7 @@
//! # }
//!
//! impl SomeTrait for () {
//! fn foo() {}<|>
//! fn foo() {}$0
//! }
//! ```
@ -82,7 +82,7 @@ pub(crate) fn complete_trait_impl(acc: &mut Completions, ctx: &CompletionContext
fn completion_match(ctx: &CompletionContext) -> Option<(ImplCompletionKind, SyntaxNode, Impl)> {
let mut token = ctx.token.clone();
// For keywork without name like `impl .. { fn <|> }`, the current position is inside
// For keywork without name like `impl .. { fn $0 }`, the current position is inside
// the whitespace token, which is outside `FN` syntax node.
// We need to follow the previous token in this case.
if token.kind() == SyntaxKind::WHITESPACE {
@ -90,20 +90,20 @@ fn completion_match(ctx: &CompletionContext) -> Option<(ImplCompletionKind, Synt
}
let impl_item_offset = match token.kind() {
// `impl .. { const <|> }`
// `impl .. { const $0 }`
// ERROR 0
// CONST_KW <- *
SyntaxKind::CONST_KW => 0,
// `impl .. { fn/type <|> }`
// `impl .. { fn/type $0 }`
// FN/TYPE_ALIAS 0
// FN_KW <- *
SyntaxKind::FN_KW | SyntaxKind::TYPE_KW => 0,
// `impl .. { fn/type/const foo<|> }`
// `impl .. { fn/type/const foo$0 }`
// FN/TYPE_ALIAS/CONST 1
// NAME 0
// IDENT <- *
SyntaxKind::IDENT if token.parent().kind() == SyntaxKind::NAME => 1,
// `impl .. { foo<|> }`
// `impl .. { foo$0 }`
// MACRO_CALL 3
// PATH 2
// PATH_SEGMENT 1
@ -120,7 +120,7 @@ fn completion_match(ctx: &CompletionContext) -> Option<(ImplCompletionKind, Synt
// <item>
let impl_def = ast::Impl::cast(impl_item.parent()?.parent()?)?;
let kind = match impl_item.kind() {
// `impl ... { const <|> fn/type/const }`
// `impl ... { const $0 fn/type/const }`
_ if token.kind() == SyntaxKind::CONST_KW => ImplCompletionKind::Const,
SyntaxKind::CONST | SyntaxKind::ERROR => ImplCompletionKind::Const,
SyntaxKind::TYPE_ALIAS => ImplCompletionKind::TypeAlias,
@ -267,7 +267,7 @@ trait Test {
struct T;
impl Test for T {
t<|>
t$0
}
"#,
expect![["
@ -287,7 +287,7 @@ struct T;
impl Test for T {
fn test() {
t<|>
t$0
}
}
",
@ -301,7 +301,7 @@ struct T;
impl Test for T {
fn test() {
fn t<|>
fn t$0
}
}
",
@ -315,7 +315,7 @@ struct T;
impl Test for T {
fn test() {
fn <|>
fn $0
}
}
",
@ -330,7 +330,7 @@ struct T;
impl Test for T {
fn test() {
foo.<|>
foo.$0
}
}
",
@ -343,7 +343,7 @@ trait Test { fn test(_: i32); fn test2(); }
struct T;
impl Test for T {
fn test(t<|>)
fn test(t$0)
}
",
expect![[""]],
@ -355,7 +355,7 @@ trait Test { fn test(_: fn()); fn test2(); }
struct T;
impl Test for T {
fn test(f: fn <|>)
fn test(f: fn $0)
}
",
expect![[""]],
@ -370,7 +370,7 @@ trait Test { const TEST: fn(); const TEST2: u32; type Test; fn test(); }
struct T;
impl Test for T {
const TEST: fn <|>
const TEST: fn $0
}
",
expect![[""]],
@ -382,7 +382,7 @@ trait Test { const TEST: u32; const TEST2: u32; type Test; fn test(); }
struct T;
impl Test for T {
const TEST: T<|>
const TEST: T$0
}
",
expect![[""]],
@ -394,7 +394,7 @@ trait Test { const TEST: u32; const TEST2: u32; type Test; fn test(); }
struct T;
impl Test for T {
const TEST: u32 = f<|>
const TEST: u32 = f$0
}
",
expect![[""]],
@ -407,7 +407,7 @@ struct T;
impl Test for T {
const TEST: u32 = {
t<|>
t$0
};
}
",
@ -421,7 +421,7 @@ struct T;
impl Test for T {
const TEST: u32 = {
fn <|>
fn $0
};
}
",
@ -435,7 +435,7 @@ struct T;
impl Test for T {
const TEST: u32 = {
fn t<|>
fn t$0
};
}
",
@ -451,7 +451,7 @@ trait Test { type Test; type Test2; fn test(); }
struct T;
impl Test for T {
type Test = T<|>;
type Test = T$0;
}
",
expect![[""]],
@ -463,7 +463,7 @@ trait Test { type Test; type Test2; fn test(); }
struct T;
impl Test for T {
type Test = fn <|>;
type Test = fn $0;
}
",
expect![[""]],
@ -481,7 +481,7 @@ trait Test {
struct T;
impl Test for T {
t<|>
t$0
}
"#,
r#"
@ -510,7 +510,7 @@ trait Test {
struct T;
impl Test for T {
fn t<|>
fn t$0
}
"#,
r#"
@ -540,7 +540,7 @@ struct T;
impl Test for T {
fn foo() {}
fn f<|>
fn f$0
}
"#,
expect![[r#"
@ -560,7 +560,7 @@ trait Test {
struct T;
impl Test for T {
fn f<|>
fn f$0
}
"#,
r#"
@ -585,7 +585,7 @@ trait Test {
struct T;
impl Test for T {
fn f<|>
fn f$0
}
"#,
r#"
@ -614,7 +614,7 @@ trait Test {
}
impl Test for () {
type S<|>
type S$0
}
"#,
"
@ -639,7 +639,7 @@ trait Test {
}
impl Test for () {
const S<|>
const S$0
}
"#,
"
@ -661,7 +661,7 @@ trait Test {
}
impl Test for () {
const S<|>
const S$0
}
"#,
"
@ -724,7 +724,7 @@ impl Test for T {{
// Enumerate some possible next siblings.
for next_sibling in &[
"",
"fn other_fn() {}", // `const <|> fn` -> `const fn`
"fn other_fn() {}", // `const $0 fn` -> `const fn`
"type OtherType = i32;",
"const OTHER_CONST: i32 = 0;",
"async fn other_fn() {}",
@ -733,9 +733,9 @@ impl Test for T {{
"default type OtherType = i32;",
"default const OTHER_CONST: i32 = 0;",
] {
test("bar", "fn <|>", "fn bar() {\n $0\n}", next_sibling);
test("Foo", "type <|>", "type Foo = ", next_sibling);
test("CONST", "const <|>", "const CONST: u16 = ", next_sibling);
test("bar", "fn $0", "fn bar() {\n $0\n}", next_sibling);
test("Foo", "type $0", "type Foo = ", next_sibling);
test("CONST", "const $0", "const CONST: u16 = ", next_sibling);
}
}
}

View file

@ -85,7 +85,7 @@ fn complete_enum_variants(acc: &mut Completions, ctx: &CompletionContext, ty: &T
//
// ```
// fn main() {
// pda<|>
// pda$0
// }
// # pub mod std { pub mod marker { pub struct PhantomData { } } }
// ```
@ -212,7 +212,7 @@ mod tests {
mark::check!(self_fulfilling_completion);
check(
r#"
use foo<|>
use foo$0
use std::collections;
"#,
expect![[r#"
@ -229,7 +229,7 @@ enum Enum { A, B }
fn quux(x: Option<Enum>) {
match x {
None => (),
Some(en<|> @ Enum::A) => (),
Some(en$0 @ Enum::A) => (),
}
}
"#,
@ -245,7 +245,7 @@ enum Enum { A, B }
fn quux(x: Option<Enum>) {
match x {
None => (),
Some(ref en<|>) => (),
Some(ref en$0) => (),
}
}
"#,
@ -261,7 +261,7 @@ enum Enum { A, B }
fn quux(x: Option<Enum>) {
match x {
None => (),
Some(En<|>) => (),
Some(En$0) => (),
}
}
"#,
@ -277,7 +277,7 @@ fn quux(x: Option<Enum>) {
r#"
fn quux(x: i32) {
let y = 92;
1 + <|>;
1 + $0;
let z = ();
}
"#,
@ -299,7 +299,7 @@ fn quux() {
};
if let Some(a) = bar() {
let b = 62;
1 + <|>
1 + $0
}
}
"#,
@ -316,7 +316,7 @@ fn quux() {
check(
r#"
fn quux() {
for x in &[1, 2, 3] { <|> }
for x in &[1, 2, 3] { $0 }
}
"#,
expect![[r#"
@ -334,7 +334,7 @@ fn quux() {
r#"
fn main() {
let wherewolf = 92;
drop(where<|>)
drop(where$0)
}
"#,
r#"
@ -349,7 +349,7 @@ fn main() {
#[test]
fn completes_generic_params() {
check(
r#"fn quux<T>() { <|> }"#,
r#"fn quux<T>() { $0 }"#,
expect![[r#"
tp T
fn quux() fn quux<T>()
@ -360,7 +360,7 @@ fn main() {
#[test]
fn completes_generic_params_in_struct() {
check(
r#"struct S<T> { x: <|>}"#,
r#"struct S<T> { x: $0}"#,
expect![[r#"
tp Self
tp T
@ -372,7 +372,7 @@ fn main() {
#[test]
fn completes_self_in_enum() {
check(
r#"enum X { Y(<|>) }"#,
r#"enum X { Y($0) }"#,
expect![[r#"
tp Self
en X
@ -386,7 +386,7 @@ fn main() {
r#"
struct S;
enum E {}
fn quux() { <|> }
fn quux() { $0 }
"#,
expect![[r#"
st S
@ -403,7 +403,7 @@ fn quux() { <|> }
"_alpha",
r#"
fn main() {
_<|>
_$0
}
fn _alpha() {}
"#,
@ -421,7 +421,7 @@ fn _alpha() {}
check(
r#"
//- /lib.rs crate:main deps:other_crate
use <|>;
use $0;
//- /other_crate/lib.rs crate:other_crate
// nothing here
@ -439,7 +439,7 @@ use <|>;
struct Foo;
mod m {
struct Bar;
fn quux() { <|> }
fn quux() { $0 }
}
"#,
expect![[r#"
@ -454,7 +454,7 @@ mod m {
check(
r#"
struct Foo;
fn x() -> <|>
fn x() -> $0
"#,
expect![[r#"
st Foo
@ -471,7 +471,7 @@ fn foo() {
let bar = 92;
{
let bar = 62;
drop(<|>)
drop($0)
}
}
"#,
@ -487,7 +487,7 @@ fn foo() {
#[test]
fn completes_self_in_methods() {
check(
r#"impl S { fn foo(&self) { <|> } }"#,
r#"impl S { fn foo(&self) { $0 } }"#,
expect![[r#"
bn self &{unknown}
tp Self
@ -500,7 +500,7 @@ fn foo() {
check(
r#"
//- /main.rs crate:main deps:std
fn foo() { let x: <|> }
fn foo() { let x: $0 }
//- /std/lib.rs crate:std
#[prelude_import]
@ -521,7 +521,7 @@ mod prelude { struct Option; }
check(
r#"
//- /main.rs crate:main deps:core,std
fn foo() { let x: <|> }
fn foo() { let x: $0 }
//- /core/lib.rs crate:core
#[prelude_import]
@ -562,7 +562,7 @@ mod m2 {
macro_rules! baz { () => {} }
}
fn main() { let v = <|> }
fn main() { let v = $0 }
"#,
expect![[r##"
md m1
@ -581,7 +581,7 @@ fn main() { let v = <|> }
check(
r#"
macro_rules! foo { () => {} }
fn foo() { <|> }
fn foo() { $0 }
"#,
expect![[r#"
fn foo() fn foo()
@ -595,7 +595,7 @@ fn foo() { <|> }
check(
r#"
macro_rules! foo { () => {} }
fn main() { let x: <|> }
fn main() { let x: $0 }
"#,
expect![[r#"
fn main() fn main()
@ -609,7 +609,7 @@ fn main() { let x: <|> }
check(
r#"
macro_rules! foo { () => {} }
fn main() { <|> }
fn main() { $0 }
"#,
expect![[r#"
fn main() fn main()
@ -623,7 +623,7 @@ fn main() { <|> }
check(
r#"
fn main() {
return f<|>;
return f$0;
fn frobnicate() {}
}
"#,
@ -641,7 +641,7 @@ fn main() {
macro_rules! m { ($e:expr) => { $e } }
fn quux(x: i32) {
let y = 92;
m!(<|>);
m!($0);
}
"#,
expect![[r#"
@ -660,7 +660,7 @@ fn quux(x: i32) {
macro_rules! m { ($e:expr) => { $e } }
fn quux(x: i32) {
let y = 92;
m!(x<|>);
m!(x$0);
}
",
expect![[r#"
@ -679,7 +679,7 @@ fn quux(x: i32) {
macro_rules! m { ($e:expr) => { $e } }
fn quux(x: i32) {
let y = 92;
m!(x<|>
m!(x$0
}
"#,
expect![[r#"
@ -697,7 +697,7 @@ fn quux(x: i32) {
r#"
use spam::Quux;
fn main() { <|> }
fn main() { $0 }
"#,
expect![[r#"
fn main() fn main()
@ -714,7 +714,7 @@ enum Foo { Bar, Baz, Quux }
fn main() {
let foo = Foo::Quux;
match foo { Qu<|> }
match foo { Qu$0 }
}
"#,
expect![[r#"
@ -734,7 +734,7 @@ enum Foo { Bar, Baz, Quux }
fn main() {
let foo = Foo::Quux;
match &foo { Qu<|> }
match &foo { Qu$0 }
}
"#,
expect![[r#"
@ -754,7 +754,7 @@ enum Foo { Bar, Baz, Quux }
fn main() {
let foo = Foo::Quux;
if let Qu<|> = foo { }
if let Qu$0 = foo { }
}
"#,
expect![[r#"
@ -771,7 +771,7 @@ fn main() {
check(
r#"
enum Foo { Bar, Baz, Quux }
fn main() { let foo: Foo = Q<|> }
fn main() { let foo: Foo = Q$0 }
"#,
expect![[r#"
ev Foo::Bar ()
@ -788,7 +788,7 @@ fn main() { let foo: Foo = Q<|> }
check(
r#"
mod m { pub enum E { V } }
fn f() -> m::E { V<|> }
fn f() -> m::E { V$0 }
"#,
expect![[r#"
ev m::E::V ()
@ -803,7 +803,7 @@ fn f() -> m::E { V<|> }
check(
r#"
struct Foo;
#[<|>]
#[$0]
fn f() {}
"#,
expect![[""]],
@ -817,7 +817,7 @@ fn f() {}
trait MyTrait {}
struct MyStruct {}
impl My<|>
impl My$0
"#,
expect![[r#"
tp Self
@ -840,7 +840,7 @@ pub mod io {
//- /main.rs crate:main deps:dep
fn main() {
stdi<|>
stdi$0
}
"#,
r#"
@ -868,7 +868,7 @@ macro_rules! macro_with_curlies {
//- /main.rs crate:main deps:dep
fn main() {
curli<|>
curli$0
}
"#,
r#"
@ -898,7 +898,7 @@ pub mod some_module {
use dep::{FirstStruct, some_module::SecondStruct};
fn main() {
this<|>
this$0
}
"#,
r#"
@ -936,7 +936,7 @@ pub mod some_module {
use dep::{FirstStruct, some_module::SecondStruct};
fn main() {
hir<|>
hir$0
}
"#,
expect![[r#"

View file

@ -63,7 +63,7 @@ pub(crate) struct CompletionContext<'a> {
pub(super) is_expr: bool,
/// Something is typed at the "top" level, in module or impl/trait.
pub(super) is_new_item: bool,
/// The receiver if this is a field or method access, i.e. writing something.<|>
/// The receiver if this is a field or method access, i.e. writing something.$0
pub(super) dot_receiver: Option<ast::Expr>,
pub(super) dot_receiver_is_ambiguous_float_literal: bool,
/// If this is a call (method or function) in particular, i.e. the () are already there.
@ -228,9 +228,9 @@ impl<'a> CompletionContext<'a> {
/// Checks whether completions in that particular case don't make much sense.
/// Examples:
/// - `fn <|>` -- we expect function name, it's unlikely that "hint" will be helpful.
/// - `fn $0` -- we expect function name, it's unlikely that "hint" will be helpful.
/// Exception for this case is `impl Trait for Foo`, where we would like to hint trait method names.
/// - `for _ i<|>` -- obviously, it'll be "in" keyword.
/// - `for _ i$0` -- obviously, it'll be "in" keyword.
pub(crate) fn no_completion_required(&self) -> bool {
(self.fn_is_prev && !self.inside_impl_trait_block) || self.for_is_prev2
}
@ -279,7 +279,7 @@ impl<'a> CompletionContext<'a> {
offset: TextSize,
) {
// FIXME: this is wrong in at least two cases:
// * when there's no token `foo(<|>)`
// * when there's no token `foo($0)`
// * when there is a token, but it happens to have type of it's own
self.expected_type = self
.token

View file

@ -43,7 +43,7 @@ pub struct CompletionItem {
/// Lookup is used to check if completion item indeed can complete current
/// ident.
///
/// That is, in `foo.bar<|>` lookup of `abracadabra` will be accepted (it
/// That is, in `foo.bar$0` lookup of `abracadabra` will be accepted (it
/// contains `bar` sub sequence), and `quux` will rejected.
lookup: Option<String>,

View file

@ -47,8 +47,8 @@ pub use crate::{
// - `expr.while` -> `while expr {}` or `while let ... {}` for `Option` or `Result`
// - `expr.ref` -> `&expr`
// - `expr.refm` -> `&mut expr`
// - `expr.let` -> `let <|> = expr;`
// - `expr.letm` -> `let mut <|> = expr;`
// - `expr.let` -> `let $0 = expr;`
// - `expr.letm` -> `let mut $0 = expr;`
// - `expr.not` -> `!expr`
// - `expr.dbg` -> `dbg!(expr)`
// - `expr.dbgr` -> `dbg!(&expr)`
@ -92,7 +92,7 @@ pub use crate::{
/// ```no_run
/// fn f() {
/// let foo = 92;
/// let _ = bar<|>
/// let _ = bar$0
/// }
/// ```
///
@ -220,7 +220,7 @@ mod tests {
fn foo() {
let bar = Bar;
bar.fo<|>;
bar.fo$0;
}
"#,
DetailAndDocumentation { detail: "fn foo(&self)", documentation: "Do the foo" },
@ -246,7 +246,7 @@ mod tests {
fn foo() {
let bar = Bar;
bar.fo<|>;
bar.fo$0;
}
"#,
DetailAndDocumentation { detail: "fn foo(&self)", documentation: " Do the foo" },
@ -259,7 +259,7 @@ mod tests {
check_no_completion(
r#"
fn foo() {
for i i<|>
for i i$0
}
"#,
);
@ -270,7 +270,7 @@ mod tests {
fn foo() -> &'static str { "foo" }
fn bar() {
for c in fo<|>
for c in fo$0
}
"#,
DetailAndDocumentation {

View file

@ -20,7 +20,7 @@ pub(crate) fn has_trait_parent(element: SyntaxElement) -> bool {
}
#[test]
fn test_has_trait_parent() {
check_pattern_is_applicable(r"trait A { f<|> }", has_trait_parent);
check_pattern_is_applicable(r"trait A { f$0 }", has_trait_parent);
}
pub(crate) fn has_impl_parent(element: SyntaxElement) -> bool {
@ -32,7 +32,7 @@ pub(crate) fn has_impl_parent(element: SyntaxElement) -> bool {
}
#[test]
fn test_has_impl_parent() {
check_pattern_is_applicable(r"impl A { f<|> }", has_impl_parent);
check_pattern_is_applicable(r"impl A { f$0 }", has_impl_parent);
}
pub(crate) fn inside_impl_trait_block(element: SyntaxElement) -> bool {
@ -47,10 +47,10 @@ pub(crate) fn inside_impl_trait_block(element: SyntaxElement) -> bool {
}
#[test]
fn test_inside_impl_trait_block() {
check_pattern_is_applicable(r"impl Foo for Bar { f<|> }", inside_impl_trait_block);
check_pattern_is_applicable(r"impl Foo for Bar { fn f<|> }", inside_impl_trait_block);
check_pattern_is_not_applicable(r"impl A { f<|> }", inside_impl_trait_block);
check_pattern_is_not_applicable(r"impl A { fn f<|> }", inside_impl_trait_block);
check_pattern_is_applicable(r"impl Foo for Bar { f$0 }", inside_impl_trait_block);
check_pattern_is_applicable(r"impl Foo for Bar { fn f$0 }", inside_impl_trait_block);
check_pattern_is_not_applicable(r"impl A { f$0 }", inside_impl_trait_block);
check_pattern_is_not_applicable(r"impl A { fn f$0 }", inside_impl_trait_block);
}
pub(crate) fn has_field_list_parent(element: SyntaxElement) -> bool {
@ -58,8 +58,8 @@ pub(crate) fn has_field_list_parent(element: SyntaxElement) -> bool {
}
#[test]
fn test_has_field_list_parent() {
check_pattern_is_applicable(r"struct Foo { f<|> }", has_field_list_parent);
check_pattern_is_applicable(r"struct Foo { f<|> pub f: i32}", has_field_list_parent);
check_pattern_is_applicable(r"struct Foo { f$0 }", has_field_list_parent);
check_pattern_is_applicable(r"struct Foo { f$0 pub f: i32}", has_field_list_parent);
}
pub(crate) fn has_block_expr_parent(element: SyntaxElement) -> bool {
@ -67,7 +67,7 @@ pub(crate) fn has_block_expr_parent(element: SyntaxElement) -> bool {
}
#[test]
fn test_has_block_expr_parent() {
check_pattern_is_applicable(r"fn my_fn() { let a = 2; f<|> }", has_block_expr_parent);
check_pattern_is_applicable(r"fn my_fn() { let a = 2; f$0 }", has_block_expr_parent);
}
pub(crate) fn has_bind_pat_parent(element: SyntaxElement) -> bool {
@ -75,8 +75,8 @@ pub(crate) fn has_bind_pat_parent(element: SyntaxElement) -> bool {
}
#[test]
fn test_has_bind_pat_parent() {
check_pattern_is_applicable(r"fn my_fn(m<|>) {}", has_bind_pat_parent);
check_pattern_is_applicable(r"fn my_fn() { let m<|> }", has_bind_pat_parent);
check_pattern_is_applicable(r"fn my_fn(m$0) {}", has_bind_pat_parent);
check_pattern_is_applicable(r"fn my_fn() { let m$0 }", has_bind_pat_parent);
}
pub(crate) fn has_ref_parent(element: SyntaxElement) -> bool {
@ -86,8 +86,8 @@ pub(crate) fn has_ref_parent(element: SyntaxElement) -> bool {
}
#[test]
fn test_has_ref_parent() {
check_pattern_is_applicable(r"fn my_fn(&m<|>) {}", has_ref_parent);
check_pattern_is_applicable(r"fn my() { let &m<|> }", has_ref_parent);
check_pattern_is_applicable(r"fn my_fn(&m$0) {}", has_ref_parent);
check_pattern_is_applicable(r"fn my() { let &m$0 }", has_ref_parent);
}
pub(crate) fn has_item_list_or_source_file_parent(element: SyntaxElement) -> bool {
@ -99,8 +99,8 @@ pub(crate) fn has_item_list_or_source_file_parent(element: SyntaxElement) -> boo
}
#[test]
fn test_has_item_list_or_source_file_parent() {
check_pattern_is_applicable(r"i<|>", has_item_list_or_source_file_parent);
check_pattern_is_applicable(r"mod foo { f<|> }", has_item_list_or_source_file_parent);
check_pattern_is_applicable(r"i$0", has_item_list_or_source_file_parent);
check_pattern_is_applicable(r"mod foo { f$0 }", has_item_list_or_source_file_parent);
}
pub(crate) fn is_match_arm(element: SyntaxElement) -> bool {
@ -112,7 +112,7 @@ pub(crate) fn is_match_arm(element: SyntaxElement) -> bool {
}
#[test]
fn test_is_match_arm() {
check_pattern_is_applicable(r"fn my_fn() { match () { () => m<|> } }", is_match_arm);
check_pattern_is_applicable(r"fn my_fn() { match () { () => m$0 } }", is_match_arm);
}
pub(crate) fn unsafe_is_prev(element: SyntaxElement) -> bool {
@ -124,7 +124,7 @@ pub(crate) fn unsafe_is_prev(element: SyntaxElement) -> bool {
}
#[test]
fn test_unsafe_is_prev() {
check_pattern_is_applicable(r"unsafe i<|>", unsafe_is_prev);
check_pattern_is_applicable(r"unsafe i$0", unsafe_is_prev);
}
pub(crate) fn if_is_prev(element: SyntaxElement) -> bool {
@ -144,11 +144,11 @@ pub(crate) fn fn_is_prev(element: SyntaxElement) -> bool {
}
#[test]
fn test_fn_is_prev() {
check_pattern_is_applicable(r"fn l<|>", fn_is_prev);
check_pattern_is_applicable(r"fn l$0", fn_is_prev);
}
/// Check if the token previous to the previous one is `for`.
/// For example, `for _ i<|>` => true.
/// For example, `for _ i$0` => true.
pub(crate) fn for_is_prev2(element: SyntaxElement) -> bool {
element
.into_token()
@ -159,12 +159,12 @@ pub(crate) fn for_is_prev2(element: SyntaxElement) -> bool {
}
#[test]
fn test_for_is_prev2() {
check_pattern_is_applicable(r"for i i<|>", for_is_prev2);
check_pattern_is_applicable(r"for i i$0", for_is_prev2);
}
#[test]
fn test_if_is_prev() {
check_pattern_is_applicable(r"if l<|>", if_is_prev);
check_pattern_is_applicable(r"if l$0", if_is_prev);
}
pub(crate) fn has_trait_as_prev_sibling(element: SyntaxElement) -> bool {
@ -172,7 +172,7 @@ pub(crate) fn has_trait_as_prev_sibling(element: SyntaxElement) -> bool {
}
#[test]
fn test_has_trait_as_prev_sibling() {
check_pattern_is_applicable(r"trait A w<|> {}", has_trait_as_prev_sibling);
check_pattern_is_applicable(r"trait A w$0 {}", has_trait_as_prev_sibling);
}
pub(crate) fn has_impl_as_prev_sibling(element: SyntaxElement) -> bool {
@ -180,7 +180,7 @@ pub(crate) fn has_impl_as_prev_sibling(element: SyntaxElement) -> bool {
}
#[test]
fn test_has_impl_as_prev_sibling() {
check_pattern_is_applicable(r"impl A w<|> {}", has_impl_as_prev_sibling);
check_pattern_is_applicable(r"impl A w$0 {}", has_impl_as_prev_sibling);
}
pub(crate) fn is_in_loop_body(element: SyntaxElement) -> bool {

View file

@ -358,7 +358,7 @@ mod tests {
r#"
enum Foo { Foo { x: i32, y: i32 } }
fn main() { Foo::Fo<|> }
fn main() { Foo::Fo$0 }
"#,
expect![[r#"
[
@ -381,7 +381,7 @@ fn main() { Foo::Fo<|> }
r#"
enum Foo { Foo (i32, i32) }
fn main() { Foo::Fo<|> }
fn main() { Foo::Fo$0 }
"#,
expect![[r#"
[
@ -406,7 +406,7 @@ fn main() { Foo::Fo<|> }
r#"
enum Foo { Foo }
fn main() { Foo::Fo<|> }
fn main() { Foo::Fo$0 }
"#,
expect![[r#"
[
@ -430,7 +430,7 @@ fn main() { Foo::Fo<|> }
mod m {
pub enum Spam { Foo, Bar(i32) }
}
fn main() { let _: m::Spam = S<|> }
fn main() { let _: m::Spam = S$0 }
"#,
expect![[r#"
[
@ -483,7 +483,7 @@ fn something_deprecated() {}
#[deprecated(since = "1.0.0")]
fn something_else_deprecated() {}
fn main() { som<|> }
fn main() { som$0 }
"#,
expect![[r#"
[
@ -523,7 +523,7 @@ fn main() { som<|> }
check(
r#"
struct A { #[deprecated] the_field: u32 }
fn foo() { A { the<|> } }
fn foo() { A { the$0 } }
"#,
expect![[r#"
[
@ -551,7 +551,7 @@ struct S {
}
impl S {
/// Method docs
fn bar(self) { self.<|> }
fn bar(self) { self.$0 }
}"#,
expect![[r#"
[
@ -584,7 +584,7 @@ impl S {
check(
r#"
use self::my<|>;
use self::my$0;
/// mod docs
mod my { }
@ -643,7 +643,7 @@ impl S {
#[inline]
fn the_method(&self) { }
}
fn foo(s: S) { s.<|> }
fn foo(s: S) { s.$0 }
"#,
expect![[r#"
[
@ -671,7 +671,7 @@ fn foo(foo: u8, bar: u8) {}
struct ManualVtable { f: fn(u8, u8) }
fn main() -> ManualVtable {
ManualVtable { f: f<|> }
ManualVtable { f: f$0 }
}
"#,
r#"
@ -692,7 +692,7 @@ fn main() -> ManualVtable {
"foo",
r#"
mod m { pub fn foo() {} }
use crate::m::f<|>;
use crate::m::f$0;
"#,
r#"
mod m { pub fn foo() {} }
@ -707,7 +707,7 @@ use crate::m::foo;
"foo",
r#"
fn foo(x: i32) {}
fn main() { f<|>(); }
fn main() { f$0(); }
"#,
r#"
fn foo(x: i32) {}
@ -719,7 +719,7 @@ fn main() { foo(); }
r#"
struct Foo;
impl Foo { fn foo(&self){} }
fn f(foo: &Foo) { foo.f<|>(); }
fn f(foo: &Foo) { foo.f$0(); }
"#,
r#"
struct Foo;
@ -736,7 +736,7 @@ fn f(foo: &Foo) { foo.foo(); }
"Vec",
r#"
struct Vec<T> {}
fn foo(xs: Ve<|>)
fn foo(xs: Ve$0)
"#,
r#"
struct Vec<T> {}
@ -747,7 +747,7 @@ fn foo(xs: Vec<$0>)
"Vec",
r#"
type Vec<T> = (T,);
fn foo(xs: Ve<|>)
fn foo(xs: Ve$0)
"#,
r#"
type Vec<T> = (T,);
@ -758,7 +758,7 @@ fn foo(xs: Vec<$0>)
"Vec",
r#"
struct Vec<T = i128> {}
fn foo(xs: Ve<|>)
fn foo(xs: Ve$0)
"#,
r#"
struct Vec<T = i128> {}
@ -769,7 +769,7 @@ fn foo(xs: Vec)
"Vec",
r#"
struct Vec<T> {}
fn foo(xs: Ve<|><i128>)
fn foo(xs: Ve$0<i128>)
"#,
r#"
struct Vec<T> {}
@ -785,7 +785,7 @@ fn foo(xs: Vec<i128>)
r#"
struct S { foo: i64, bar: u32, baz: u32 }
fn test(bar: u32) { }
fn foo(s: S) { test(s.<|>) }
fn foo(s: S) { test(s.$0) }
"#,
expect![[r#"
fd bar [type+name]
@ -802,7 +802,7 @@ fn foo(s: S) { test(s.<|>) }
r#"
struct A { foo: i64, bar: u32, baz: u32 }
struct B { x: (), y: f32, bar: u32 }
fn foo(a: A) { B { bar: a.<|> }; }
fn foo(a: A) { B { bar: a.$0 }; }
"#,
expect![[r#"
fd bar [type+name]
@ -819,7 +819,7 @@ fn foo(a: A) { B { bar: a.<|> }; }
struct A { foo: i64, bar: u32, baz: u32 }
struct B { x: (), y: f32, bar: u32 }
fn f(foo: i64) { }
fn foo(a: A) { B { bar: f(a.<|>) }; }
fn foo(a: A) { B { bar: f(a.$0) }; }
"#,
expect![[r#"
fd foo [type+name]
@ -832,7 +832,7 @@ fn foo(a: A) { B { bar: f(a.<|>) }; }
struct A { foo: i64, bar: u32, baz: u32 }
struct B { x: (), y: f32, bar: u32 }
fn f(foo: i64) { }
fn foo(a: A) { f(B { bar: a.<|> }); }
fn foo(a: A) { f(B { bar: a.$0 }); }
"#,
expect![[r#"
fd bar [type+name]
@ -847,7 +847,7 @@ fn foo(a: A) { f(B { bar: a.<|> }); }
check_scores(
r#"
struct WorldSnapshot { _f: () };
fn go(world: &WorldSnapshot) { go(w<|>) }
fn go(world: &WorldSnapshot) { go(w$0) }
"#,
expect![[r#"
bn world [type+name]
@ -862,7 +862,7 @@ fn go(world: &WorldSnapshot) { go(w<|>) }
check_scores(
r#"
struct Foo;
fn f(foo: &Foo) { f(foo, w<|>) }
fn f(foo: &Foo) { f(foo, w$0) }
"#,
expect![[r#"
st Foo []

View file

@ -115,7 +115,7 @@ mod tests {
enum Option<T> { Some(T), None }
use Option::*;
fn main() -> Option<i32> {
Som<|>
Som$0
}
"#,
r#"

View file

@ -124,7 +124,7 @@ mod tests {
"no_args",
r#"
fn no_args() {}
fn main() { no_<|> }
fn main() { no_$0 }
"#,
r#"
fn no_args() {}
@ -136,7 +136,7 @@ fn main() { no_args()$0 }
"with_args",
r#"
fn with_args(x: i32, y: String) {}
fn main() { with_<|> }
fn main() { with_$0 }
"#,
r#"
fn with_args(x: i32, y: String) {}
@ -151,7 +151,7 @@ struct S;
impl S {
fn foo(&self) {}
}
fn bar(s: &S) { s.f<|> }
fn bar(s: &S) { s.f$0 }
"#,
r#"
struct S;
@ -170,7 +170,7 @@ impl S {
fn foo(&self, x: i32) {}
}
fn bar(s: &S) {
s.f<|>
s.f$0
}
"#,
r#"
@ -195,7 +195,7 @@ struct S;
impl S {
fn foo(&self) {}
}
fn main() { S::f<|> }
fn main() { S::f$0 }
"#,
r#"
struct S;
@ -215,7 +215,7 @@ fn main() { S::foo(${1:&self})$0 }
"with_args",
r#"
fn with_args(x: i32, y: String) {}
fn main() { with_<|> }
fn main() { with_$0 }
"#,
r#"
fn with_args(x: i32, y: String) {}
@ -230,7 +230,7 @@ fn main() { with_args($0) }
"foo",
r#"
fn foo(_foo: i32, ___bar: bool, ho_ge_: String) {}
fn main() { f<|> }
fn main() { f$0 }
"#,
r#"
fn foo(_foo: i32, ___bar: bool, ho_ge_: String) {}
@ -248,7 +248,7 @@ struct Foo {}
fn ref_arg(x: &Foo) {}
fn main() {
let x = Foo {};
ref_ar<|>
ref_ar$0
}
"#,
r#"
@ -271,7 +271,7 @@ struct Foo {}
fn ref_arg(x: &mut Foo) {}
fn main() {
let x = Foo {};
ref_ar<|>
ref_ar$0
}
"#,
r#"
@ -299,7 +299,7 @@ impl Bar {
fn main() {
let x = Foo {};
let y = Bar {};
y.<|>
y.$0
}
"#,
r#"
@ -326,7 +326,7 @@ fn main() {
fn take_mutably(mut x: &i32) {}
fn main() {
take_m<|>
take_m$0
}
"#,
r#"

View file

@ -135,7 +135,7 @@ mod tests {
"frobnicate!",
r#"
//- /main.rs crate:main deps:foo
use foo::<|>;
use foo::$0;
//- /foo/lib.rs crate:foo
#[macro_export]
macro_rules! frobnicate { () => () }
@ -149,7 +149,7 @@ use foo::frobnicate;
"frobnicate!",
r#"
macro_rules! frobnicate { () => () }
fn main() { frob<|>!(); }
fn main() { frob$0!(); }
"#,
r#"
macro_rules! frobnicate { () => () }
@ -173,7 +173,7 @@ fn main() { frobnicate!(); }
/// ```
macro_rules! vec { () => {} }
fn fn main() { v<|> }
fn fn main() { v$0 }
"#,
r#"
/// Creates a [`Vec`] containing the arguments.
@ -198,7 +198,7 @@ fn fn main() { vec![$0] }
/// Don't call `fooo!()` `fooo!()`, or `_foo![]` `_foo![]`,
/// call as `let _=foo! { hello world };`
macro_rules! foo { () => {} }
fn main() { <|> }
fn main() { $0 }
"#,
r#"
/// Foo

View file

@ -22,12 +22,12 @@ pub(crate) const TEST_CONFIG: CompletionConfig = CompletionConfig {
merge: Some(MergeBehavior::Full),
};
/// Creates analysis from a multi-file fixture, returns positions marked with <|>.
/// Creates analysis from a multi-file fixture, returns positions marked with $0.
pub(crate) fn position(ra_fixture: &str) -> (RootDatabase, FilePosition) {
let change_fixture = ChangeFixture::parse(ra_fixture);
let mut database = RootDatabase::default();
database.apply_change(change_fixture.change);
let (file_id, range_or_offset) = change_fixture.file_position.expect("expected a marker (<|>)");
let (file_id, range_or_offset) = change_fixture.file_position.expect("expected a marker ($0)");
let offset = match range_or_offset {
RangeOrOffset::Range(_) => panic!(),
RangeOrOffset::Offset(it) => it,

View file

@ -194,7 +194,7 @@ mod tests {
let mut buf = String::new();
let off: usize = offset.into();
buf.push_str(&code[..off]);
buf.push_str("<|>marker");
buf.push_str("$0marker");
buf.push_str(&code[off..]);
buf
};
@ -231,7 +231,7 @@ mod tests {
r"
fn quux(foo: i32) {
let f = |bar, baz: i32| {
<|>
$0
};
}",
&["bar", "baz", "foo"],
@ -243,7 +243,7 @@ mod tests {
do_check(
r"
fn quux() {
f(|x| <|> );
f(|x| $0 );
}",
&["x"],
);
@ -254,7 +254,7 @@ mod tests {
do_check(
r"
fn quux() {
z.f(|x| <|> );
z.f(|x| $0 );
}",
&["x"],
);
@ -267,7 +267,7 @@ mod tests {
fn quux() {
loop {
let x = ();
<|>
$0
};
}",
&["x"],
@ -281,7 +281,7 @@ mod tests {
fn quux() {
match () {
Some(x) => {
<|>
$0
}
};
}",
@ -294,7 +294,7 @@ mod tests {
do_check(
r"
fn foo(x: String) {
let x : &str = &x<|>;
let x : &str = &x$0;
}",
&["x"],
);
@ -307,7 +307,7 @@ mod tests {
fn foo() {
match Some(()) {
opt @ Some(unit) => {
<|>
$0
}
_ => {}
}
@ -330,7 +330,7 @@ fn foo() {
fn foo() {
mac!();
<|>
$0
}
",
&[],
@ -343,7 +343,7 @@ fn foo() {
r"
fn foo() {
trait {}
<|>
$0
}
",
&[],
@ -391,7 +391,7 @@ fn foo(x: i32, y: u32) {
let z = x * 2;
}
{
let t = x<|> * 3;
let t = x$0 * 3;
}
}
"#,
@ -404,7 +404,7 @@ fn foo(x: i32, y: u32) {
do_check_local_name(
r#"
fn foo(x: String) {
let x : &str = &x<|>;
let x : &str = &x$0;
}
"#,
7,
@ -417,7 +417,7 @@ fn foo(x: String) {
r"
fn foo(x: String) {
let x : &str = &x;
x<|>
x$0
}
",
28,
@ -430,7 +430,7 @@ fn foo(x: String) {
r"
fn foo() {
if let Some(&from) = bar() {
from<|>;
from$0;
}
}
",
@ -446,7 +446,7 @@ fn foo() {
fn test() {
let foo: Option<f32> = None;
while let Option::Some(spam) = foo {
spam<|>
spam$0
}
}
"#,

View file

@ -410,7 +410,7 @@ mod tests {
let code = r#"
//- /main.rs
struct S;
<|>
$0
"#;
check_found_path(code, "S", "S", "crate::S", "self::S");
}
@ -420,7 +420,7 @@ mod tests {
let code = r#"
//- /main.rs
enum E { A }
<|>
$0
"#;
check_found_path(code, "E::A", "E::A", "E::A", "E::A");
}
@ -432,7 +432,7 @@ mod tests {
mod foo {
pub struct S;
}
<|>
$0
"#;
check_found_path(code, "foo::S", "foo::S", "crate::foo::S", "self::foo::S");
}
@ -446,7 +446,7 @@ mod tests {
mod bar;
struct S;
//- /foo/bar.rs
<|>
$0
"#;
check_found_path(code, "super::S", "super::S", "crate::foo::S", "super::S");
}
@ -457,7 +457,7 @@ mod tests {
//- /main.rs
mod foo;
//- /foo.rs
<|>
$0
"#;
check_found_path(code, "self", "self", "crate::foo", "self");
}
@ -468,7 +468,7 @@ mod tests {
//- /main.rs
mod foo;
//- /foo.rs
<|>
$0
"#;
check_found_path(code, "crate", "crate", "crate", "crate");
}
@ -480,7 +480,7 @@ mod tests {
mod foo;
struct S;
//- /foo.rs
<|>
$0
"#;
check_found_path(code, "crate::S", "crate::S", "crate::S", "crate::S");
}
@ -489,7 +489,7 @@ mod tests {
fn different_crate() {
let code = r#"
//- /main.rs crate:main deps:std
<|>
$0
//- /std.rs crate:std
pub struct S;
"#;
@ -501,7 +501,7 @@ mod tests {
let code = r#"
//- /main.rs crate:main deps:std
extern crate std as std_renamed;
<|>
$0
//- /std.rs crate:std
pub struct S;
"#;
@ -523,7 +523,7 @@ mod tests {
//- /main.rs crate:main deps:syntax
use syntax::ast;
<|>
$0
//- /lib.rs crate:syntax
pub mod ast {
@ -543,7 +543,7 @@ mod tests {
let code = r#"
//- /main.rs crate:main deps:syntax
<|>
$0
//- /lib.rs crate:syntax
pub mod ast {
@ -569,7 +569,7 @@ mod tests {
mod foo { pub(super) struct S; }
pub(crate) use foo::*;
}
<|>
$0
"#;
check_found_path(code, "bar::S", "bar::S", "crate::bar::S", "self::bar::S");
}
@ -582,7 +582,7 @@ mod tests {
mod foo { pub(super) struct S; }
pub(crate) use foo::S as U;
}
<|>
$0
"#;
check_found_path(code, "bar::U", "bar::U", "crate::bar::U", "self::bar::U");
}
@ -591,7 +591,7 @@ mod tests {
fn different_crate_reexport() {
let code = r#"
//- /main.rs crate:main deps:std
<|>
$0
//- /std.rs crate:std deps:core
pub use core::S;
//- /core.rs crate:core
@ -604,7 +604,7 @@ mod tests {
fn prelude() {
let code = r#"
//- /main.rs crate:main deps:std
<|>
$0
//- /std.rs crate:std
pub mod prelude { pub struct S; }
#[prelude_import]
@ -617,7 +617,7 @@ mod tests {
fn enum_variant_from_prelude() {
let code = r#"
//- /main.rs crate:main deps:std
<|>
$0
//- /std.rs crate:std
pub mod prelude {
pub enum Option<T> { Some(T), None }
@ -637,7 +637,7 @@ mod tests {
pub mod foo;
pub mod baz;
struct S;
<|>
$0
//- /foo.rs
pub mod bar { pub struct S; }
//- /baz.rs
@ -654,7 +654,7 @@ mod tests {
pub mod bar { pub struct S; }
use bar::S;
//- /foo.rs
<|>
$0
"#;
// crate::S would be shorter, but using private imports seems wrong
check_found_path(code, "crate::bar::S", "crate::bar::S", "crate::bar::S", "crate::bar::S");
@ -668,7 +668,7 @@ mod tests {
pub mod bar;
pub mod baz;
//- /bar.rs
<|>
$0
//- /foo.rs
pub use super::baz;
pub struct S;
@ -683,7 +683,7 @@ mod tests {
mark::check!(prefer_std_paths);
let code = r#"
//- /main.rs crate:main deps:alloc,std
<|>
$0
//- /std.rs crate:std deps:alloc
pub mod sync {
@ -711,7 +711,7 @@ mod tests {
//- /main.rs crate:main deps:core,std
#![no_std]
<|>
$0
//- /std.rs crate:std deps:core
@ -740,7 +740,7 @@ mod tests {
//- /main.rs crate:main deps:alloc,std
#![no_std]
<|>
$0
//- /std.rs crate:std deps:alloc
@ -767,7 +767,7 @@ mod tests {
fn prefer_shorter_paths_if_not_alloc() {
let code = r#"
//- /main.rs crate:main deps:megaalloc,std
<|>
$0
//- /std.rs crate:std deps:megaalloc
pub mod sync {
@ -790,7 +790,7 @@ mod tests {
fn builtins_are_in_scope() {
let code = r#"
//- /main.rs
<|>
$0
pub mod primitive {
pub use u8;

View file

@ -28,7 +28,7 @@ fn typing_inside_a_function_should_not_invalidate_def_map() {
check_def_map_is_not_recomputed(
r"
//- /lib.rs
mod foo;<|>
mod foo;$0
use crate::foo::bar::Baz;
@ -81,7 +81,7 @@ fn typing_inside_a_macro_should_not_invalidate_def_map() {
pub mod bar;
//- /foo/bar.rs
<|>
$0
m!(X);
",
);

View file

@ -277,7 +277,7 @@ mod tests {
let expander = BuiltinDeriveExpander::find_by_name(&name).unwrap();
let fixture = format!(
r#"//- /main.rs crate:main deps:core
<|>
$0
{}
//- /lib.rs crate:core
// empty

View file

@ -314,7 +314,7 @@ fn typing_whitespace_inside_a_function_should_not_invalidate_types() {
"
//- /lib.rs
fn foo() -> i32 {
<|>1 + 1
$01 + 1
}
",
);

View file

@ -178,7 +178,7 @@ mod tests {
//- /lib.rs
fn callee() {}
fn caller() {
call<|>ee();
call$0ee();
}
"#,
"callee Function FileId(0) 0..14 3..9",
@ -192,7 +192,7 @@ fn caller() {
check_hierarchy(
r#"
//- /lib.rs
fn call<|>ee() {}
fn call$0ee() {}
fn caller() {
callee();
}
@ -210,7 +210,7 @@ fn caller() {
//- /lib.rs
fn callee() {}
fn caller() {
call<|>ee();
call$0ee();
callee();
}
"#,
@ -227,7 +227,7 @@ fn caller() {
//- /lib.rs
fn callee() {}
fn caller1() {
call<|>ee();
call$0ee();
}
fn caller2() {
@ -250,7 +250,7 @@ fn caller2() {
//- /lib.rs cfg:test
fn callee() {}
fn caller1() {
call<|>ee();
call$0ee();
}
#[cfg(test)]
@ -281,7 +281,7 @@ mod foo;
use foo::callee;
fn caller() {
call<|>ee();
call$0ee();
}
//- /foo/mod.rs
@ -299,7 +299,7 @@ pub fn callee() {}
r#"
//- /lib.rs
fn callee() {}
fn call<|>er() {
fn call$0er() {
callee();
callee();
}
@ -318,7 +318,7 @@ fn call<|>er() {
mod foo;
use foo::callee;
fn call<|>er() {
fn call$0er() {
callee();
}
@ -337,7 +337,7 @@ pub fn callee() {}
r#"
//- /lib.rs
fn caller1() {
call<|>er2();
call$0er2();
}
fn caller2() {
@ -365,7 +365,7 @@ fn a() {
fn b() {}
fn main() {
a<|>()
a$0()
}
"#,
"a Function FileId(0) 0..18 3..4",
@ -376,7 +376,7 @@ fn main() {
check_hierarchy(
r#"
fn a() {
b<|>()
b$0()
}
fn b() {}

View file

@ -315,7 +315,7 @@ fn div(x: i32, y: i32) -> Result<i32, ()> {
if y == 0 {
return Err(());
}
x / y<|>
x / y$0
}
//- /core/lib.rs crate:core
pub mod result {
@ -346,7 +346,7 @@ fn div<T>(x: T) -> Result<T, i32> {
if x == 0 {
return Err(7);
}
<|>x
$0x
}
//- /core/lib.rs crate:core
pub mod result {
@ -379,7 +379,7 @@ fn div(x: i32, y: i32) -> MyResult<i32> {
if y == 0 {
return Err(());
}
x <|>/ y
x $0/ y
}
//- /core/lib.rs crate:core
pub mod result {
@ -444,7 +444,7 @@ pub mod result {
struct TestStruct { one: i32, two: i64 }
fn test_fn() {
let s = TestStruct {<|>};
let s = TestStruct {$0};
}
"#,
r#"
@ -464,7 +464,7 @@ fn test_fn() {
struct TestStruct { one: i32 }
impl TestStruct {
fn test_fn() { let s = Self {<|>}; }
fn test_fn() { let s = Self {$0}; }
}
"#,
r#"
@ -487,7 +487,7 @@ enum Expr {
impl Expr {
fn new_bin(lhs: Box<Expr>, rhs: Box<Expr>) -> Expr {
Expr::Bin {<|> }
Expr::Bin {$0 }
}
}
"#,
@ -512,7 +512,7 @@ impl Expr {
struct TestStruct { one: i32, two: i64 }
fn test_fn() {
let s = TestStruct{ two: 2<|> };
let s = TestStruct{ two: 2$0 };
}
"#,
r"
@ -608,7 +608,7 @@ fn here() {}
macro_rules! id { ($($tt:tt)*) => { $($tt)*}; }
fn main() {
let _x = id![Foo { a: <|>42 }];
let _x = id![Foo { a: $042 }];
}
pub struct Foo { pub a: i32, pub b: i32 }
@ -663,7 +663,7 @@ mod a {
check_fix(
r"
mod b {}
use {<|>b};
use {$0b};
",
r"
mod b {}
@ -673,7 +673,7 @@ mod a {
check_fix(
r"
mod b {}
use {b<|>};
use {b$0};
",
r"
mod b {}
@ -683,7 +683,7 @@ mod a {
check_fix(
r"
mod a { mod c {} }
use a::{c<|>};
use a::{c$0};
",
r"
mod a { mod c {} }
@ -693,7 +693,7 @@ mod a {
check_fix(
r"
mod a {}
use a::{self<|>};
use a::{self$0};
",
r"
mod a {}
@ -703,7 +703,7 @@ mod a {
check_fix(
r"
mod a { mod c {} mod d { mod e {} } }
use a::{c, d::{e<|>}};
use a::{c, d::{e$0}};
",
r"
mod a { mod c {} mod d { mod e {} } }
@ -717,7 +717,7 @@ mod a {
check_fix(
r"
fn main() {
Foo { bar: 3, baz<|>: false};
Foo { bar: 3, baz$0: false};
}
struct Foo {
bar: i32
@ -743,7 +743,7 @@ struct Foo {
mod foo;
fn main() {
foo::Foo { bar: 3, <|>baz: false};
foo::Foo { bar: 3, $0baz: false};
}
//- /foo.rs
struct Foo {
@ -777,7 +777,7 @@ struct Foo {
fn test_rename_incorrect_case() {
check_fix(
r#"
pub struct test_struct<|> { one: i32 }
pub struct test_struct$0 { one: i32 }
pub fn some_fn(val: test_struct) -> test_struct {
test_struct { one: val.one + 1 }
@ -794,7 +794,7 @@ pub fn some_fn(val: TestStruct) -> TestStruct {
check_fix(
r#"
pub fn some_fn(NonSnakeCase<|>: u8) -> u8 {
pub fn some_fn(NonSnakeCase$0: u8) -> u8 {
NonSnakeCase
}
"#,
@ -807,7 +807,7 @@ pub fn some_fn(non_snake_case: u8) -> u8 {
check_fix(
r#"
pub fn SomeFn<|>(val: u8) -> u8 {
pub fn SomeFn$0(val: u8) -> u8 {
if val != 0 { SomeFn(val - 1) } else { val }
}
"#,
@ -821,7 +821,7 @@ pub fn some_fn(val: u8) -> u8 {
check_fix(
r#"
fn some_fn() {
let whatAWeird_Formatting<|> = 10;
let whatAWeird_Formatting$0 = 10;
another_func(whatAWeird_Formatting);
}
"#,
@ -839,7 +839,7 @@ fn some_fn() {
check_no_diagnostics(
r#"
fn foo() {
const ANOTHER_ITEM<|>: &str = "some_item";
const ANOTHER_ITEM$0: &str = "some_item";
}
"#,
);
@ -852,7 +852,7 @@ fn foo() {
pub struct TestStruct;
impl TestStruct {
pub fn SomeFn<|>() -> TestStruct {
pub fn SomeFn$0() -> TestStruct {
TestStruct
}
}
@ -871,7 +871,7 @@ impl TestStruct {
#[test]
fn test_single_incorrect_case_diagnostic_in_function_name_issue_6970() {
let input = r#"fn FOO<|>() {}"#;
let input = r#"fn FOO$0() {}"#;
let expected = r#"fn foo() {}"#;
let (analysis, file_position) = fixture::position(input);

View file

@ -120,7 +120,7 @@ fn main() { A { 0: 0 } }
struct A { a: &'static str }
fn main() {
let a = "haha";
A { a<|>: a }
A { a$0: a }
}
"#,
r#"
@ -138,7 +138,7 @@ struct A { a: &'static str, b: &'static str }
fn main() {
let a = "haha";
let b = "bb";
A { a<|>: a, b }
A { a$0: a, b }
}
"#,
r#"
@ -171,7 +171,7 @@ fn f(a: A) { let A { 0: 0 } = a; }
r#"
struct A { a: &'static str }
fn f(a: A) {
let A { a<|>: a } = a;
let A { a$0: a } = a;
}
"#,
r#"
@ -186,7 +186,7 @@ fn f(a: A) {
r#"
struct A { a: &'static str, b: &'static str }
fn f(a: A) {
let A { a<|>: a, b } = a;
let A { a$0: a, b } = a;
}
"#,
r#"

View file

@ -464,7 +464,7 @@ mod tests {
fn test_doc_url_struct() {
check(
r#"
pub struct Fo<|>o;
pub struct Fo$0o;
"#,
expect![[r#"https://docs.rs/test/*/test/struct.Foo.html"#]],
);
@ -474,7 +474,7 @@ pub struct Fo<|>o;
fn test_doc_url_fn() {
check(
r#"
pub fn fo<|>o() {}
pub fn fo$0o() {}
"#,
expect![[r##"https://docs.rs/test/*/test/fn.foo.html#method.foo"##]],
);
@ -487,7 +487,7 @@ pub fn fo<|>o() {}
pub struct Foo;
impl Foo {
pub fn met<|>hod() {}
pub fn met$0hod() {}
}
"#,
@ -500,7 +500,7 @@ impl Foo {
check(
r#"
pub trait Bar {
fn met<|>hod() {}
fn met$0hod() {}
}
"#,
@ -513,7 +513,7 @@ pub trait Bar {
check(
r#"
pub trait Foo {
fn met<|>hod();
fn met$0hod();
}
"#,
@ -526,7 +526,7 @@ pub trait Foo {
check(
r#"
pub struct Foo {
pub fie<|>ld: ()
pub fie$0ld: ()
}
"#,
@ -539,7 +539,7 @@ pub struct Foo {
check(
r#"
pub mod foo {
pub mod ba<|>r {}
pub mod ba$0r {}
}
"#,
expect![[r#"https://docs.rs/test/*/test/foo/bar/index.html"#]],
@ -564,7 +564,7 @@ pub mod wrapper {
}
fn foo() {
let bar: wrapper::It<|>em;
let bar: wrapper::It$0em;
}
"#,
expect![[r#"https://docs.rs/test/*/test/wrapper/module/struct.Item.html"#]],

View file

@ -144,7 +144,7 @@ macro_rules! foo {
macro_rules! baz {
() => { foo!(); }
}
f<|>oo!();
f$0oo!();
"#,
expect![[r#"
foo
@ -165,7 +165,7 @@ macro_rules! foo {
}
}
}
f<|>oo!();
f$0oo!();
"#,
expect![[r#"
foo
@ -192,7 +192,7 @@ macro_rules! match_ast {
}
fn main() {
mat<|>ch_ast! {
mat$0ch_ast! {
match container {
ast::TraitDef(it) => {},
ast::ImplDef(it) => {},
@ -226,7 +226,7 @@ macro_rules! match_ast {
fn main() {
let p = f(|it| {
let res = mat<|>ch_ast! { match c {}};
let res = mat$0ch_ast! { match c {}};
Some(res)
})?;
}
@ -250,7 +250,7 @@ macro_rules! foo {
}
fn main() {
let res = fo<|>o!();
let res = fo$0o!();
}
"#,
expect![[r#"
@ -272,7 +272,7 @@ macro_rules! foo {
}
fn main() {
let res = fo<|>o!();
let res = fo$0o!();
}
"#,
expect![[r#"

View file

@ -334,29 +334,29 @@ mod tests {
#[test]
fn test_extend_selection_arith() {
do_check(r#"fn foo() { <|>1 + 1 }"#, &["1", "1 + 1", "{ 1 + 1 }"]);
do_check(r#"fn foo() { $01 + 1 }"#, &["1", "1 + 1", "{ 1 + 1 }"]);
}
#[test]
fn test_extend_selection_list() {
do_check(r#"fn foo(<|>x: i32) {}"#, &["x", "x: i32"]);
do_check(r#"fn foo(<|>x: i32, y: i32) {}"#, &["x", "x: i32", "x: i32, "]);
do_check(r#"fn foo(<|>x: i32,y: i32) {}"#, &["x", "x: i32", "x: i32,", "(x: i32,y: i32)"]);
do_check(r#"fn foo(x: i32, <|>y: i32) {}"#, &["y", "y: i32", ", y: i32"]);
do_check(r#"fn foo(x: i32, <|>y: i32, ) {}"#, &["y", "y: i32", "y: i32, "]);
do_check(r#"fn foo(x: i32,<|>y: i32) {}"#, &["y", "y: i32", ",y: i32"]);
do_check(r#"fn foo($0x: i32) {}"#, &["x", "x: i32"]);
do_check(r#"fn foo($0x: i32, y: i32) {}"#, &["x", "x: i32", "x: i32, "]);
do_check(r#"fn foo($0x: i32,y: i32) {}"#, &["x", "x: i32", "x: i32,", "(x: i32,y: i32)"]);
do_check(r#"fn foo(x: i32, $0y: i32) {}"#, &["y", "y: i32", ", y: i32"]);
do_check(r#"fn foo(x: i32, $0y: i32, ) {}"#, &["y", "y: i32", "y: i32, "]);
do_check(r#"fn foo(x: i32,$0y: i32) {}"#, &["y", "y: i32", ",y: i32"]);
do_check(r#"const FOO: [usize; 2] = [ 22<|> , 33];"#, &["22", "22 , "]);
do_check(r#"const FOO: [usize; 2] = [ 22 , 33<|>];"#, &["33", ", 33"]);
do_check(r#"const FOO: [usize; 2] = [ 22 , 33<|> ,];"#, &["33", "33 ,", "[ 22 , 33 ,]"]);
do_check(r#"const FOO: [usize; 2] = [ 22$0 , 33];"#, &["22", "22 , "]);
do_check(r#"const FOO: [usize; 2] = [ 22 , 33$0];"#, &["33", ", 33"]);
do_check(r#"const FOO: [usize; 2] = [ 22 , 33$0 ,];"#, &["33", "33 ,", "[ 22 , 33 ,]"]);
do_check(r#"fn main() { (1, 2<|>) }"#, &["2", ", 2", "(1, 2)"]);
do_check(r#"fn main() { (1, 2$0) }"#, &["2", ", 2", "(1, 2)"]);
do_check(
r#"
const FOO: [usize; 2] = [
22,
<|>33,
$033,
]"#,
&["33", "33,"],
);
@ -365,7 +365,7 @@ const FOO: [usize; 2] = [
r#"
const FOO: [usize; 2] = [
22
, 33<|>,
, 33$0,
]"#,
&["33", "33,"],
);
@ -376,7 +376,7 @@ const FOO: [usize; 2] = [
do_check(
r#"
impl S {
<|> fn foo() {
$0 fn foo() {
}
}"#,
@ -393,7 +393,7 @@ struct A;
/// bla
/// bla
struct B {
<|>
$0
}
"#,
&["\n \n", "{\n \n}", "/// bla\n/// bla\nstruct B {\n \n}"],
@ -407,7 +407,7 @@ struct B {
fn bar(){}
// fn foo() {
// 1 + <|>1
// 1 + $01
// }
// fn foo(){}
@ -419,7 +419,7 @@ fn bar(){}
r#"
// #[derive(Debug, Clone, Copy, PartialEq, Eq)]
// pub enum Direction {
// <|> Next,
// $0 Next,
// Prev
// }
"#,
@ -433,27 +433,27 @@ fn bar(){}
r#"
/*
foo
_bar1<|>*/
_bar1$0*/
"#,
&["_bar1", "/*\nfoo\n_bar1*/"],
);
do_check(r#"//!<|>foo_2 bar"#, &["foo_2", "//!foo_2 bar"]);
do_check(r#"//!$0foo_2 bar"#, &["foo_2", "//!foo_2 bar"]);
do_check(r#"/<|>/foo bar"#, &["//foo bar"]);
do_check(r#"/$0/foo bar"#, &["//foo bar"]);
}
#[test]
fn test_extend_selection_prefer_idents() {
do_check(
r#"
fn main() { foo<|>+bar;}
fn main() { foo$0+bar;}
"#,
&["foo", "foo+bar"],
);
do_check(
r#"
fn main() { foo+<|>bar;}
fn main() { foo+$0bar;}
"#,
&["bar", "foo+bar"],
);
@ -461,18 +461,18 @@ fn main() { foo+<|>bar;}
#[test]
fn test_extend_selection_prefer_lifetimes() {
do_check(r#"fn foo<<|>'a>() {}"#, &["'a", "<'a>"]);
do_check(r#"fn foo<'a<|>>() {}"#, &["'a", "<'a>"]);
do_check(r#"fn foo<$0'a>() {}"#, &["'a", "<'a>"]);
do_check(r#"fn foo<'a$0>() {}"#, &["'a", "<'a>"]);
}
#[test]
fn test_extend_selection_select_first_word() {
do_check(r#"// foo bar b<|>az quxx"#, &["baz", "// foo bar baz quxx"]);
do_check(r#"// foo bar b$0az quxx"#, &["baz", "// foo bar baz quxx"]);
do_check(
r#"
impl S {
fn foo() {
// hel<|>lo world
// hel$0lo world
}
}
"#,
@ -486,7 +486,7 @@ fn foo() {
r#"
fn bar(){}
" fn f<|>oo() {"
" fn f$0oo() {"
"#,
&["foo", "\" fn foo() {\""],
);
@ -499,7 +499,7 @@ fn bar(){}
fn foo<R>()
where
R: req::Request + 'static,
R::Params: DeserializeOwned<|> + panic::UnwindSafe + 'static,
R::Params: DeserializeOwned$0 + panic::UnwindSafe + 'static,
R::Result: Serialize + 'static,
"#,
&[
@ -510,26 +510,26 @@ fn foo<R>()
"R::Params: DeserializeOwned + panic::UnwindSafe + 'static,",
],
);
do_check(r#"fn foo<T>() where T: <|>Copy"#, &["Copy"]);
do_check(r#"fn foo<T>() where T: <|>Copy + Display"#, &["Copy", "Copy + "]);
do_check(r#"fn foo<T>() where T: <|>Copy +Display"#, &["Copy", "Copy +"]);
do_check(r#"fn foo<T>() where T: <|>Copy+Display"#, &["Copy", "Copy+"]);
do_check(r#"fn foo<T>() where T: Copy + <|>Display"#, &["Display", "+ Display"]);
do_check(r#"fn foo<T>() where T: Copy + <|>Display + Sync"#, &["Display", "Display + "]);
do_check(r#"fn foo<T>() where T: Copy +<|>Display"#, &["Display", "+Display"]);
do_check(r#"fn foo<T>() where T: $0Copy"#, &["Copy"]);
do_check(r#"fn foo<T>() where T: $0Copy + Display"#, &["Copy", "Copy + "]);
do_check(r#"fn foo<T>() where T: $0Copy +Display"#, &["Copy", "Copy +"]);
do_check(r#"fn foo<T>() where T: $0Copy+Display"#, &["Copy", "Copy+"]);
do_check(r#"fn foo<T>() where T: Copy + $0Display"#, &["Display", "+ Display"]);
do_check(r#"fn foo<T>() where T: Copy + $0Display + Sync"#, &["Display", "Display + "]);
do_check(r#"fn foo<T>() where T: Copy +$0Display"#, &["Display", "+Display"]);
}
#[test]
fn test_extend_trait_bounds_list_inline() {
do_check(r#"fn foo<T: <|>Copy>() {}"#, &["Copy"]);
do_check(r#"fn foo<T: <|>Copy + Display>() {}"#, &["Copy", "Copy + "]);
do_check(r#"fn foo<T: <|>Copy +Display>() {}"#, &["Copy", "Copy +"]);
do_check(r#"fn foo<T: <|>Copy+Display>() {}"#, &["Copy", "Copy+"]);
do_check(r#"fn foo<T: Copy + <|>Display>() {}"#, &["Display", "+ Display"]);
do_check(r#"fn foo<T: Copy + <|>Display + Sync>() {}"#, &["Display", "Display + "]);
do_check(r#"fn foo<T: Copy +<|>Display>() {}"#, &["Display", "+Display"]);
do_check(r#"fn foo<T: $0Copy>() {}"#, &["Copy"]);
do_check(r#"fn foo<T: $0Copy + Display>() {}"#, &["Copy", "Copy + "]);
do_check(r#"fn foo<T: $0Copy +Display>() {}"#, &["Copy", "Copy +"]);
do_check(r#"fn foo<T: $0Copy+Display>() {}"#, &["Copy", "Copy+"]);
do_check(r#"fn foo<T: Copy + $0Display>() {}"#, &["Display", "+ Display"]);
do_check(r#"fn foo<T: Copy + $0Display + Sync>() {}"#, &["Display", "Display + "]);
do_check(r#"fn foo<T: Copy +$0Display>() {}"#, &["Display", "+Display"]);
do_check(
r#"fn foo<T: Copy<|> + Display, U: Copy>() {}"#,
r#"fn foo<T: Copy$0 + Display, U: Copy>() {}"#,
&[
"Copy",
"Copy + ",
@ -544,19 +544,19 @@ fn foo<R>()
#[test]
fn test_extend_selection_on_tuple_in_type() {
do_check(
r#"fn main() { let _: (krate, <|>_crate_def_map, module_id) = (); }"#,
r#"fn main() { let _: (krate, $0_crate_def_map, module_id) = (); }"#,
&["_crate_def_map", "_crate_def_map, ", "(krate, _crate_def_map, module_id)"],
);
// white space variations
do_check(
r#"fn main() { let _: (krate,<|>_crate_def_map,module_id) = (); }"#,
r#"fn main() { let _: (krate,$0_crate_def_map,module_id) = (); }"#,
&["_crate_def_map", "_crate_def_map,", "(krate,_crate_def_map,module_id)"],
);
do_check(
r#"
fn main() { let _: (
krate,
_crate<|>_def_map,
_crate$0_def_map,
module_id
) = (); }"#,
&[
@ -570,19 +570,19 @@ fn main() { let _: (
#[test]
fn test_extend_selection_on_tuple_in_rvalue() {
do_check(
r#"fn main() { let var = (krate, _crate_def_map<|>, module_id); }"#,
r#"fn main() { let var = (krate, _crate_def_map$0, module_id); }"#,
&["_crate_def_map", "_crate_def_map, ", "(krate, _crate_def_map, module_id)"],
);
// white space variations
do_check(
r#"fn main() { let var = (krate,_crate<|>_def_map,module_id); }"#,
r#"fn main() { let var = (krate,_crate$0_def_map,module_id); }"#,
&["_crate_def_map", "_crate_def_map,", "(krate,_crate_def_map,module_id)"],
);
do_check(
r#"
fn main() { let var = (
krate,
_crate_def_map<|>,
_crate_def_map$0,
module_id
); }"#,
&[
@ -596,19 +596,19 @@ fn main() { let var = (
#[test]
fn test_extend_selection_on_tuple_pat() {
do_check(
r#"fn main() { let (krate, _crate_def_map<|>, module_id) = var; }"#,
r#"fn main() { let (krate, _crate_def_map$0, module_id) = var; }"#,
&["_crate_def_map", "_crate_def_map, ", "(krate, _crate_def_map, module_id)"],
);
// white space variations
do_check(
r#"fn main() { let (krate,_crate<|>_def_map,module_id) = var; }"#,
r#"fn main() { let (krate,_crate$0_def_map,module_id) = var; }"#,
&["_crate_def_map", "_crate_def_map,", "(krate,_crate_def_map,module_id)"],
);
do_check(
r#"
fn main() { let (
krate,
_crate_def_map<|>,
_crate_def_map$0,
module_id
) = var; }"#,
&[
@ -623,7 +623,7 @@ fn main() { let (
fn extend_selection_inside_macros() {
do_check(
r#"macro_rules! foo { ($item:item) => {$item} }
foo!{fn hello(na<|>me:usize){}}"#,
foo!{fn hello(na$0me:usize){}}"#,
&[
"name",
"name:usize",
@ -640,7 +640,7 @@ fn main() { let (
do_check(
r#" macro_rules! foo2 { ($item:item) => {$item} }
macro_rules! foo { ($item:item) => {foo2!($item);} }
foo!{fn hello(na<|>me:usize){}}"#,
foo!{fn hello(na$0me:usize){}}"#,
&[
"name",
"name:usize",

View file

@ -20,12 +20,12 @@ pub(crate) fn files(ra_fixture: &str) -> (Analysis, Vec<FileId>) {
(host.analysis(), change_fixture.files)
}
/// Creates analysis from a multi-file fixture, returns positions marked with <|>.
/// Creates analysis from a multi-file fixture, returns positions marked with $0.
pub(crate) fn position(ra_fixture: &str) -> (Analysis, FilePosition) {
let mut host = AnalysisHost::default();
let change_fixture = ChangeFixture::parse(ra_fixture);
host.db.apply_change(change_fixture.change);
let (file_id, range_or_offset) = change_fixture.file_position.expect("expected a marker (<|>)");
let (file_id, range_or_offset) = change_fixture.file_position.expect("expected a marker ($0)");
let offset = match range_or_offset {
RangeOrOffset::Range(_) => panic!(),
RangeOrOffset::Offset(it) => it,
@ -33,12 +33,12 @@ pub(crate) fn position(ra_fixture: &str) -> (Analysis, FilePosition) {
(host.analysis(), FilePosition { file_id, offset })
}
/// Creates analysis for a single file, returns range marked with a pair of <|>.
/// Creates analysis for a single file, returns range marked with a pair of $0.
pub(crate) fn range(ra_fixture: &str) -> (Analysis, FileRange) {
let mut host = AnalysisHost::default();
let change_fixture = ChangeFixture::parse(ra_fixture);
host.db.apply_change(change_fixture.change);
let (file_id, range_or_offset) = change_fixture.file_position.expect("expected a marker (<|>)");
let (file_id, range_or_offset) = change_fixture.file_position.expect("expected a marker ($0)");
let range = match range_or_offset {
RangeOrOffset::Range(it) => it,
RangeOrOffset::Offset(_) => panic!(),
@ -46,12 +46,12 @@ pub(crate) fn range(ra_fixture: &str) -> (Analysis, FileRange) {
(host.analysis(), FileRange { file_id, range })
}
/// Creates analysis from a multi-file fixture, returns positions marked with <|>.
/// Creates analysis from a multi-file fixture, returns positions marked with $0.
pub(crate) fn annotations(ra_fixture: &str) -> (Analysis, FilePosition, Vec<(FileRange, String)>) {
let mut host = AnalysisHost::default();
let change_fixture = ChangeFixture::parse(ra_fixture);
host.db.apply_change(change_fixture.change);
let (file_id, range_or_offset) = change_fixture.file_position.expect("expected a marker (<|>)");
let (file_id, range_or_offset) = change_fixture.file_position.expect("expected a marker ($0)");
let offset = match range_or_offset {
RangeOrOffset::Range(_) => panic!(),
RangeOrOffset::Offset(it) => it,

View file

@ -34,7 +34,7 @@ mod tests {
fn test_find_all_methods() {
let (analysis, pos) = fixture::position(
r#"
fn private_fn() {<|>}
fn private_fn() {$0}
pub fn pub_fn() {}
@ -51,7 +51,7 @@ mod tests {
let (analysis, pos) = fixture::position(
r#"
trait Foo {
fn bar() {<|>}
fn bar() {$0}
fn baz() {}
}
"#,
@ -67,7 +67,7 @@ mod tests {
r#"
//- /lib.rs
#[test]
fn foo() {<|>}
fn foo() {$0}
pub fn pub_fn() {}

View file

@ -166,7 +166,7 @@ mod tests {
check(
r#"
//- /main.rs crate:main deps:std
extern crate std<|>;
extern crate std$0;
//- /std/lib.rs crate:std
// empty
//^ file
@ -179,7 +179,7 @@ mod tests {
check(
r#"
//- /main.rs crate:main deps:std
extern crate std as abc<|>;
extern crate std as abc$0;
//- /std/lib.rs crate:std
// empty
//^ file
@ -193,7 +193,7 @@ mod tests {
r#"
struct Foo;
//^^^
enum E { X(Foo<|>) }
enum E { X(Foo$0) }
"#,
);
}
@ -204,7 +204,7 @@ enum E { X(Foo<|>) }
r#"
struct Foo;
//^^^
enum E { X(<|>Foo) }
enum E { X($0Foo) }
"#,
);
}
@ -217,7 +217,7 @@ enum E { X(<|>Foo) }
use a::Foo;
mod a;
mod b;
enum E { X(Foo<|>) }
enum E { X(Foo$0) }
//- /a.rs
struct Foo;
@ -233,7 +233,7 @@ struct Foo;
check(
r#"
//- /lib.rs
mod <|>foo;
mod $0foo;
//- /foo.rs
// empty
@ -244,7 +244,7 @@ mod <|>foo;
check(
r#"
//- /lib.rs
mod <|>foo;
mod $0foo;
//- /foo/mod.rs
// empty
@ -260,7 +260,7 @@ mod <|>foo;
macro_rules! foo { () => { () } }
//^^^
fn bar() {
<|>foo!();
$0foo!();
}
"#,
);
@ -273,7 +273,7 @@ fn bar() {
//- /lib.rs
use foo::foo;
fn bar() {
<|>foo!();
$0foo!();
}
//- /foo/lib.rs
@ -289,7 +289,7 @@ macro_rules! foo { () => { () } }
check(
r#"
//- /lib.rs
use foo::foo<|>;
use foo::foo$0;
//- /foo/lib.rs
#[macro_export]
@ -312,7 +312,7 @@ define_fn!(foo);
//^^^
fn bar() {
<|>foo();
$0foo();
}
"#,
);
@ -331,7 +331,7 @@ macro_rules! define_fn {
//^^^^^^^^^^^^^
fn bar() {
<|>foo();
$0foo();
}
"#,
);
@ -347,7 +347,7 @@ macro_rules! foo {() => {0}}
fn bar() {
match (0,1) {
(<|>foo!(), _) => {}
($0foo!(), _) => {}
}
}
"#,
@ -363,7 +363,7 @@ macro_rules! foo {() => {0}}
//^^^
fn bar() {
match 0 {
<|>foo!() => {}
$0foo!() => {}
}
}
"#,
@ -375,7 +375,7 @@ fn bar() {
check(
r#"
//- /lib.rs crate:main deps:foo
use foo as bar<|>;
use foo as bar$0;
//- /foo/lib.rs crate:foo
// empty
@ -389,7 +389,7 @@ use foo as bar<|>;
check(
r#"
//- /lib.rs crate:main deps:foo
use foo::foo as bar<|>;
use foo::foo as bar$0;
//- /foo/lib.rs crate:foo
#[macro_export]
@ -410,7 +410,7 @@ impl Foo {
}
fn bar(foo: &Foo) {
foo.frobnicate<|>();
foo.frobnicate$0();
}
"#,
);
@ -425,7 +425,7 @@ struct Foo {
} //^^^^
fn bar(foo: &Foo) {
foo.spam<|>;
foo.spam$0;
}
"#,
);
@ -442,7 +442,7 @@ struct Foo {
fn bar() -> Foo {
Foo {
spam<|>: 0,
spam$0: 0,
}
}
"#,
@ -459,7 +459,7 @@ struct Foo {
} //^^^^
fn bar(foo: Foo) -> Foo {
let Foo { spam<|>: _, } = foo
let Foo { spam$0: _, } = foo
}
"#,
);
@ -474,7 +474,7 @@ struct Foo { spam: u32 }
//^^^^
fn bar() -> Foo {
Foo { spam<|>: m!() }
Foo { spam$0: m!() }
}
",
);
@ -489,7 +489,7 @@ struct Foo(u32);
fn bar() {
let foo = Foo(0);
foo.<|>0;
foo.$00;
}
"#,
);
@ -505,7 +505,7 @@ impl Foo {
} //^^^^^^^^^^
fn bar(foo: &Foo) {
Foo::frobnicate<|>();
Foo::frobnicate$0();
}
"#,
);
@ -520,7 +520,7 @@ trait Foo {
} //^^^^^^^^^^
fn bar() {
Foo::frobnicate<|>();
Foo::frobnicate$0();
}
"#,
);
@ -537,7 +537,7 @@ trait Trait {
impl Trait for Foo {}
fn bar() {
Foo::frobnicate<|>();
Foo::frobnicate$0();
}
"#,
);
@ -551,7 +551,7 @@ struct Foo;
impl Foo {
//^^^
pub fn new() -> Self {
Self<|> {}
Self$0 {}
}
}
"#,
@ -561,7 +561,7 @@ impl Foo {
struct Foo;
impl Foo {
//^^^
pub fn new() -> Self<|> {
pub fn new() -> Self$0 {
Self {}
}
}
@ -573,7 +573,7 @@ impl Foo {
enum Foo { A }
impl Foo {
//^^^
pub fn new() -> Self<|> {
pub fn new() -> Self$0 {
Foo::A
}
}
@ -585,7 +585,7 @@ impl Foo {
enum Foo { A }
impl Foo {
//^^^
pub fn thing(a: &Self<|>) {
pub fn thing(a: &Self$0) {
}
}
"#,
@ -603,7 +603,7 @@ trait Make {
impl Make for Foo {
//^^^
fn new() -> Self {
Self<|> {}
Self$0 {}
}
}
"#,
@ -617,7 +617,7 @@ trait Make {
}
impl Make for Foo {
//^^^
fn new() -> Self<|> {
fn new() -> Self$0 {
Self {}
}
}
@ -629,7 +629,7 @@ impl Make for Foo {
fn goto_def_when_used_on_definition_name_itself() {
check(
r#"
struct Foo<|> { value: u32 }
struct Foo$0 { value: u32 }
//^^^
"#,
);
@ -637,21 +637,21 @@ struct Foo<|> { value: u32 }
check(
r#"
struct Foo {
field<|>: string,
field$0: string,
} //^^^^^
"#,
);
check(
r#"
fn foo_test<|>() { }
fn foo_test$0() { }
//^^^^^^^^
"#,
);
check(
r#"
enum Foo<|> { Variant }
enum Foo$0 { Variant }
//^^^
"#,
);
@ -660,7 +660,7 @@ enum Foo<|> { Variant }
r#"
enum Foo {
Variant1,
Variant2<|>,
Variant2$0,
//^^^^^^^^
Variant3,
}
@ -669,35 +669,35 @@ enum Foo {
check(
r#"
static INNER<|>: &str = "";
static INNER$0: &str = "";
//^^^^^
"#,
);
check(
r#"
const INNER<|>: &str = "";
const INNER$0: &str = "";
//^^^^^
"#,
);
check(
r#"
type Thing<|> = Option<()>;
type Thing$0 = Option<()>;
//^^^^^
"#,
);
check(
r#"
trait Foo<|> { }
trait Foo$0 { }
//^^^
"#,
);
check(
r#"
mod bar<|> { }
mod bar$0 { }
//^^^
"#,
);
@ -714,7 +714,7 @@ fn foo() {}
//^^^
id! {
fn bar() {
fo<|>o();
fo$0o();
}
}
mod confuse_index { fn foo(); }
@ -743,7 +743,7 @@ pub mod __export {
fn foo() -> i8 {}
//^^^
fn test() {
format!("{}", fo<|>o())
format!("{}", fo$0o())
}
"#,
);
@ -761,7 +761,7 @@ macro_rules! include {}
//^^^^^^^^^^^^^^^^^^^
fn f() {
foo<|>();
foo$0();
}
mod confuse_index {
@ -778,7 +778,7 @@ fn foo() {}
fn goto_for_type_param() {
check(
r#"
struct Foo<T: Clone> { t: <|>T }
struct Foo<T: Clone> { t: $0T }
//^
"#,
);
@ -796,7 +796,7 @@ fn foo() {
let x = 1;
//^
id!({
let y = <|>x;
let y = $0x;
let z = y;
});
}
@ -814,7 +814,7 @@ fn foo() {
id!({
let y = x;
//^
let z = <|>y;
let z = $0y;
});
}
"#,
@ -829,7 +829,7 @@ fn main() {
fn foo() {
let x = 92;
//^
<|>x;
$0x;
}
}
"#,
@ -843,7 +843,7 @@ fn main() {
fn bar() {
macro_rules! foo { () => { () } }
//^^^
<|>foo!();
$0foo!();
}
"#,
);
@ -857,7 +857,7 @@ struct Foo { x: i32 }
fn main() {
let x = 92;
//^
Foo { x<|> };
Foo { x$0 };
}
"#,
)
@ -872,7 +872,7 @@ enum Foo {
} //^
fn baz(foo: Foo) {
match foo {
Foo::Bar { x<|> } => x
Foo::Bar { x$0 } => x
};
}
"#,
@ -887,7 +887,7 @@ enum Foo { Bar }
//^^^
impl Foo {
fn baz(self) {
match self { Self::Bar<|> => {} }
match self { Self::Bar$0 => {} }
}
}
"#,
@ -902,7 +902,7 @@ enum Foo { Bar { val: i32 } }
//^^^
impl Foo {
fn baz(self) -> i32 {
match self { Self::Bar<|> { val } => {} }
match self { Self::Bar$0 { val } => {} }
}
}
"#,
@ -916,7 +916,7 @@ impl Foo {
enum Foo { Bar }
//^^^
impl Foo {
fn baz(self) { Self::Bar<|>; }
fn baz(self) { Self::Bar$0; }
}
"#,
);
@ -929,7 +929,7 @@ impl Foo {
enum Foo { Bar { val: i32 } }
//^^^
impl Foo {
fn baz(self) { Self::Bar<|> {val: 4}; }
fn baz(self) { Self::Bar$0 {val: 4}; }
}
"#,
);
@ -939,7 +939,7 @@ impl Foo {
fn goto_def_for_type_alias_generic_parameter() {
check(
r#"
type Alias<T> = T<|>;
type Alias<T> = T$0;
//^
"#,
)
@ -950,7 +950,7 @@ type Alias<T> = T<|>;
check(
r#"
//- /lib.rs
foo::module<|>::mac!();
foo::module$0::mac!();
//- /foo/lib.rs
pub mod module {
@ -972,7 +972,7 @@ trait Iterator {
//^^^^
}
fn f() -> impl Iterator<Item<|> = u8> {}
fn f() -> impl Iterator<Item$0 = u8> {}
"#,
);
}
@ -987,7 +987,7 @@ trait Iterator {
type B;
}
fn f() -> impl Iterator<A<|> = u8, B = ()> {}
fn f() -> impl Iterator<A$0 = u8, B = ()> {}
"#,
);
check(
@ -998,7 +998,7 @@ trait Iterator {
//^
}
fn f() -> impl Iterator<A = u8, B<|> = ()> {}
fn f() -> impl Iterator<A = u8, B$0 = ()> {}
"#,
);
}
@ -1012,7 +1012,7 @@ trait Iterator {
//^^^^
}
fn g() -> <() as Iterator<Item<|> = ()>>::Item {}
fn g() -> <() as Iterator<Item$0 = ()>>::Item {}
"#,
);
}
@ -1027,7 +1027,7 @@ trait Iterator {
type B;
}
fn g() -> <() as Iterator<A<|> = (), B = u8>>::B {}
fn g() -> <() as Iterator<A$0 = (), B = u8>>::B {}
"#,
);
check(
@ -1038,7 +1038,7 @@ trait Iterator {
//^
}
fn g() -> <() as Iterator<A = (), B<|> = u8>>::A {}
fn g() -> <() as Iterator<A = (), B$0 = u8>>::A {}
"#,
);
}
@ -1052,7 +1052,7 @@ struct Foo {}
impl Foo {
fn bar(self: &Foo) {
//^^^^
let foo = sel<|>f;
let foo = sel$0f;
}
}"#,
)
@ -1065,7 +1065,7 @@ impl Foo {
struct Foo {}
impl Foo {
fn bar(&self<|>) {
fn bar(&self$0) {
//^^^^
}
}"#,
@ -1076,7 +1076,7 @@ impl Foo {
fn goto_lifetime_param_on_decl() {
check(
r#"
fn foo<'foobar<|>>(_: &'foobar ()) {
fn foo<'foobar$0>(_: &'foobar ()) {
//^^^^^^^
}"#,
)
@ -1086,7 +1086,7 @@ fn foo<'foobar<|>>(_: &'foobar ()) {
fn goto_lifetime_param_decl() {
check(
r#"
fn foo<'foobar>(_: &'foobar<|> ()) {
fn foo<'foobar>(_: &'foobar$0 ()) {
//^^^^^^^
}"#,
)
@ -1097,7 +1097,7 @@ fn foo<'foobar>(_: &'foobar<|> ()) {
check(
r#"
fn foo<'foobar>(_: &'foobar ()) {
fn foo<'foobar>(_: &'foobar<|> ()) {}
fn foo<'foobar>(_: &'foobar$0 ()) {}
//^^^^^^^
}"#,
)
@ -1108,13 +1108,13 @@ fn foo<'foobar>(_: &'foobar ()) {
fn goto_lifetime_hrtb() {
check(
r#"trait Foo<T> {}
fn foo<T>() where for<'a> T: Foo<&'a<|> (u8, u16)>, {}
fn foo<T>() where for<'a> T: Foo<&'a$0 (u8, u16)>, {}
//^^
"#,
);
check(
r#"trait Foo<T> {}
fn foo<T>() where for<'a<|>> T: Foo<&'a (u8, u16)>, {}
fn foo<T>() where for<'a$0> T: Foo<&'a (u8, u16)>, {}
//^^
"#,
);
@ -1125,7 +1125,7 @@ fn foo<T>() where for<'a<|>> T: Foo<&'a (u8, u16)>, {}
fn goto_lifetime_hrtb_for_type() {
check(
r#"trait Foo<T> {}
fn foo<T>() where T: for<'a> Foo<&'a<|> (u8, u16)>, {}
fn foo<T>() where T: for<'a> Foo<&'a$0 (u8, u16)>, {}
//^^
"#,
);
@ -1139,7 +1139,7 @@ fn foo<'foo>(_: &'foo ()) {
'foo: {
//^^^^
'bar: loop {
break 'foo<|>;
break 'foo$0;
}
}
}"#,

View file

@ -107,7 +107,7 @@ mod tests {
fn goto_implementation_works() {
check(
r#"
struct Foo<|>;
struct Foo$0;
impl Foo {}
//^^^
"#,
@ -118,7 +118,7 @@ impl Foo {}
fn goto_implementation_works_multiple_blocks() {
check(
r#"
struct Foo<|>;
struct Foo$0;
impl Foo {}
//^^^
impl Foo {}
@ -131,7 +131,7 @@ impl Foo {}
fn goto_implementation_works_multiple_mods() {
check(
r#"
struct Foo<|>;
struct Foo$0;
mod a {
impl super::Foo {}
//^^^^^^^^^^
@ -149,7 +149,7 @@ mod b {
check(
r#"
//- /lib.rs
struct Foo<|>;
struct Foo$0;
mod a;
mod b;
//- /a.rs
@ -166,7 +166,7 @@ impl crate::Foo {}
fn goto_implementation_for_trait() {
check(
r#"
trait T<|> {}
trait T$0 {}
struct Foo;
impl T for Foo {}
//^^^
@ -179,7 +179,7 @@ impl T for Foo {}
check(
r#"
//- /lib.rs
trait T<|> {};
trait T$0 {};
struct Foo;
mod a;
mod b;
@ -199,7 +199,7 @@ impl crate::T for crate::Foo {}
r#"
//- /lib.rs
trait T {}
struct Foo<|>;
struct Foo$0;
impl Foo {}
//^^^
impl T for Foo {}
@ -216,7 +216,7 @@ impl T for &Foo {}
r#"
#[derive(Copy)]
//^^^^^^^^^^^^^^^
struct Foo<|>;
struct Foo$0;
mod marker {
trait Copy {}

View file

@ -76,7 +76,7 @@ mod tests {
struct Foo;
//^^^
fn foo() {
let f: Foo; f<|>
let f: Foo; f$0
}
"#,
);
@ -89,7 +89,7 @@ fn foo() {
struct Foo;
//^^^
fn foo() {
let f: &Foo; f<|>
let f: &Foo; f$0
}
"#,
);
@ -103,7 +103,7 @@ macro_rules! id { ($($tt:tt)*) => { $($tt)* } }
struct Foo {}
//^^^
id! {
fn bar() { let f<|> = Foo {}; }
fn bar() { let f$0 = Foo {}; }
}
"#,
);
@ -115,7 +115,7 @@ id! {
r#"
struct Foo;
//^^^
fn foo(<|>f: Foo) {}
fn foo($0f: Foo) {}
"#,
);
}
@ -129,7 +129,7 @@ struct Foo;
struct Bar(Foo);
fn foo() {
let bar = Bar(Foo);
bar.<|>0;
bar.$00;
}
"#,
);
@ -142,7 +142,7 @@ fn foo() {
struct Foo;
//^^^
impl Foo {
fn f(&self<|>) {}
fn f(&self$0) {}
}
"#,
)

View file

@ -457,7 +457,7 @@ mod tests {
pub fn foo() -> u32 { 1 }
fn main() {
let foo_test = foo()<|>;
let foo_test = foo()$0;
}
"#,
expect![[r#"
@ -476,7 +476,7 @@ fn main() {
pub fn foo() -> u32 { 1 }
fn main() {
let foo_test = foo()<|>;
let foo_test = foo()$0;
}
"#,
expect![[r#"
@ -506,7 +506,7 @@ fn main() {
Option::Some(*memo + value)
};
let number = 5u32;
let mut iter<|> = scan(OtherStruct { i: num }, closure, number);
let mut iter$0 = scan(OtherStruct { i: num }, closure, number);
}
"#,
expect![[r#"
@ -526,7 +526,7 @@ fn main() {
r#"
pub fn foo() -> u32 { 1 }
fn main() { let foo_test = fo<|>o(); }
fn main() { let foo_test = fo$0o(); }
"#,
expect![[r#"
*foo*
@ -558,7 +558,7 @@ mod a;
mod b;
mod c;
fn main() { let foo_test = fo<|>o(); }
fn main() { let foo_test = fo$0o(); }
"#,
expect![[r#"
*foo*
@ -575,7 +575,7 @@ fn main() { let foo_test = fo<|>o(); }
r#"
pub fn foo<'a, T: AsRef<str>>(b: &'a T) -> &'a str { }
fn main() { let foo_test = fo<|>o(); }
fn main() { let foo_test = fo$0o(); }
"#,
expect![[r#"
*foo*
@ -595,7 +595,7 @@ fn main() { let foo_test = fo<|>o(); }
fn hover_shows_fn_signature_on_fn_name() {
check(
r#"
pub fn foo<|>(a: u32, b: u32) -> u32 {}
pub fn foo$0(a: u32, b: u32) -> u32 {}
fn main() { }
"#,
@ -623,7 +623,7 @@ fn main() { }
/// #
/// foo(Path::new("hello, world!"))
/// ```
pub fn foo<|>(_: &Path) {}
pub fn foo$0(_: &Path) {}
fn main() { }
"#,
@ -656,7 +656,7 @@ fn main() { }
check(
r##"
#[doc = r#"Raw string doc attr"#]
pub fn foo<|>(_: &Path) {}
pub fn foo$0(_: &Path) {}
fn main() { }
"##,
@ -686,7 +686,7 @@ fn main() { }
struct Foo { field_a: u32 }
fn main() {
let foo = Foo { field_a<|>: 0, };
let foo = Foo { field_a$0: 0, };
}
"#,
expect![[r#"
@ -705,7 +705,7 @@ fn main() {
// Hovering over the field in the definition
check(
r#"
struct Foo { field_a<|>: u32 }
struct Foo { field_a$0: u32 }
fn main() {
let foo = Foo { field_a: 0 };
@ -728,7 +728,7 @@ fn main() {
#[test]
fn hover_const_static() {
check(
r#"const foo<|>: u32 = 123;"#,
r#"const foo$0: u32 = 123;"#,
expect![[r#"
*foo*
@ -742,7 +742,7 @@ fn main() {
"#]],
);
check(
r#"static foo<|>: u32 = 456;"#,
r#"static foo$0: u32 = 456;"#,
expect![[r#"
*foo*
@ -764,7 +764,7 @@ fn main() {
struct Test<K, T = u8> { k: K, t: T }
fn main() {
let zz<|> = Test { t: 23u8, k: 33 };
let zz$0 = Test { t: 23u8, k: 33 };
}"#,
expect![[r#"
*zz*
@ -783,7 +783,7 @@ fn main() {
enum Option<T> { Some(T) }
use Option::Some;
fn main() { So<|>me(12); }
fn main() { So$0me(12); }
"#,
expect![[r#"
*Some*
@ -803,7 +803,7 @@ fn main() { So<|>me(12); }
enum Option<T> { Some(T) }
use Option::Some;
fn main() { let b<|>ar = Some(12); }
fn main() { let b$0ar = Some(12); }
"#,
expect![[r#"
*bar*
@ -821,7 +821,7 @@ fn main() { let b<|>ar = Some(12); }
r#"
enum Option<T> {
/// The None variant
Non<|>e
Non$0e
}
"#,
expect![[r#"
@ -848,7 +848,7 @@ enum Option<T> {
Some(T)
}
fn main() {
let s = Option::Som<|>e(12);
let s = Option::Som$0e(12);
}
"#,
expect![[r#"
@ -872,7 +872,7 @@ fn main() {
#[test]
fn hover_for_local_variable() {
check(
r#"fn func(foo: i32) { fo<|>o; }"#,
r#"fn func(foo: i32) { fo$0o; }"#,
expect![[r#"
*foo*
@ -886,7 +886,7 @@ fn main() {
#[test]
fn hover_for_local_variable_pat() {
check(
r#"fn func(fo<|>o: i32) {}"#,
r#"fn func(fo$0o: i32) {}"#,
expect![[r#"
*foo*
@ -900,7 +900,7 @@ fn main() {
#[test]
fn hover_local_var_edge() {
check(
r#"fn func(foo: i32) { if true { <|>foo; }; }"#,
r#"fn func(foo: i32) { if true { $0foo; }; }"#,
expect![[r#"
*foo*
@ -914,7 +914,7 @@ fn main() {
#[test]
fn hover_for_param_edge() {
check(
r#"fn func(<|>foo: i32) {}"#,
r#"fn func($0foo: i32) {}"#,
expect![[r#"
*foo*
@ -934,7 +934,7 @@ fn main() {
trait DerefMut {
type Target: ?Sized;
}
fn f(_x<|>: impl Deref<Target=u8> + DerefMut<Target=u8>) {}"#,
fn f(_x$0: impl Deref<Target=u8> + DerefMut<Target=u8>) {}"#,
expect![[r#"
*_x*
@ -955,7 +955,7 @@ impl Thing {
fn new() -> Thing { Thing { x: 0 } }
}
fn main() { let foo_<|>test = Thing::new(); }
fn main() { let foo_$0test = Thing::new(); }
"#,
expect![[r#"
*foo_test*
@ -979,7 +979,7 @@ mod wrapper {
}
}
fn main() { let foo_test = wrapper::Thing::new<|>(); }
fn main() { let foo_test = wrapper::Thing::new$0(); }
"#,
expect![[r#"
*new*
@ -1006,7 +1006,7 @@ impl X {
fn main() {
match 1 {
X::C<|> => {},
X::C$0 => {},
2 => {},
_ => {}
};
@ -1032,7 +1032,7 @@ fn main() {
r#"
struct Thing { x: u32 }
impl Thing {
fn new() -> Self { Self<|> { x: 0 } }
fn new() -> Self { Self$0 { x: 0 } }
}
"#,
expect![[r#"
@ -1051,7 +1051,7 @@ impl Thing {
r#"
struct Thing { x: u32 }
impl Thing {
fn new() -> Self<|> { Self { x: 0 } }
fn new() -> Self$0 { Self { x: 0 } }
}
"#,
expect![[r#"
@ -1070,7 +1070,7 @@ impl Thing {
r#"
enum Thing { A }
impl Thing {
pub fn new() -> Self<|> { Thing::A }
pub fn new() -> Self$0 { Thing::A }
}
"#,
expect![[r#"
@ -1089,7 +1089,7 @@ impl Thing {
r#"
enum Thing { A }
impl Thing {
pub fn thing(a: Self<|>) {}
pub fn thing(a: Self$0) {}
}
"#,
expect![[r#"
@ -1114,7 +1114,7 @@ fn x() {}
fn y() {
let x = 0i32;
x<|>;
x$0;
}
"#,
expect![[r#"
@ -1133,7 +1133,7 @@ fn y() {
r#"
macro_rules! foo { () => {} }
fn f() { fo<|>o!(); }
fn f() { fo$0o!(); }
"#,
expect![[r#"
*foo*
@ -1152,7 +1152,7 @@ fn f() { fo<|>o!(); }
#[test]
fn test_hover_tuple_field() {
check(
r#"struct TS(String, i32<|>);"#,
r#"struct TS(String, i32$0);"#,
expect![[r#"
*i32*
@ -1170,7 +1170,7 @@ fn f() { fo<|>o!(); }
macro_rules! id { ($($tt:tt)*) => { $($tt)* } }
fn foo() {}
id! {
fn bar() { fo<|>o(); }
fn bar() { fo$0o(); }
}
"#,
expect![[r#"
@ -1192,7 +1192,7 @@ id! {
check(
r#"
macro_rules! id { ($($tt:tt)*) => { $($tt)* } }
fn foo(bar:u32) { let a = id!(ba<|>r); }
fn foo(bar:u32) { let a = id!(ba$0r); }
"#,
expect![[r#"
*bar*
@ -1210,7 +1210,7 @@ fn foo(bar:u32) { let a = id!(ba<|>r); }
r#"
macro_rules! id_deep { ($($tt:tt)*) => { $($tt)* } }
macro_rules! id { ($($tt:tt)*) => { id_deep!($($tt)*) } }
fn foo(bar:u32) { let a = id!(ba<|>r); }
fn foo(bar:u32) { let a = id!(ba$0r); }
"#,
expect![[r#"
*bar*
@ -1229,7 +1229,7 @@ fn foo(bar:u32) { let a = id!(ba<|>r); }
macro_rules! id_deep { ($($tt:tt)*) => { $($tt)* } }
macro_rules! id { ($($tt:tt)*) => { id_deep!($($tt)*) } }
fn bar() -> u32 { 0 }
fn foo() { let a = id!([0u32, bar(<|>)] ); }
fn foo() { let a = id!([0u32, bar($0)] ); }
"#,
expect![[r#"
*bar()*
@ -1247,7 +1247,7 @@ fn foo() { let a = id!([0u32, bar(<|>)] ); }
macro_rules! arr { ($($tt:tt)*) => { [$($tt)*)] } }
fn foo() {
let mastered_for_itunes = "";
let _ = arr!("Tr<|>acks", &mastered_for_itunes);
let _ = arr!("Tr$0acks", &mastered_for_itunes);
}
"#,
expect![[r#"
@ -1268,7 +1268,7 @@ macro_rules! assert {}
fn bar() -> bool { true }
fn foo() {
assert!(ba<|>r());
assert!(ba$0r());
}
"#,
expect![[r#"
@ -1293,7 +1293,7 @@ fn foo() {
macro_rules! format {}
fn foo() {
format!("hel<|>lo {}", 0);
format!("hel$0lo {}", 0);
}
"#,
);
@ -1306,7 +1306,7 @@ fn foo() {
/// <- `\u{3000}` here
fn foo() { }
fn bar() { fo<|>o(); }
fn bar() { fo$0o(); }
",
expect![[r#"
*foo*
@ -1329,7 +1329,7 @@ fn bar() { fo<|>o(); }
#[test]
fn test_hover_function_show_qualifiers() {
check(
r#"async fn foo<|>() {}"#,
r#"async fn foo$0() {}"#,
expect![[r#"
*foo*
@ -1343,7 +1343,7 @@ fn bar() { fo<|>o(); }
"#]],
);
check(
r#"pub const unsafe fn foo<|>() {}"#,
r#"pub const unsafe fn foo$0() {}"#,
expect![[r#"
*foo*
@ -1357,7 +1357,7 @@ fn bar() { fo<|>o(); }
"#]],
);
check(
r#"pub(crate) async unsafe extern "C" fn foo<|>() {}"#,
r#"pub(crate) async unsafe extern "C" fn foo$0() {}"#,
expect![[r#"
*foo*
@ -1375,7 +1375,7 @@ fn bar() { fo<|>o(); }
#[test]
fn test_hover_trait_show_qualifiers() {
check_actions(
r"unsafe trait foo<|>() {}",
r"unsafe trait foo$0() {}",
expect![[r#"
[
Implementation(
@ -1396,7 +1396,7 @@ fn bar() { fo<|>o(); }
check(
r#"
//- /main.rs crate:main deps:std
extern crate st<|>d;
extern crate st$0d;
//- /std/lib.rs crate:std
//! Standard library for this test
//!
@ -1414,7 +1414,7 @@ extern crate st<|>d;
check(
r#"
//- /main.rs crate:main deps:std
extern crate std as ab<|>c;
extern crate std as ab$0c;
//- /std/lib.rs crate:std
//! Standard library for this test
//!
@ -1435,7 +1435,7 @@ extern crate std as ab<|>c;
fn test_hover_mod_with_same_name_as_function() {
check(
r#"
use self::m<|>y::Bar;
use self::m$0y::Bar;
mod my { pub struct Bar; }
fn my() {}
@ -1461,7 +1461,7 @@ fn my() {}
/// bar docs
struct Bar;
fn foo() { let bar = Ba<|>r; }
fn foo() { let bar = Ba$0r; }
"#,
expect![[r#"
*Bar*
@ -1488,7 +1488,7 @@ fn foo() { let bar = Ba<|>r; }
#[doc = "bar docs"]
struct Bar;
fn foo() { let bar = Ba<|>r; }
fn foo() { let bar = Ba$0r; }
"#,
expect![[r#"
*Bar*
@ -1517,7 +1517,7 @@ fn foo() { let bar = Ba<|>r; }
#[doc = "bar docs 2"]
struct Bar;
fn foo() { let bar = Ba<|>r; }
fn foo() { let bar = Ba$0r; }
"#,
expect![[r#"
*Bar*
@ -1545,7 +1545,7 @@ fn foo() { let bar = Ba<|>r; }
r#"
pub struct Foo;
/// [Foo](struct.Foo.html)
pub struct B<|>ar
pub struct B$0ar
"#,
expect![[r#"
*Bar*
@ -1571,7 +1571,7 @@ pub struct B<|>ar
r#"
pub struct Foo;
/// [struct Foo](struct.Foo.html)
pub struct B<|>ar
pub struct B$0ar
"#,
expect![[r#"
*Bar*
@ -1599,7 +1599,7 @@ pub struct B<|>ar
pub struct Foo;
pub struct Bar {
/// [Foo](struct.Foo.html)
fie<|>ld: ()
fie$0ld: ()
}
"#,
expect![[r#"
@ -1628,7 +1628,7 @@ pub mod foo {
pub struct Foo;
}
/// [Foo](foo::Foo)
pub struct B<|>ar
pub struct B$0ar
"#,
expect![[r#"
*Bar*
@ -1658,7 +1658,7 @@ pub mod foo {
pub struct Foo;
}
/// [Foo](foo::Foo)
pub struct B<|>ar
pub struct B$0ar
"#,
expect![[r#"
*Bar*
@ -1684,7 +1684,7 @@ pub struct B<|>ar
r#"
pub struct Foo;
/// [Foo]
pub struct B<|>ar
pub struct B$0ar
"#,
expect![[r#"
*Bar*
@ -1710,7 +1710,7 @@ pub struct B<|>ar
r#"
pub struct Foo;
/// [`Foo`]
pub struct B<|>ar
pub struct B$0ar
"#,
expect![[r#"
*Bar*
@ -1737,7 +1737,7 @@ pub struct B<|>ar
pub struct Foo;
fn Foo() {}
/// [Foo()]
pub struct B<|>ar
pub struct B$0ar
"#,
expect![[r#"
*Bar*
@ -1763,7 +1763,7 @@ pub struct B<|>ar
r#"
pub struct Foo;
/// [`struct Foo`]
pub struct B<|>ar
pub struct B$0ar
"#,
expect![[r#"
*Bar*
@ -1789,7 +1789,7 @@ pub struct B<|>ar
r#"
pub struct Foo;
/// [`struct@Foo`]
pub struct B<|>ar
pub struct B$0ar
"#,
expect![[r#"
*Bar*
@ -1817,7 +1817,7 @@ pub struct Foo;
/// [my Foo][foo]
///
/// [foo]: Foo
pub struct B<|>ar
pub struct B$0ar
"#,
expect![[r#"
*Bar*
@ -1843,7 +1843,7 @@ pub struct B<|>ar
r#"
pub struct Foo;
/// [external](https://www.google.com)
pub struct B<|>ar
pub struct B$0ar
"#,
expect![[r#"
*Bar*
@ -1870,7 +1870,7 @@ pub struct B<|>ar
r#"
pub struct Foo;
/// [baz](Baz)
pub struct B<|>ar
pub struct B$0ar
"#,
expect![[r#"
*Bar*
@ -1896,7 +1896,7 @@ pub struct B<|>ar
r#"
enum E {
/// [E]
V<|> { field: i32 }
V$0 { field: i32 }
}
"#,
expect![[r#"
@ -1923,7 +1923,7 @@ enum E {
r#"
struct S {
/// [`S`]
field<|>: i32
field$0: i32
}
"#,
expect![[r#"
@ -1969,7 +1969,7 @@ struct S {
///
/// [`Result`]: ../../std/result/enum.Result.html
/// [^example]: https://www.example.com/
pub fn fo<|>o() {}
pub fn fo$0o() {}
"#,
expect![[r#"
*foo*
@ -2026,7 +2026,7 @@ macro_rules! bar {
bar!();
fn foo() { let bar = Bar; bar.fo<|>o(); }
fn foo() { let bar = Bar; bar.fo$0o(); }
"#,
expect![[r#"
*foo*
@ -2064,7 +2064,7 @@ macro_rules! bar {
bar!();
fn foo() { let bar = Bar; bar.fo<|>o(); }
fn foo() { let bar = Bar; bar.fo$0o(); }
"#,
expect![[r#"
*foo*
@ -2087,7 +2087,7 @@ fn foo() { let bar = Bar; bar.fo<|>o(); }
#[test]
fn test_hover_trait_has_impl_action() {
check_actions(
r#"trait foo<|>() {}"#,
r#"trait foo$0() {}"#,
expect![[r#"
[
Implementation(
@ -2106,7 +2106,7 @@ fn foo() { let bar = Bar; bar.fo<|>o(); }
#[test]
fn test_hover_struct_has_impl_action() {
check_actions(
r"struct foo<|>() {}",
r"struct foo$0() {}",
expect![[r#"
[
Implementation(
@ -2125,7 +2125,7 @@ fn foo() { let bar = Bar; bar.fo<|>o(); }
#[test]
fn test_hover_union_has_impl_action() {
check_actions(
r#"union foo<|>() {}"#,
r#"union foo$0() {}"#,
expect![[r#"
[
Implementation(
@ -2144,7 +2144,7 @@ fn foo() { let bar = Bar; bar.fo<|>o(); }
#[test]
fn test_hover_enum_has_impl_action() {
check_actions(
r"enum foo<|>() { A, B }",
r"enum foo$0() { A, B }",
expect![[r#"
[
Implementation(
@ -2163,7 +2163,7 @@ fn foo() { let bar = Bar; bar.fo<|>o(); }
#[test]
fn test_hover_self_has_impl_action() {
check_actions(
r#"struct foo where Self<|>:;"#,
r#"struct foo where Self$0:;"#,
expect![[r#"
[
Implementation(
@ -2184,7 +2184,7 @@ fn foo() { let bar = Bar; bar.fo<|>o(); }
check_actions(
r#"
#[test]
fn foo_<|>test() {}
fn foo_$0test() {}
"#,
expect![[r#"
[
@ -2219,7 +2219,7 @@ fn foo_<|>test() {}
fn test_hover_test_mod_has_action() {
check_actions(
r#"
mod tests<|> {
mod tests$0 {
#[test]
fn foo_test() {}
}
@ -2254,7 +2254,7 @@ mod tests<|> {
r#"
struct S{ f1: u32 }
fn main() { let s<|>t = S{ f1:0 }; }
fn main() { let s$0t = S{ f1:0 }; }
"#,
expect![[r#"
[
@ -2287,7 +2287,7 @@ fn main() { let s<|>t = S{ f1:0 }; }
struct Arg(u32);
struct S<T>{ f1: T }
fn main() { let s<|>t = S{ f1:Arg(0) }; }
fn main() { let s$0t = S{ f1:Arg(0) }; }
"#,
expect![[r#"
[
@ -2333,7 +2333,7 @@ fn main() { let s<|>t = S{ f1:Arg(0) }; }
struct Arg(u32);
struct S<T>{ f1: T }
fn main() { let s<|>t = S{ f1: S{ f1: Arg(0) } }; }
fn main() { let s$0t = S{ f1: S{ f1: Arg(0) } }; }
"#,
expect![[r#"
[
@ -2382,7 +2382,7 @@ mod M {
pub struct C(u32);
}
fn main() { let s<|>t = (A(1), B(2), M::C(3) ); }
fn main() { let s$0t = (A(1), B(2), M::C(3) ); }
"#,
expect![[r#"
[
@ -2441,7 +2441,7 @@ fn main() { let s<|>t = (A(1), B(2), M::C(3) ); }
trait Foo {}
fn foo() -> impl Foo {}
fn main() { let s<|>t = foo(); }
fn main() { let s$0t = foo(); }
"#,
expect![[r#"
[
@ -2475,7 +2475,7 @@ trait Foo<T> {}
struct S;
fn foo() -> impl Foo<S> {}
fn main() { let s<|>t = foo(); }
fn main() { let s$0t = foo(); }
"#,
expect![[r#"
[
@ -2522,7 +2522,7 @@ trait Foo {}
trait Bar {}
fn foo() -> impl Foo + Bar {}
fn main() { let s<|>t = foo(); }
fn main() { let s$0t = foo(); }
"#,
expect![[r#"
[
@ -2572,7 +2572,7 @@ struct S2 {}
fn foo() -> impl Foo<S1> + Bar<S2> {}
fn main() { let s<|>t = foo(); }
fn main() { let s$0t = foo(); }
"#,
expect![[r#"
[
@ -2642,7 +2642,7 @@ fn main() { let s<|>t = foo(); }
check_actions(
r#"
trait Foo {}
fn foo(ar<|>g: &impl Foo) {}
fn foo(ar$0g: &impl Foo) {}
"#,
expect![[r#"
[
@ -2676,7 +2676,7 @@ trait Foo {}
trait Bar<T> {}
struct S{}
fn foo(ar<|>g: &impl Foo + Bar<S>) {}
fn foo(ar$0g: &impl Foo + Bar<S>) {}
"#,
expect![[r#"
[
@ -2734,7 +2734,7 @@ fn foo(ar<|>g: &impl Foo + Bar<S>) {}
r#"
struct S;
fn foo() {
let fo<|>o = async { S };
let fo$0o = async { S };
}
#[prelude_import] use future::*;
@ -2786,7 +2786,7 @@ mod future {
r#"
trait Foo<T> {}
struct S {}
fn foo(ar<|>g: &impl Foo<S>) {}
fn foo(ar$0g: &impl Foo<S>) {}
"#,
expect![[r#"
[
@ -2836,7 +2836,7 @@ impl Foo for S {}
struct B<T>{}
fn foo() -> B<dyn Foo> {}
fn main() { let s<|>t = foo(); }
fn main() { let s$0t = foo(); }
"#,
expect![[r#"
[
@ -2880,7 +2880,7 @@ fn main() { let s<|>t = foo(); }
check_actions(
r#"
trait Foo {}
fn foo(ar<|>g: &dyn Foo) {}
fn foo(ar$0g: &dyn Foo) {}
"#,
expect![[r#"
[
@ -2912,7 +2912,7 @@ fn foo(ar<|>g: &dyn Foo) {}
r#"
trait Foo<T> {}
struct S {}
fn foo(ar<|>g: &dyn Foo<S>) {}
fn foo(ar$0g: &dyn Foo<S>) {}
"#,
expect![[r#"
[
@ -2960,7 +2960,7 @@ trait DynTrait<T> {}
struct B<T> {}
struct S {}
fn foo(a<|>rg: &impl ImplTrait<B<dyn DynTrait<B<S>>>>) {}
fn foo(a$0rg: &impl ImplTrait<B<dyn DynTrait<B<S>>>>) {}
"#,
expect![[r#"
[
@ -3041,7 +3041,7 @@ impl Foo for S { type Item = Bar; }
fn test() -> impl Foo { S {} }
fn main() { let s<|>t = test().get(); }
fn main() { let s$0t = test().get(); }
"#,
expect![[r#"
[
@ -3074,7 +3074,7 @@ fn main() { let s<|>t = test().get(); }
struct Bar;
struct Foo<const BAR: Bar>;
impl<const BAR: Bar> Foo<BAR<|>> {}
impl<const BAR: Bar> Foo<BAR$0> {}
"#,
expect![[r#"
[
@ -3106,7 +3106,7 @@ impl<const BAR: Bar> Foo<BAR<|>> {}
r#"
trait Foo {}
fn foo<T: Foo>(t: T<|>){}
fn foo<T: Foo>(t: T$0){}
"#,
expect![[r#"
[
@ -3146,7 +3146,7 @@ pub mod wrapper {
}
//- /main.rs crate:main deps:name-with-dashes
fn main() { let foo_test = name_with_dashes::wrapper::Thing::new<|>(); }
fn main() { let foo_test = name_with_dashes::wrapper::Thing::new$0(); }
"#,
expect![[r#"
*new*
@ -3172,7 +3172,7 @@ struct S {
fn main() {
let s = S { f: 0 };
let S { f<|> } = &s;
let S { f$0 } = &s;
}
"#,
expect![[r#"
@ -3191,7 +3191,7 @@ fn main() {
r#"
struct Foo {}
impl Foo {
fn bar(&sel<|>f) {}
fn bar(&sel$0f) {}
}
"#,
expect![[r#"
@ -3210,7 +3210,7 @@ impl Foo {
struct Arc<T>(T);
struct Foo {}
impl Foo {
fn bar(sel<|>f: Arc<Foo>) {}
fn bar(sel$0f: Arc<Foo>) {}
}
"#,
expect![[r#"
@ -3227,7 +3227,7 @@ impl Foo {
check(
r#"
/// Be quick;
mod Foo<|> {
mod Foo$0 {
//! time is mana
/// This comment belongs to the function
@ -3258,7 +3258,7 @@ mod Foo<|> {
check(
r#"
#[doc = "Be quick;"]
mod Foo<|> {
mod Foo$0 {
#![doc = "time is mana"]
#[doc = "This comment belongs to the function"]
@ -3289,7 +3289,7 @@ mod Foo<|> {
check_hover_no_result(
r#"
fn no_hover() {
// no<|>hover
// no$0hover
}
"#,
);
@ -3300,7 +3300,7 @@ fn no_hover() {
check(
r#"
fn foo() {
'label<|>: loop {}
'label$0: loop {}
}
"#,
expect![[r#"
@ -3316,7 +3316,7 @@ fn foo() {
#[test]
fn hover_lifetime() {
check(
r#"fn foo<'lifetime>(_: &'lifetime<|> ()) {}"#,
r#"fn foo<'lifetime>(_: &'lifetime$0 ()) {}"#,
expect![[r#"
*'lifetime*
@ -3335,7 +3335,7 @@ struct Foo<T>(T);
trait Copy {}
trait Clone {}
trait Sized {}
impl<T: Copy + Clone> Foo<T<|>> where T: Sized {}
impl<T: Copy + Clone> Foo<T$0> where T: Sized {}
"#,
expect![[r#"
*T*
@ -3348,7 +3348,7 @@ impl<T: Copy + Clone> Foo<T<|>> where T: Sized {}
check(
r#"
struct Foo<T>(T);
impl<T> Foo<T<|>> {}
impl<T> Foo<T$0> {}
"#,
expect![[r#"
*T*
@ -3362,7 +3362,7 @@ impl<T> Foo<T<|>> {}
check(
r#"
struct Foo<T>(T);
impl<T: 'static> Foo<T<|>> {}
impl<T: 'static> Foo<T$0> {}
"#,
expect![[r#"
*T*
@ -3379,7 +3379,7 @@ impl<T: 'static> Foo<T<|>> {}
check(
r#"
struct Foo<const LEN: usize>;
impl<const LEN: usize> Foo<LEN<|>> {}
impl<const LEN: usize> Foo<LEN$0> {}
"#,
expect![[r#"
*LEN*

View file

@ -104,7 +104,7 @@ fn remove_newline(edit: &mut TextEditBuilder, token: &SyntaxToken, offset: TextS
// Special case that turns something like:
//
// ```
// my_function({<|>
// my_function({$0
// <some-expr>
// })
// ```
@ -116,7 +116,7 @@ fn remove_newline(edit: &mut TextEditBuilder, token: &SyntaxToken, offset: TextS
// ditto for
//
// ```
// use foo::{<|>
// use foo::{$0
// bar
// };
// ```
@ -222,13 +222,13 @@ mod tests {
check_join_lines(
r"
fn foo() {
<|>foo(1,
$0foo(1,
)
}
",
r"
fn foo() {
<|>foo(1)
$0foo(1)
}
",
);
@ -239,14 +239,14 @@ fn foo() {
check_join_lines(
r"
pub fn reparse(&self, edit: &AtomTextEdit) -> File {
<|>self.incremental_reparse(edit).unwrap_or_else(|| {
$0self.incremental_reparse(edit).unwrap_or_else(|| {
self.full_reparse(edit)
})
}
",
r"
pub fn reparse(&self, edit: &AtomTextEdit) -> File {
<|>self.incremental_reparse(edit).unwrap_or_else(|| self.full_reparse(edit))
$0self.incremental_reparse(edit).unwrap_or_else(|| self.full_reparse(edit))
}
",
);
@ -257,13 +257,13 @@ pub fn reparse(&self, edit: &AtomTextEdit) -> File {
check_join_lines(
r"
fn foo() {
foo(<|>{
foo($0{
92
})
}",
r"
fn foo() {
foo(<|>92)
foo($092)
}",
);
}
@ -274,7 +274,7 @@ fn foo() {
fn foo() {
loop {
match x {
92 => <|>{
92 => $0{
continue;
}
}
@ -285,7 +285,7 @@ fn foo() {
fn foo() {
loop {
match x {
92 => <|>continue,
92 => $0continue,
}
}
}
@ -299,7 +299,7 @@ fn foo() {
r"
fn foo(e: Result<U, V>) {
match e {
Ok(u) => <|>{
Ok(u) => $0{
u.foo()
}
Err(v) => v,
@ -308,7 +308,7 @@ fn foo(e: Result<U, V>) {
r"
fn foo(e: Result<U, V>) {
match e {
Ok(u) => <|>u.foo(),
Ok(u) => $0u.foo(),
Err(v) => v,
}
}",
@ -321,7 +321,7 @@ fn foo(e: Result<U, V>) {
r"
fn foo() {
match ty {
<|> Some(ty) => {
$0 Some(ty) => {
match ty {
_ => false,
}
@ -333,7 +333,7 @@ fn foo() {
r"
fn foo() {
match ty {
<|> Some(ty) => match ty {
$0 Some(ty) => match ty {
_ => false,
},
_ => true,
@ -350,7 +350,7 @@ fn foo() {
r"
fn foo(e: Result<U, V>) {
match e {
Ok(u) => <|>{
Ok(u) => $0{
u.foo()
},
Err(v) => v,
@ -359,7 +359,7 @@ fn foo(e: Result<U, V>) {
r"
fn foo(e: Result<U, V>) {
match e {
Ok(u) => <|>u.foo(),
Ok(u) => $0u.foo(),
Err(v) => v,
}
}",
@ -370,7 +370,7 @@ fn foo(e: Result<U, V>) {
r"
fn foo(e: Result<U, V>) {
match e {
Ok(u) => <|>{
Ok(u) => $0{
u.foo()
} ,
Err(v) => v,
@ -379,7 +379,7 @@ fn foo(e: Result<U, V>) {
r"
fn foo(e: Result<U, V>) {
match e {
Ok(u) => <|>u.foo() ,
Ok(u) => $0u.foo() ,
Err(v) => v,
}
}",
@ -390,7 +390,7 @@ fn foo(e: Result<U, V>) {
r"
fn foo(e: Result<U, V>) {
match e {
Ok(u) => <|>{
Ok(u) => $0{
u.foo()
}
,
@ -400,7 +400,7 @@ fn foo(e: Result<U, V>) {
r"
fn foo(e: Result<U, V>) {
match e {
Ok(u) => <|>u.foo()
Ok(u) => $0u.foo()
,
Err(v) => v,
}
@ -414,13 +414,13 @@ fn foo(e: Result<U, V>) {
check_join_lines(
r"
fn foo() {
let x = (<|>{
let x = ($0{
4
},);
}",
r"
fn foo() {
let x = (<|>4,);
let x = ($04,);
}",
);
@ -428,13 +428,13 @@ fn foo() {
check_join_lines(
r"
fn foo() {
let x = (<|>{
let x = ($0{
4
} ,);
}",
r"
fn foo() {
let x = (<|>4 ,);
let x = ($04 ,);
}",
);
@ -442,14 +442,14 @@ fn foo() {
check_join_lines(
r"
fn foo() {
let x = (<|>{
let x = ($0{
4
}
,);
}",
r"
fn foo() {
let x = (<|>4
let x = ($04
,);
}",
);
@ -460,11 +460,11 @@ fn foo() {
// No space after the '{'
check_join_lines(
r"
<|>use syntax::{
$0use syntax::{
TextSize, TextRange,
};",
r"
<|>use syntax::{TextSize, TextRange,
$0use syntax::{TextSize, TextRange,
};",
);
}
@ -475,11 +475,11 @@ fn foo() {
check_join_lines(
r"
use syntax::{
<|> TextSize, TextRange
$0 TextSize, TextRange
};",
r"
use syntax::{
<|> TextSize, TextRange};",
$0 TextSize, TextRange};",
);
}
@ -489,11 +489,11 @@ use syntax::{
check_join_lines(
r"
use syntax::{
<|> TextSize, TextRange,
$0 TextSize, TextRange,
};",
r"
use syntax::{
<|> TextSize, TextRange};",
$0 TextSize, TextRange};",
);
}
@ -502,14 +502,14 @@ use syntax::{
check_join_lines(
r"
use syntax::{
algo::<|>{
algo::$0{
find_token_at_offset,
},
ast,
};",
r"
use syntax::{
algo::<|>find_token_at_offset,
algo::$0find_token_at_offset,
ast,
};",
);
@ -520,13 +520,13 @@ use syntax::{
check_join_lines(
r"
fn foo() {
// Hello<|>
// Hello$0
// world!
}
",
r"
fn foo() {
// Hello<|> world!
// Hello$0 world!
}
",
);
@ -537,13 +537,13 @@ fn foo() {
check_join_lines(
r"
fn foo() {
/// Hello<|>
/// Hello$0
/// world!
}
",
r"
fn foo() {
/// Hello<|> world!
/// Hello$0 world!
}
",
);
@ -554,13 +554,13 @@ fn foo() {
check_join_lines(
r"
fn foo() {
//! Hello<|>
//! Hello$0
//! world!
}
",
r"
fn foo() {
//! Hello<|> world!
//! Hello$0 world!
}
",
);
@ -571,13 +571,13 @@ fn foo() {
check_join_lines(
r"
fn foo() {
// Hello<|>
// Hello$0
/* world! */
}
",
r"
fn foo() {
// Hello<|> world! */
// Hello$0 world! */
}
",
);
@ -588,7 +588,7 @@ fn foo() {
check_join_lines(
r"
fn foo() {
// The<|>
// The$0
/* quick
brown
fox! */
@ -596,7 +596,7 @@ fn foo() {
",
r"
fn foo() {
// The<|> quick
// The$0 quick
brown
fox! */
}
@ -621,10 +621,10 @@ fn foo() {
check_join_lines_sel(
r"
fn foo() {
<|>foo(1,
$0foo(1,
2,
3,
<|>)
$0)
}
",
r"
@ -639,9 +639,9 @@ fn foo() {
fn test_join_lines_selection_struct() {
check_join_lines_sel(
r"
struct Foo <|>{
struct Foo $0{
f: u32,
}<|>
}$0
",
r"
struct Foo { f: u32 }
@ -654,9 +654,9 @@ struct Foo { f: u32 }
check_join_lines_sel(
r"
fn foo() {
join(<|>type_params.type_params()
join($0type_params.type_params()
.filter_map(|it| it.name())
.map(|it| it.text())<|>)
.map(|it| it.text())$0)
}",
r"
fn foo() {
@ -671,9 +671,9 @@ fn foo() {
r"
pub fn handle_find_matching_brace() {
params.offsets
.map(|offset| <|>{
.map(|offset| $0{
world.analysis().matching_brace(&file, offset).unwrap_or(offset)
}<|>)
}$0)
.collect();
}",
r"
@ -691,7 +691,7 @@ pub fn handle_find_matching_brace() {
r"
fn main() {
let _ = {
// <|>foo
// $0foo
// bar
92
};
@ -700,7 +700,7 @@ fn main() {
r"
fn main() {
let _ = {
// <|>foo bar
// $0foo bar
92
};
}
@ -712,12 +712,12 @@ fn main() {
fn join_lines_mandatory_blocks_block() {
check_join_lines(
r"
<|>fn foo() {
$0fn foo() {
92
}
",
r"
<|>fn foo() { 92
$0fn foo() { 92
}
",
);
@ -725,14 +725,14 @@ fn main() {
check_join_lines(
r"
fn foo() {
<|>if true {
$0if true {
92
}
}
",
r"
fn foo() {
<|>if true { 92
$0if true { 92
}
}
",
@ -741,14 +741,14 @@ fn foo() {
check_join_lines(
r"
fn foo() {
<|>loop {
$0loop {
92
}
}
",
r"
fn foo() {
<|>loop { 92
$0loop { 92
}
}
",
@ -757,14 +757,14 @@ fn foo() {
check_join_lines(
r"
fn foo() {
<|>unsafe {
$0unsafe {
92
}
}
",
r"
fn foo() {
<|>unsafe { 92
$0unsafe { 92
}
}
",

View file

@ -58,15 +58,15 @@ mod tests {
assert_eq_text!(after, &actual);
}
do_check("struct Foo { a: i32, }<|>", "struct Foo <|>{ a: i32, }");
do_check("fn main() { |x: i32|<|> x * 2;}", "fn main() { <|>|x: i32| x * 2;}");
do_check("fn main() { <|>|x: i32| x * 2;}", "fn main() { |x: i32<|>| x * 2;}");
do_check("struct Foo { a: i32, }$0", "struct Foo $0{ a: i32, }");
do_check("fn main() { |x: i32|$0 x * 2;}", "fn main() { $0|x: i32| x * 2;}");
do_check("fn main() { $0|x: i32| x * 2;}", "fn main() { |x: i32$0| x * 2;}");
{
mark::check!(pipes_not_braces);
do_check(
"fn main() { match 92 { 1 | 2 |<|> 3 => 92 } }",
"fn main() { match 92 { 1 | 2 |<|> 3 => 92 } }",
"fn main() { match 92 { 1 | 2 |$0 3 => 92 } }",
"fn main() { match 92 { 1 | 2 |$0 3 => 92 } }",
);
}
}

View file

@ -74,7 +74,7 @@ mod tests {
//- /lib.rs
mod foo;
//- /foo.rs
<|>// empty
$0// empty
",
);
let nav = analysis.parent_module(pos).unwrap().pop().unwrap();
@ -90,7 +90,7 @@ mod tests {
mod foo;
//- /foo.rs
mod <|>bar;
mod $0bar;
//- /foo/bar.rs
// empty
@ -107,7 +107,7 @@ mod tests {
//- /lib.rs
mod foo {
mod bar {
mod baz { <|> }
mod baz { $0 }
}
}
",
@ -123,7 +123,7 @@ mod tests {
//- /main.rs
mod foo;
//- /foo.rs
<|>
$0
"#,
);
assert_eq!(analysis.crate_for(file_id).unwrap().len(), 1);

View file

@ -331,7 +331,7 @@ mod tests {
fn test_struct_literal_after_space() {
check(
r#"
struct Foo <|>{
struct Foo $0{
a: i32,
}
impl Foo {
@ -354,7 +354,7 @@ fn main() {
fn test_struct_literal_before_space() {
check(
r#"
struct Foo<|> {}
struct Foo$0 {}
fn main() {
let f: Foo;
f = Foo {};
@ -373,7 +373,7 @@ struct Foo<|> {}
fn test_struct_literal_with_generic_type() {
check(
r#"
struct Foo<T> <|>{}
struct Foo<T> $0{}
fn main() {
let f: Foo::<i32>;
f = Foo {};
@ -391,7 +391,7 @@ struct Foo<T> <|>{}
fn test_struct_literal_for_tuple() {
check(
r#"
struct Foo<|>(i32);
struct Foo$0(i32);
fn main() {
let f: Foo;
@ -410,7 +410,7 @@ fn main() {
fn test_enum_after_space() {
check(
r#"
enum Foo <|>{
enum Foo $0{
A,
B,
}
@ -431,7 +431,7 @@ fn main() {
fn test_enum_before_space() {
check(
r#"
enum Foo<|> {
enum Foo$0 {
A,
B,
}
@ -453,7 +453,7 @@ fn main() {
fn test_enum_with_generic_type() {
check(
r#"
enum Foo<T> <|>{
enum Foo<T> $0{
A(T),
B,
}
@ -474,7 +474,7 @@ fn main() {
fn test_enum_for_tuple() {
check(
r#"
enum Foo<|>{
enum Foo$0{
A(i8),
B(i8),
}
@ -498,7 +498,7 @@ fn main() {
fn main() {
let mut i = 1;
let j = 1;
i = i<|> + j;
i = i$0 + j;
{
i = 0;
@ -522,7 +522,7 @@ fn main() {
check(
r#"
fn foo() {
let spam<|> = 92;
let spam$0 = 92;
spam + spam
}
fn bar() {
@ -543,7 +543,7 @@ fn bar() {
fn test_find_all_refs_for_param_inside() {
check(
r#"
fn foo(i : u32) -> u32 { i<|> }
fn foo(i : u32) -> u32 { i$0 }
"#,
expect![[r#"
i ValueParam FileId(0) 7..8 Other
@ -557,7 +557,7 @@ fn foo(i : u32) -> u32 { i<|> }
fn test_find_all_refs_for_fn_param() {
check(
r#"
fn foo(i<|> : u32) -> u32 { i }
fn foo(i$0 : u32) -> u32 { i }
"#,
expect![[r#"
i ValueParam FileId(0) 7..8 Other
@ -573,7 +573,7 @@ fn foo(i<|> : u32) -> u32 { i }
r#"
//- /lib.rs
struct Foo {
pub spam<|>: u32,
pub spam$0: u32,
}
fn main(s: Foo) {
@ -594,7 +594,7 @@ fn main(s: Foo) {
r#"
struct Foo;
impl Foo {
fn f<|>(&self) { }
fn f$0(&self) { }
}
"#,
expect![[r#"
@ -610,7 +610,7 @@ impl Foo {
r#"
enum Foo {
A,
B<|>,
B$0,
C,
}
"#,
@ -627,7 +627,7 @@ enum Foo {
r#"
enum Foo {
A,
B { field<|>: u8 },
B { field$0: u8 },
C,
}
"#,
@ -669,7 +669,7 @@ pub struct Bar {
}
fn f() {
let i = foo::Foo<|> { n: 5 };
let i = foo::Foo$0 { n: 5 };
}
"#,
expect![[r#"
@ -689,7 +689,7 @@ fn f() {
check(
r#"
//- /lib.rs
mod foo<|>;
mod foo$0;
use foo::Foo;
@ -726,7 +726,7 @@ fn f() {
}
//- /foo/some.rs
pub(super) struct Foo<|> {
pub(super) struct Foo$0 {
pub n: u32,
}
"#,
@ -746,7 +746,7 @@ pub(super) struct Foo<|> {
mod foo;
mod bar;
pub fn quux<|>() {}
pub fn quux$0() {}
//- /foo.rs
fn f() { super::quux(); }
@ -782,7 +782,7 @@ pub(super) struct Foo<|> {
check(
r#"
#[macro_export]
macro_rules! m1<|> { () => (()) }
macro_rules! m1$0 { () => (()) }
fn foo() {
m1();
@ -803,7 +803,7 @@ fn foo() {
check(
r#"
fn foo() {
let mut i<|> = 0;
let mut i$0 = 0;
i = i + 1;
}
"#,
@ -826,7 +826,7 @@ struct S {
fn foo() {
let mut s = S{f: 0};
s.f<|> = 0;
s.f$0 = 0;
}
"#,
expect![[r#"
@ -843,7 +843,7 @@ fn foo() {
check(
r#"
fn foo() {
let i<|>;
let i$0;
i = 1;
}
"#,
@ -863,7 +863,7 @@ mod foo {
pub struct Foo;
impl Foo {
pub fn new<|>() -> Foo { Foo }
pub fn new$0() -> Foo { Foo }
}
}
@ -886,7 +886,7 @@ fn main() {
//- /lib.rs
mod foo { mod bar; }
fn f<|>() {}
fn f$0() {}
//- /foo/bar.rs
use crate::f;
@ -907,7 +907,7 @@ fn g() { f(); }
check(
r#"
struct S {
field<|>: u8,
field$0: u8,
}
fn f(s: S) {
@ -930,7 +930,7 @@ fn f(s: S) {
r#"
enum En {
Variant {
field<|>: u8,
field$0: u8,
}
}
@ -955,7 +955,7 @@ fn f(e: En) {
mod m {
pub enum En {
Variant {
field<|>: u8,
field$0: u8,
}
}
}
@ -980,7 +980,7 @@ struct Foo { bar: i32 }
impl Foo {
fn foo(self) {
let x = self<|>.bar;
let x = self$0.bar;
if true {
let _ = match () {
() => self,
@ -1032,7 +1032,7 @@ impl Foo {
r#"
trait Foo<'a> {}
impl<'a> Foo<'a> for &'a () {}
fn foo<'a, 'b: 'a>(x: &'a<|> ()) -> &'a () where &'a (): Foo<'a> {
fn foo<'a, 'b: 'a>(x: &'a$0 ()) -> &'a () where &'a (): Foo<'a> {
fn bar<'a>(_: &'a ()) {}
x
}
@ -1053,7 +1053,7 @@ fn foo<'a, 'b: 'a>(x: &'a<|> ()) -> &'a () where &'a (): Foo<'a> {
fn test_find_lifetimes_type_alias() {
check(
r#"
type Foo<'a, T> where T: 'a<|> = &'a T;
type Foo<'a, T> where T: 'a$0 = &'a T;
"#,
expect![[r#"
'a LifetimeParam FileId(0) 9..11 9..11 Lifetime
@ -1072,7 +1072,7 @@ trait Foo<'a> {
fn foo() -> &'a ();
}
impl<'a> Foo<'a> for &'a () {
fn foo() -> &'a<|> () {
fn foo() -> &'a$0 () {
unimplemented!()
}
}
@ -1093,7 +1093,7 @@ impl<'a> Foo<'a> for &'a () {
r#"
macro_rules! foo {($i:ident) => {$i} }
fn main() {
let a<|> = "test";
let a$0 = "test";
foo!(a);
}
"#,
@ -1112,7 +1112,7 @@ fn main() {
macro_rules! foo {($i:ident) => {$i} }
fn main() {
let a = "test";
foo!(a<|>);
foo!(a$0);
}
"#,
expect![[r#"
@ -1130,7 +1130,7 @@ fn main() {
fn foo<'a>() -> &'a () {
'a: loop {
'b: loop {
continue 'a<|>;
continue 'a$0;
}
break 'a;
}
@ -1149,7 +1149,7 @@ fn foo<'a>() -> &'a () {
fn test_find_const_param() {
check(
r#"
fn foo<const FOO<|>: usize>() -> usize {
fn foo<const FOO$0: usize>() -> usize {
FOO
}
"#,

View file

@ -493,19 +493,19 @@ mod tests {
#[test]
fn test_rename_to_underscore() {
check("_", r#"fn main() { let i<|> = 1; }"#, r#"fn main() { let _ = 1; }"#);
check("_", r#"fn main() { let i$0 = 1; }"#, r#"fn main() { let _ = 1; }"#);
}
#[test]
fn test_rename_to_raw_identifier() {
check("r#fn", r#"fn main() { let i<|> = 1; }"#, r#"fn main() { let r#fn = 1; }"#);
check("r#fn", r#"fn main() { let i$0 = 1; }"#, r#"fn main() { let r#fn = 1; }"#);
}
#[test]
fn test_rename_to_invalid_identifier1() {
check(
"invalid!",
r#"fn main() { let i<|> = 1; }"#,
r#"fn main() { let i$0 = 1; }"#,
"error: Invalid name `invalid!`: not an identifier",
);
}
@ -514,7 +514,7 @@ mod tests {
fn test_rename_to_invalid_identifier2() {
check(
"multiple tokens",
r#"fn main() { let i<|> = 1; }"#,
r#"fn main() { let i$0 = 1; }"#,
"error: Invalid name `multiple tokens`: not an identifier",
);
}
@ -523,7 +523,7 @@ mod tests {
fn test_rename_to_invalid_identifier3() {
check(
"let",
r#"fn main() { let i<|> = 1; }"#,
r#"fn main() { let i$0 = 1; }"#,
"error: Invalid name `let`: not an identifier",
);
}
@ -532,7 +532,7 @@ mod tests {
fn test_rename_to_invalid_identifier_lifetime() {
check(
"'foo",
r#"fn main() { let i<|> = 1; }"#,
r#"fn main() { let i$0 = 1; }"#,
"error: Invalid name `'foo`: not an identifier",
);
}
@ -541,7 +541,7 @@ mod tests {
fn test_rename_to_invalid_identifier_lifetime2() {
check(
"foo",
r#"fn main<'a>(_: &'a<|> ()) {}"#,
r#"fn main<'a>(_: &'a$0 ()) {}"#,
"error: Invalid name `foo`: not a lifetime identifier",
);
}
@ -554,7 +554,7 @@ mod tests {
fn main() {
let mut i = 1;
let j = 1;
i = i<|> + j;
i = i$0 + j;
{ i = 0; }
@ -579,7 +579,7 @@ fn main() {
fn test_rename_unresolved_reference() {
check(
"new_name",
r#"fn main() { let _ = unresolved_ref<|>; }"#,
r#"fn main() { let _ = unresolved_ref$0; }"#,
"error: No references found at position",
);
}
@ -591,7 +591,7 @@ fn main() {
r#"
macro_rules! foo {($i:ident) => {$i} }
fn main() {
let a<|> = "test";
let a$0 = "test";
foo!(a);
}
"#,
@ -613,7 +613,7 @@ fn main() {
macro_rules! foo {($i:ident) => {$i} }
fn main() {
let a = "test";
foo!(a<|>);
foo!(a$0);
}
"#,
r#"
@ -634,7 +634,7 @@ fn main() {
macro_rules! define_fn {($id:ident) => { fn $id{} }}
define_fn!(foo);
fn main() {
fo<|>o();
fo$0o();
}
"#,
r#"
@ -653,7 +653,7 @@ fn main() {
"bar",
r#"
macro_rules! define_fn {($id:ident) => { fn $id{} }}
define_fn!(fo<|>o);
define_fn!(fo$0o);
fn main() {
foo();
}
@ -670,17 +670,17 @@ fn main() {
#[test]
fn test_rename_for_param_inside() {
check("j", r#"fn foo(i : u32) -> u32 { i<|> }"#, r#"fn foo(j : u32) -> u32 { j }"#);
check("j", r#"fn foo(i : u32) -> u32 { i$0 }"#, r#"fn foo(j : u32) -> u32 { j }"#);
}
#[test]
fn test_rename_refs_for_fn_param() {
check("j", r#"fn foo(i<|> : u32) -> u32 { i }"#, r#"fn foo(j : u32) -> u32 { j }"#);
check("j", r#"fn foo(i$0 : u32) -> u32 { i }"#, r#"fn foo(j : u32) -> u32 { j }"#);
}
#[test]
fn test_rename_for_mut_param() {
check("j", r#"fn foo(mut i<|> : u32) -> u32 { i }"#, r#"fn foo(mut j : u32) -> u32 { j }"#);
check("j", r#"fn foo(mut i$0 : u32) -> u32 { i }"#, r#"fn foo(mut j : u32) -> u32 { j }"#);
}
#[test]
@ -688,7 +688,7 @@ fn main() {
check(
"j",
r#"
struct Foo { i<|>: i32 }
struct Foo { i$0: i32 }
impl Foo {
fn new(i: i32) -> Self {
@ -714,7 +714,7 @@ impl Foo {
check(
"j",
r#"
struct Foo { i<|>: i32 }
struct Foo { i$0: i32 }
impl Foo {
fn new(i: i32) -> Self {
@ -743,7 +743,7 @@ impl Foo {
struct Foo { i: i32 }
impl Foo {
fn new(i<|>: i32) -> Self {
fn new(i$0: i32) -> Self {
Self { i }
}
}
@ -765,7 +765,7 @@ impl Foo {
check(
"j",
r#"
struct Foo { i<|>: i32 }
struct Foo { i$0: i32 }
struct Bar { i: i32 }
impl Bar {
@ -794,7 +794,7 @@ impl Bar {
r#"
struct Foo { i: i32 }
fn baz(i<|>: i32) -> Self {
fn baz(i$0: i32) -> Self {
let x = Foo { i };
{
let i = 0;
@ -825,7 +825,7 @@ fn baz(j: i32) -> Self {
mod bar;
//- /bar.rs
mod foo<|>;
mod foo$0;
//- /bar/foo.rs
// empty
@ -883,7 +883,7 @@ fn main() {}
pub struct FooContent;
//- /bar.rs
use crate::foo<|>::FooContent;
use crate::foo$0::FooContent;
"#,
expect![[r#"
RangeInfo {
@ -943,7 +943,7 @@ use crate::foo<|>::FooContent;
"foo2",
r#"
//- /lib.rs
mod fo<|>o;
mod fo$0o;
//- /foo/mod.rs
// emtpy
"#,
@ -992,7 +992,7 @@ mod fo<|>o;
"bar",
r#"
//- /lib.rs
mod outer { mod fo<|>o; }
mod outer { mod fo$0o; }
//- /outer/foo.rs
// emtpy
@ -1041,7 +1041,7 @@ mod outer { mod fo<|>o; }
check(
"baz",
r#"
mod <|>foo { pub fn bar() {} }
mod $0foo { pub fn bar() {} }
fn main() { foo::bar(); }
"#,
@ -1065,7 +1065,7 @@ fn f() {
}
//- /bar.rs
pub mod foo<|>;
pub mod foo$0;
//- /bar/foo.rs
// pub fn fun() {}
@ -1128,7 +1128,7 @@ pub mod foo<|>;
"Baz",
r#"
mod foo {
pub enum Foo { Bar<|> }
pub enum Foo { Bar$0 }
}
fn func(f: foo::Foo) {
@ -1157,7 +1157,7 @@ fn func(f: foo::Foo) {
"baz",
r#"
mod foo {
pub struct Foo { pub bar<|>: uint }
pub struct Foo { pub bar$0: uint }
}
fn foo(f: foo::Foo) {
@ -1184,7 +1184,7 @@ fn foo(f: foo::Foo) {
struct Foo { i: i32 }
impl Foo {
fn f(foo<|>: &mut Foo) -> i32 {
fn f(foo$0: &mut Foo) -> i32 {
foo.i
}
}
@ -1205,7 +1205,7 @@ impl Foo {
struct Foo { i: i32 }
impl Foo {
fn f(foo<|>: Foo) -> i32 {
fn f(foo$0: Foo) -> i32 {
foo.i
}
}
@ -1229,7 +1229,7 @@ impl Foo {
r#"
struct Foo { i: i32 }
fn f(foo<|>: &mut Foo) -> i32 {
fn f(foo$0: &mut Foo) -> i32 {
foo.i
}
"#,
@ -1242,7 +1242,7 @@ struct Foo { i: i32 }
struct Bar;
impl Bar {
fn f(foo<|>: &mut Foo) -> i32 {
fn f(foo$0: &mut Foo) -> i32 {
foo.i
}
}
@ -1258,7 +1258,7 @@ impl Bar {
r#"
struct Foo { i: i32 }
impl Foo {
fn f(x: (), foo<|>: &mut Foo) -> i32 {
fn f(x: (), foo$0: &mut Foo) -> i32 {
foo.i
}
}
@ -1274,7 +1274,7 @@ impl Foo {
r#"
struct Foo { i: i32 }
impl &Foo {
fn f(foo<|>: &Foo) -> i32 {
fn f(foo$0: &Foo) -> i32 {
foo.i
}
}
@ -1298,7 +1298,7 @@ impl &Foo {
struct Foo { i: i32 }
impl Foo {
fn f(&mut <|>self) -> i32 {
fn f(&mut $0self) -> i32 {
self.i
}
}
@ -1323,7 +1323,7 @@ impl Foo {
struct Foo { i: i32 }
impl Foo {
fn f(<|>self) -> i32 {
fn f($0self) -> i32 {
self.i
}
}
@ -1350,7 +1350,7 @@ struct Foo { i: i32 }
impl Foo {
fn f(&self) -> i32 {
let self_var = 1;
self<|>.i
self$0.i
}
}
"#,
@ -1373,7 +1373,7 @@ impl Foo {
check(
"bar",
r#"
struct Foo { i<|>: i32 }
struct Foo { i$0: i32 }
fn foo(bar: i32) -> Foo {
Foo { i: bar }
@ -1394,7 +1394,7 @@ fn foo(bar: i32) -> Foo {
check(
"baz",
r#"
struct Foo { i<|>: i32 }
struct Foo { i$0: i32 }
fn foo(foo: Foo) {
let Foo { i: baz } = foo;
@ -1433,7 +1433,7 @@ struct Foo {
fn foo(foo: Foo) {
let Foo { i: b } = foo;
let _ = b<|>;
let _ = b$0;
}
"#,
expected_fixture,
@ -1447,7 +1447,7 @@ struct Foo {
fn foo(foo: Foo) {
let Foo { i } = foo;
let _ = i<|>;
let _ = i$0;
}
"#,
expected_fixture,
@ -1464,7 +1464,7 @@ struct Foo {
}
fn foo(Foo { i }: foo) -> i32 {
i<|>
i$0
}
"#,
r#"
@ -1488,7 +1488,7 @@ trait Foo<'a> {
fn foo() -> &'a ();
}
impl<'a> Foo<'a> for &'a () {
fn foo() -> &'a<|> () {
fn foo() -> &'a$0 () {
unimplemented!()
}
}
@ -1520,7 +1520,7 @@ fn main() {
let test_variable = CustomOption::Some(22);
match test_variable {
CustomOption::Some(foo<|>) if foo == 11 => {}
CustomOption::Some(foo$0) if foo == 11 => {}
_ => (),
}
}"#,
@ -1549,7 +1549,7 @@ fn main() {
fn foo<'a>() -> &'a () {
'a: {
'b: loop {
break 'a<|>;
break 'a$0;
}
}
}

View file

@ -329,7 +329,7 @@ mod tests {
check(
r#"
//- /lib.rs
<|>
$0
fn main() {}
#[test]
@ -425,7 +425,7 @@ fn bench() {}
check(
r#"
//- /lib.rs
<|>
$0
fn main() {}
/// ```
@ -573,7 +573,7 @@ struct StructWithRunnable(String);
check(
r#"
//- /lib.rs
<|>
$0
fn main() {}
struct Data;
@ -625,7 +625,7 @@ impl Data {
check(
r#"
//- /lib.rs
<|>
$0
mod test_mod {
#[test]
fn test_foo1() {}
@ -679,7 +679,7 @@ mod test_mod {
check(
r#"
//- /lib.rs
<|>
$0
mod root_tests {
mod nested_tests_0 {
mod nested_tests_1 {
@ -819,7 +819,7 @@ mod root_tests {
check(
r#"
//- /lib.rs crate:foo cfg:feature=foo
<|>
$0
#[test]
#[cfg(feature = "foo")]
fn test_foo1() {}
@ -864,7 +864,7 @@ fn test_foo1() {}
check(
r#"
//- /lib.rs crate:foo cfg:feature=foo,feature=bar
<|>
$0
#[test]
#[cfg(all(feature = "foo", feature = "bar"))]
fn test_foo1() {}
@ -919,7 +919,7 @@ fn test_foo1() {}
check(
r#"
//- /lib.rs
<|>
$0
mod test_mod {
fn foo1() {}
}
@ -938,7 +938,7 @@ mod test_mod {
//- /lib.rs
mod foo;
//- /foo.rs
struct Foo;<|>
struct Foo;$0
impl Foo {
/// ```
/// let x = 5;

View file

@ -85,7 +85,7 @@ fn syntax_tree_for_token(node: &SyntaxToken, text_range: TextRange) -> Option<St
.trim_end_matches('"')
.trim()
// Remove custom markers
.replace("<|>", "");
.replace("$0", "");
let parsed = SourceFile::parse(&text);
@ -182,7 +182,7 @@ SOURCE_FILE@0..60
#[test]
fn test_syntax_tree_with_range() {
let (analysis, range) = fixture::range(r#"<|>fn foo() {}<|>"#.trim());
let (analysis, range) = fixture::range(r#"$0fn foo() {}$0"#.trim());
let syn = analysis.syntax_tree(range.file_id, Some(range.range)).unwrap();
assert_eq_text!(
@ -206,10 +206,10 @@ FN@0..11
let (analysis, range) = fixture::range(
r#"fn test() {
<|>assert!("
$0assert!("
fn foo() {
}
", "");<|>
", "");$0
}"#
.trim(),
);
@ -243,8 +243,8 @@ EXPR_STMT@16..58
let (analysis, range) = fixture::range(
r#"fn test() {
assert!("
<|>fn foo() {
}<|>
$0fn foo() {
}$0
fn bar() {
}
", "");
@ -277,8 +277,8 @@ SOURCE_FILE@0..12
let (analysis, range) = fixture::range(
r###"fn test() {
assert!(r#"
<|>fn foo() {
}<|>
$0fn foo() {
}$0
fn bar() {
}
"#, "");
@ -310,11 +310,11 @@ SOURCE_FILE@0..12
// With a raw string
let (analysis, range) = fixture::range(
r###"fn test() {
assert!(r<|>#"
assert!(r$0#"
fn foo() {
}
fn bar() {
}"<|>#, "");
}"$0#, "");
}"###
.trim(),
);

View file

@ -170,7 +170,7 @@ mod tests {
fn test_on_eq_typed() {
// do_check(r"
// fn foo() {
// let foo =<|>
// let foo =$0
// }
// ", r"
// fn foo() {
@ -181,7 +181,7 @@ mod tests {
'=',
r"
fn foo() {
let foo <|> 1 + 1
let foo $0 1 + 1
}
",
r"
@ -192,7 +192,7 @@ fn foo() {
);
// do_check(r"
// fn foo() {
// let foo =<|>
// let foo =$0
// let bar = 1;
// }
// ", r"
@ -210,7 +210,7 @@ fn foo() {
r"
fn main() {
xs.foo()
<|>
$0
}
",
r"
@ -225,7 +225,7 @@ fn foo() {
r"
fn main() {
xs.foo()
<|>
$0
}
",
)
@ -238,7 +238,7 @@ fn foo() {
r"
fn main() {
xs.foo()
<|>;
$0;
}
",
r"
@ -253,7 +253,7 @@ fn foo() {
r"
fn main() {
xs.foo()
<|>;
$0;
}
",
)
@ -266,7 +266,7 @@ fn foo() {
r#"
fn main() {
let _ = foo
<|>
$0
bar()
}
"#,
@ -288,7 +288,7 @@ fn main() {
fn main() {
xs.foo()
.first()
<|>
$0
}
",
r"
@ -305,7 +305,7 @@ fn main() {
fn main() {
xs.foo()
.first()
<|>
$0
}
",
);
@ -318,7 +318,7 @@ fn main() {
r"
fn source_impl() {
let var = enum_defvariant_list().unwrap()
<|>
$0
.nth(92)
.unwrap();
}
@ -337,7 +337,7 @@ fn main() {
r"
fn source_impl() {
let var = enum_defvariant_list().unwrap()
<|>
$0
.nth(92)
.unwrap();
}
@ -351,7 +351,7 @@ fn main() {
'.',
r"
fn main() {
<|>
$0
}
",
);
@ -359,7 +359,7 @@ fn main() {
'.',
r"
fn main() {
<|>
$0
}
",
);
@ -367,6 +367,6 @@ fn main() {
#[test]
fn adds_space_after_return_type() {
type_char('>', "fn foo() -<|>{ 92 }", "fn foo() -> { 92 }")
type_char('>', "fn foo() -$0{ 92 }", "fn foo() -> { 92 }")
}
}

View file

@ -136,7 +136,7 @@ mod tests {
fn continues_doc_comment() {
do_check(
r"
/// Some docs<|>
/// Some docs$0
fn foo() {
}
",
@ -151,7 +151,7 @@ fn foo() {
do_check(
r"
impl S {
/// Some<|> docs.
/// Some$0 docs.
fn foo() {}
}
",
@ -166,7 +166,7 @@ impl S {
do_check(
r"
///<|> Some docs
///$0 Some docs
fn foo() {
}
",
@ -181,7 +181,7 @@ fn foo() {
#[test]
fn does_not_continue_before_doc_comment() {
do_check_noop(r"<|>//! docz");
do_check_noop(r"$0//! docz");
}
#[test]
@ -189,7 +189,7 @@ fn foo() {
do_check(
r"
fn main() {
// Fix<|> me
// Fix$0 me
let x = 1 + 1;
}
",
@ -208,7 +208,7 @@ fn main() {
do_check(
r"
fn main() {
// Fix<|>
// Fix$0
// me
let x = 1 + 1;
}
@ -229,7 +229,7 @@ fn main() {
do_check_noop(
r"
fn main() {
// Fix me<|>
// Fix me$0
let x = 1 + 1;
}
",
@ -242,7 +242,7 @@ fn main() {
do_check(
r#"
fn main() {
// Fix me <|>
// Fix me $0
let x = 1 + 1;
}
"#,
@ -261,7 +261,7 @@ fn main() {
do_check(
"
fn main() {
// Fix me \t\t <|>
// Fix me \t\t $0
let x = 1 + 1;
}
",

Some files were not shown because too many files have changed in this diff Show more