Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
4392: Add From should not move the cursor r=matklad a=matklad



bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
  • Loading branch information
bors[bot] and matklad authored May 9, 2020
2 parents 77d2eab + d9828a5 commit f1cb5b8
Showing 1 changed file with 11 additions and 14 deletions.
25 changes: 11 additions & 14 deletions crates/ra_assists/src/handlers/add_from_impl_for_enum.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
use ra_ide_db::RootDatabase;
use ra_syntax::{
ast::{self, AstNode, NameOwner},
TextSize,
};
use ra_syntax::ast::{self, AstNode, NameOwner};
use stdx::format_to;
use test_utils::tested_by;

Expand Down Expand Up @@ -69,7 +66,6 @@ impl From<{0}> for {1} {{
variant_name
);
edit.insert(start_offset, buf);
edit.set_cursor(start_offset + TextSize::of("\n\n"));
},
)
}
Expand Down Expand Up @@ -97,19 +93,20 @@ fn existing_from_impl(

#[cfg(test)]
mod tests {
use super::*;
use test_utils::covers;

use crate::tests::{check_assist, check_assist_not_applicable};
use test_utils::covers;

use super::*;

#[test]
fn test_add_from_impl_for_enum() {
check_assist(
add_from_impl_for_enum,
"enum A { <|>One(u32) }",
r#"enum A { One(u32) }
r#"enum A { <|>One(u32) }
<|>impl From<u32> for A {
impl From<u32> for A {
fn from(v: u32) -> Self {
A::One(v)
}
Expand All @@ -121,10 +118,10 @@ mod tests {
fn test_add_from_impl_for_enum_complicated_path() {
check_assist(
add_from_impl_for_enum,
"enum A { <|>One(foo::bar::baz::Boo) }",
r#"enum A { One(foo::bar::baz::Boo) }
r#"enum A { <|>One(foo::bar::baz::Boo) }"#,
r#"enum A { <|>One(foo::bar::baz::Boo) }
<|>impl From<foo::bar::baz::Boo> for A {
impl From<foo::bar::baz::Boo> for A {
fn from(v: foo::bar::baz::Boo) -> Self {
A::One(v)
}
Expand Down Expand Up @@ -184,9 +181,9 @@ impl From<String> for A {
pub trait From<T> {
fn from(T) -> Self;
}"#,
r#"enum A { One(u32), Two(String), }
r#"enum A { <|>One(u32), Two(String), }
<|>impl From<u32> for A {
impl From<u32> for A {
fn from(v: u32) -> Self {
A::One(v)
}
Expand Down

0 comments on commit f1cb5b8

Please sign in to comment.