Skip to content

Commit 69a6e4c

Browse files
7708: Format code through rust-analyzer formatter.
1 parent cb3f4d4 commit 69a6e4c

File tree

1 file changed

+44
-35
lines changed

1 file changed

+44
-35
lines changed

crates/ide_assists/src/handlers/generate_default_from_new.rs

Lines changed: 44 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
1-
use crate::{AssistId, assist_context::{AssistContext, Assists}};
2-
use syntax::{AstNode, SyntaxKind, SyntaxNode, SyntaxText, ast::{self, NameOwner}};
1+
use crate::{
2+
assist_context::{AssistContext, Assists},
3+
AssistId,
4+
};
5+
use syntax::{
6+
ast::{self, NameOwner},
7+
AstNode, SyntaxKind, SyntaxNode, SyntaxText,
8+
};
39
use test_utils::mark;
410

511
// Assist: generate_default_from_new
@@ -51,7 +57,6 @@ pub(crate) fn generate_default_from_new(acc: &mut Assists, ctx: &AssistContext)
5157

5258
let default_fn_syntax = default_fn_node_for_new(struct_name);
5359

54-
5560
acc.add(
5661
AssistId("generate_default_from_new", crate::AssistKind::Generate),
5762
"Generate a Default impl from a new fn",
@@ -72,14 +77,15 @@ fn scope_for_fn_insertion_node(node: &SyntaxNode) -> Option<SyntaxNode> {
7277
fn default_fn_node_for_new(struct_name: SyntaxText) -> String {
7378
// TODO: Update the implementation to consider the code indentation.
7479
format!(
75-
r#"
80+
r#"
7681
7782
impl Default for {} {{
7883
fn default() -> Self {{
7984
Self::new()
8085
}}
81-
}}"#
82-
,struct_name)
86+
}}"#,
87+
struct_name
88+
)
8389
}
8490

8591
#[cfg(test)]
@@ -157,24 +163,26 @@ impl Default for Test {
157163
#[test]
158164
fn new_function_with_parameters() {
159165
mark::check!(new_function_with_parameters);
160-
check_assist_not_applicable(generate_default_from_new,
161-
r#"
166+
check_assist_not_applicable(
167+
generate_default_from_new,
168+
r#"
162169
struct Example { _inner: () }
163170
164171
impl Example {
165172
pub fn $0new(value: ()) -> Self {
166173
Self { _inner: value }
167174
}
168175
}
169-
"#
176+
"#,
170177
);
171178
}
172179

173180
#[test]
174181
fn other_function_than_new() {
175182
mark::check!(other_function_than_new);
176-
check_assist_not_applicable(generate_default_from_new,
177-
r#"
183+
check_assist_not_applicable(
184+
generate_default_from_new,
185+
r#"
178186
struct Example { _inner: () }
179187
180188
impl Exmaple {
@@ -183,39 +191,40 @@ impl Exmaple {
183191
}
184192
}
185193
186-
"#
194+
"#,
187195
);
188196
}
189197

190-
// #[test]
191-
// fn default_block_is_already_present() {
192-
// check_assist_not_applicable(generate_default_from_new,
193-
// r#"
194-
// struct Example { _inner: () }
195-
196-
// impl Exmaple {
197-
// pub fn n$0ew() -> Self {
198-
// Self { _inner: () }
199-
// }
200-
// }
201-
202-
// impl Default for Example {
203-
// fn default() -> Self {
204-
// Self::new()
205-
// }
206-
// }
207-
// "#,
208-
// );
209-
// }
198+
// #[test]
199+
// fn default_block_is_already_present() {
200+
// check_assist_not_applicable(generate_default_from_new,
201+
// r#"
202+
// struct Example { _inner: () }
203+
204+
// impl Exmaple {
205+
// pub fn n$0ew() -> Self {
206+
// Self { _inner: () }
207+
// }
208+
// }
209+
210+
// impl Default for Example {
211+
// fn default() -> Self {
212+
// Self::new()
213+
// }
214+
// }
215+
// "#,
216+
// );
217+
// }
210218

211219
#[test]
212220
fn standalone_new_function() {
213-
check_assist_not_applicable(generate_default_from_new,
214-
r#"
221+
check_assist_not_applicable(
222+
generate_default_from_new,
223+
r#"
215224
fn n$0ew() -> u32 {
216225
0
217226
}
218-
"#
227+
"#,
219228
);
220229
}
221230
}

0 commit comments

Comments
 (0)