aboutsummaryrefslogtreecommitdiff
path: root/crates/ide_assists/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ide_assists/src')
-rw-r--r--crates/ide_assists/src/handlers/generate_default_from_new.rs12
-rw-r--r--crates/ide_assists/src/tests/generated.rs31
2 files changed, 37 insertions, 6 deletions
diff --git a/crates/ide_assists/src/handlers/generate_default_from_new.rs b/crates/ide_assists/src/handlers/generate_default_from_new.rs
index e7f4591ac..c7b049a46 100644
--- a/crates/ide_assists/src/handlers/generate_default_from_new.rs
+++ b/crates/ide_assists/src/handlers/generate_default_from_new.rs
@@ -10,13 +10,13 @@ use test_utils::mark;
10 10
11// Assist: generate_default_from_new 11// Assist: generate_default_from_new
12// 12//
13// Generates default implementation from new method 13// Generates default implementation from new method.
14// 14//
15// ``` 15// ```
16// struct Example { _inner: () } 16// struct Example { _inner: () }
17// 17//
18// impl Example { 18// impl Example {
19// pu|b fn new() -> Self { 19// pub fn n$0ew() -> Self {
20// Self { _inner: () } 20// Self { _inner: () }
21// } 21// }
22// } 22// }
@@ -24,13 +24,13 @@ use test_utils::mark;
24// -> 24// ->
25// ``` 25// ```
26// struct Example { _inner: () } 26// struct Example { _inner: () }
27 27//
28// impl Example { 28// impl Example {
29// pub fn new() -> Self { 29// pub fn new() -> Self {
30// Self { _inner: () } 30// Self { _inner: () }
31// } 31// }
32// } 32// }
33 33//
34// impl Default for Example { 34// impl Default for Example {
35// fn default() -> Self { 35// fn default() -> Self {
36// Self::new() 36// Self::new()
@@ -62,7 +62,7 @@ pub(crate) fn generate_default_from_new(acc: &mut Assists, ctx: &AssistContext)
62 "Generate a Default impl from a new fn", 62 "Generate a Default impl from a new fn",
63 impl_obj.syntax().text_range(), 63 impl_obj.syntax().text_range(),
64 move |builder| { 64 move |builder| {
65 // TODO: indentation logic can also go here. 65 // FIXME: indentation logic can also go here.
66 // let new_indent = IndentLevel::from_node(&insert_after); 66 // let new_indent = IndentLevel::from_node(&insert_after);
67 let insert_location = impl_obj.syntax().text_range().end(); 67 let insert_location = impl_obj.syntax().text_range().end();
68 builder.insert(insert_location, default_fn_syntax); 68 builder.insert(insert_location, default_fn_syntax);
@@ -75,7 +75,7 @@ fn scope_for_fn_insertion_node(node: &SyntaxNode) -> Option<SyntaxNode> {
75} 75}
76 76
77fn default_fn_node_for_new(struct_name: SyntaxText) -> String { 77fn default_fn_node_for_new(struct_name: SyntaxText) -> String {
78 // TODO: Update the implementation to consider the code indentation. 78 // FIXME: Update the implementation to consider the code indentation.
79 format!( 79 format!(
80 r#" 80 r#"
81 81
diff --git a/crates/ide_assists/src/tests/generated.rs b/crates/ide_assists/src/tests/generated.rs
index 4f007aa48..304b5798f 100644
--- a/crates/ide_assists/src/tests/generated.rs
+++ b/crates/ide_assists/src/tests/generated.rs
@@ -440,6 +440,37 @@ impl Default for Version {
440} 440}
441 441
442#[test] 442#[test]
443fn doctest_generate_default_from_new() {
444 check_doc_test(
445 "generate_default_from_new",
446 r#####"
447struct Example { _inner: () }
448
449impl Example {
450 pub fn n$0ew() -> Self {
451 Self { _inner: () }
452 }
453}
454"#####,
455 r#####"
456struct Example { _inner: () }
457
458impl Example {
459 pub fn new() -> Self {
460 Self { _inner: () }
461 }
462}
463
464impl Default for Example {
465 fn default() -> Self {
466 Self::new()
467 }
468}
469"#####,
470 )
471}
472
473#[test]
443fn doctest_generate_derive() { 474fn doctest_generate_derive() {
444 check_doc_test( 475 check_doc_test(
445 "generate_derive", 476 "generate_derive",