aboutsummaryrefslogtreecommitdiff
path: root/crates/ide_assists
diff options
context:
space:
mode:
authorChetan Khilosiya <[email protected]>2021-02-27 20:29:19 +0000
committerChetan Khilosiya <[email protected]>2021-03-06 19:19:03 +0000
commit69a6e4c80c9efa5c611e357f56a4d8cbd9d81e6b (patch)
treeb17c40425ad4363d108235db18a5f5f09c88d97c /crates/ide_assists
parentcb3f4d43d9646deadf27da54e0d2a204685ed665 (diff)
7708: Format code through rust-analyzer formatter.
Diffstat (limited to 'crates/ide_assists')
-rw-r--r--crates/ide_assists/src/handlers/generate_default_from_new.rs79
1 files changed, 44 insertions, 35 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 a1174d315..e7f4591ac 100644
--- a/crates/ide_assists/src/handlers/generate_default_from_new.rs
+++ b/crates/ide_assists/src/handlers/generate_default_from_new.rs
@@ -1,5 +1,11 @@
1use crate::{AssistId, assist_context::{AssistContext, Assists}}; 1use crate::{
2use syntax::{AstNode, SyntaxKind, SyntaxNode, SyntaxText, ast::{self, NameOwner}}; 2 assist_context::{AssistContext, Assists},
3 AssistId,
4};
5use syntax::{
6 ast::{self, NameOwner},
7 AstNode, SyntaxKind, SyntaxNode, SyntaxText,
8};
3use test_utils::mark; 9use test_utils::mark;
4 10
5// Assist: generate_default_from_new 11// Assist: generate_default_from_new
@@ -51,7 +57,6 @@ pub(crate) fn generate_default_from_new(acc: &mut Assists, ctx: &AssistContext)
51 57
52 let default_fn_syntax = default_fn_node_for_new(struct_name); 58 let default_fn_syntax = default_fn_node_for_new(struct_name);
53 59
54
55 acc.add( 60 acc.add(
56 AssistId("generate_default_from_new", crate::AssistKind::Generate), 61 AssistId("generate_default_from_new", crate::AssistKind::Generate),
57 "Generate a Default impl from a new fn", 62 "Generate a Default impl from a new fn",
@@ -72,14 +77,15 @@ fn scope_for_fn_insertion_node(node: &SyntaxNode) -> Option<SyntaxNode> {
72fn default_fn_node_for_new(struct_name: SyntaxText) -> String { 77fn default_fn_node_for_new(struct_name: SyntaxText) -> String {
73 // TODO: Update the implementation to consider the code indentation. 78 // TODO: Update the implementation to consider the code indentation.
74 format!( 79 format!(
75 r#" 80 r#"
76 81
77impl Default for {} {{ 82impl Default for {} {{
78 fn default() -> Self {{ 83 fn default() -> Self {{
79 Self::new() 84 Self::new()
80 }} 85 }}
81}}"# 86}}"#,
82 ,struct_name) 87 struct_name
88 )
83} 89}
84 90
85#[cfg(test)] 91#[cfg(test)]
@@ -157,8 +163,9 @@ impl Default for Test {
157 #[test] 163 #[test]
158 fn new_function_with_parameters() { 164 fn new_function_with_parameters() {
159 mark::check!(new_function_with_parameters); 165 mark::check!(new_function_with_parameters);
160 check_assist_not_applicable(generate_default_from_new, 166 check_assist_not_applicable(
161 r#" 167 generate_default_from_new,
168 r#"
162struct Example { _inner: () } 169struct Example { _inner: () }
163 170
164impl Example { 171impl Example {
@@ -166,15 +173,16 @@ impl Example {
166 Self { _inner: value } 173 Self { _inner: value }
167 } 174 }
168} 175}
169"# 176"#,
170 ); 177 );
171 } 178 }
172 179
173 #[test] 180 #[test]
174 fn other_function_than_new() { 181 fn other_function_than_new() {
175 mark::check!(other_function_than_new); 182 mark::check!(other_function_than_new);
176 check_assist_not_applicable(generate_default_from_new, 183 check_assist_not_applicable(
177 r#" 184 generate_default_from_new,
185 r#"
178struct Example { _inner: () } 186struct Example { _inner: () }
179 187
180impl Exmaple { 188impl Exmaple {
@@ -183,39 +191,40 @@ impl Exmaple {
183 } 191 }
184} 192}
185 193
186"# 194"#,
187 ); 195 );
188 } 196 }
189 197
190// #[test] 198 // #[test]
191// fn default_block_is_already_present() { 199 // fn default_block_is_already_present() {
192// check_assist_not_applicable(generate_default_from_new, 200 // check_assist_not_applicable(generate_default_from_new,
193// r#" 201 // r#"
194// struct Example { _inner: () } 202 // struct Example { _inner: () }
195 203
196// impl Exmaple { 204 // impl Exmaple {
197// pub fn n$0ew() -> Self { 205 // pub fn n$0ew() -> Self {
198// Self { _inner: () } 206 // Self { _inner: () }
199// } 207 // }
200// } 208 // }
201 209
202// impl Default for Example { 210 // impl Default for Example {
203// fn default() -> Self { 211 // fn default() -> Self {
204// Self::new() 212 // Self::new()
205// } 213 // }
206// } 214 // }
207// "#, 215 // "#,
208// ); 216 // );
209// } 217 // }
210 218
211 #[test] 219 #[test]
212 fn standalone_new_function() { 220 fn standalone_new_function() {
213 check_assist_not_applicable(generate_default_from_new, 221 check_assist_not_applicable(
214 r#" 222 generate_default_from_new,
223 r#"
215fn n$0ew() -> u32 { 224fn n$0ew() -> u32 {
216 0 225 0
217} 226}
218"# 227"#,
219 ); 228 );
220 } 229 }
221} 230}