aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_assists/src
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2020-06-01 14:36:51 +0100
committerAleksey Kladov <[email protected]>2020-06-01 14:41:16 +0100
commit285717de33c25422db60420030d46d10cf3b0121 (patch)
treed757ba7d5afc93ae3f0a22fbd0cc401f52e067b9 /crates/ra_assists/src
parentd08232b10d7085e1f5be96b87cca880f6ee56c9e (diff)
Rename assist
Diffstat (limited to 'crates/ra_assists/src')
-rw-r--r--crates/ra_assists/src/handlers/introduce_named_lifetime.rs (renamed from crates/ra_assists/src/handlers/change_lifetime_anon_to_named.rs)47
-rw-r--r--crates/ra_assists/src/lib.rs4
-rw-r--r--crates/ra_assists/src/tests/generated.rs50
3 files changed, 49 insertions, 52 deletions
diff --git a/crates/ra_assists/src/handlers/change_lifetime_anon_to_named.rs b/crates/ra_assists/src/handlers/introduce_named_lifetime.rs
index 0fdbc63dd..beb5b7366 100644
--- a/crates/ra_assists/src/handlers/change_lifetime_anon_to_named.rs
+++ b/crates/ra_assists/src/handlers/introduce_named_lifetime.rs
@@ -6,10 +6,10 @@ use rustc_hash::FxHashSet;
6 6
7use crate::{assist_context::AssistBuilder, AssistContext, AssistId, Assists}; 7use crate::{assist_context::AssistBuilder, AssistContext, AssistId, Assists};
8 8
9static ASSIST_NAME: &str = "change_lifetime_anon_to_named"; 9static ASSIST_NAME: &str = "introduce_named_lifetime";
10static ASSIST_LABEL: &str = "Give anonymous lifetime a name"; 10static ASSIST_LABEL: &str = "Introduce named lifetime";
11 11
12// Assist: change_lifetime_anon_to_named 12// Assist: introduce_named_lifetime
13// 13//
14// Change an anonymous lifetime to a named lifetime. 14// Change an anonymous lifetime to a named lifetime.
15// 15//
@@ -34,7 +34,7 @@ static ASSIST_LABEL: &str = "Give anonymous lifetime a name";
34// ``` 34// ```
35// FIXME: How can we handle renaming any one of multiple anonymous lifetimes? 35// FIXME: How can we handle renaming any one of multiple anonymous lifetimes?
36// FIXME: should also add support for the case fun(f: &Foo) -> &<|>Foo 36// FIXME: should also add support for the case fun(f: &Foo) -> &<|>Foo
37pub(crate) fn change_lifetime_anon_to_named(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { 37pub(crate) fn introduce_named_lifetime(acc: &mut Assists, ctx: &AssistContext) -> Option<()> {
38 let lifetime_token = ctx 38 let lifetime_token = ctx
39 .find_token_at_offset(SyntaxKind::LIFETIME) 39 .find_token_at_offset(SyntaxKind::LIFETIME)
40 .filter(|lifetime| lifetime.text() == "'_")?; 40 .filter(|lifetime| lifetime.text() == "'_")?;
@@ -154,7 +154,7 @@ mod tests {
154 #[test] 154 #[test]
155 fn test_example_case() { 155 fn test_example_case() {
156 check_assist( 156 check_assist(
157 change_lifetime_anon_to_named, 157 introduce_named_lifetime,
158 r#"impl Cursor<'_<|>> { 158 r#"impl Cursor<'_<|>> {
159 fn node(self) -> &SyntaxNode { 159 fn node(self) -> &SyntaxNode {
160 match self { 160 match self {
@@ -175,7 +175,7 @@ mod tests {
175 #[test] 175 #[test]
176 fn test_example_case_simplified() { 176 fn test_example_case_simplified() {
177 check_assist( 177 check_assist(
178 change_lifetime_anon_to_named, 178 introduce_named_lifetime,
179 r#"impl Cursor<'_<|>> {"#, 179 r#"impl Cursor<'_<|>> {"#,
180 r#"impl<'a> Cursor<'a> {"#, 180 r#"impl<'a> Cursor<'a> {"#,
181 ); 181 );
@@ -184,7 +184,7 @@ mod tests {
184 #[test] 184 #[test]
185 fn test_example_case_cursor_after_tick() { 185 fn test_example_case_cursor_after_tick() {
186 check_assist( 186 check_assist(
187 change_lifetime_anon_to_named, 187 introduce_named_lifetime,
188 r#"impl Cursor<'<|>_> {"#, 188 r#"impl Cursor<'<|>_> {"#,
189 r#"impl<'a> Cursor<'a> {"#, 189 r#"impl<'a> Cursor<'a> {"#,
190 ); 190 );
@@ -193,7 +193,7 @@ mod tests {
193 #[test] 193 #[test]
194 fn test_example_case_cursor_before_tick() { 194 fn test_example_case_cursor_before_tick() {
195 check_assist( 195 check_assist(
196 change_lifetime_anon_to_named, 196 introduce_named_lifetime,
197 r#"impl Cursor<<|>'_> {"#, 197 r#"impl Cursor<<|>'_> {"#,
198 r#"impl<'a> Cursor<'a> {"#, 198 r#"impl<'a> Cursor<'a> {"#,
199 ); 199 );
@@ -201,23 +201,20 @@ mod tests {
201 201
202 #[test] 202 #[test]
203 fn test_not_applicable_cursor_position() { 203 fn test_not_applicable_cursor_position() {
204 check_assist_not_applicable(change_lifetime_anon_to_named, r#"impl Cursor<'_><|> {"#); 204 check_assist_not_applicable(introduce_named_lifetime, r#"impl Cursor<'_><|> {"#);
205 check_assist_not_applicable(change_lifetime_anon_to_named, r#"impl Cursor<|><'_> {"#); 205 check_assist_not_applicable(introduce_named_lifetime, r#"impl Cursor<|><'_> {"#);
206 } 206 }
207 207
208 #[test] 208 #[test]
209 fn test_not_applicable_lifetime_already_name() { 209 fn test_not_applicable_lifetime_already_name() {
210 check_assist_not_applicable(change_lifetime_anon_to_named, r#"impl Cursor<'a<|>> {"#); 210 check_assist_not_applicable(introduce_named_lifetime, r#"impl Cursor<'a<|>> {"#);
211 check_assist_not_applicable( 211 check_assist_not_applicable(introduce_named_lifetime, r#"fn my_fun<'a>() -> X<'a<|>>"#);
212 change_lifetime_anon_to_named,
213 r#"fn my_fun<'a>() -> X<'a<|>>"#,
214 );
215 } 212 }
216 213
217 #[test] 214 #[test]
218 fn test_with_type_parameter() { 215 fn test_with_type_parameter() {
219 check_assist( 216 check_assist(
220 change_lifetime_anon_to_named, 217 introduce_named_lifetime,
221 r#"impl<T> Cursor<T, '_<|>>"#, 218 r#"impl<T> Cursor<T, '_<|>>"#,
222 r#"impl<T, 'a> Cursor<T, 'a>"#, 219 r#"impl<T, 'a> Cursor<T, 'a>"#,
223 ); 220 );
@@ -226,7 +223,7 @@ mod tests {
226 #[test] 223 #[test]
227 fn test_with_existing_lifetime_name_conflict() { 224 fn test_with_existing_lifetime_name_conflict() {
228 check_assist( 225 check_assist(
229 change_lifetime_anon_to_named, 226 introduce_named_lifetime,
230 r#"impl<'a, 'b> Cursor<'a, 'b, '_<|>>"#, 227 r#"impl<'a, 'b> Cursor<'a, 'b, '_<|>>"#,
231 r#"impl<'a, 'b, 'c> Cursor<'a, 'b, 'c>"#, 228 r#"impl<'a, 'b, 'c> Cursor<'a, 'b, 'c>"#,
232 ); 229 );
@@ -235,7 +232,7 @@ mod tests {
235 #[test] 232 #[test]
236 fn test_function_return_value_anon_lifetime_param() { 233 fn test_function_return_value_anon_lifetime_param() {
237 check_assist( 234 check_assist(
238 change_lifetime_anon_to_named, 235 introduce_named_lifetime,
239 r#"fn my_fun() -> X<'_<|>>"#, 236 r#"fn my_fun() -> X<'_<|>>"#,
240 r#"fn my_fun<'a>() -> X<'a>"#, 237 r#"fn my_fun<'a>() -> X<'a>"#,
241 ); 238 );
@@ -244,7 +241,7 @@ mod tests {
244 #[test] 241 #[test]
245 fn test_function_return_value_anon_reference_lifetime() { 242 fn test_function_return_value_anon_reference_lifetime() {
246 check_assist( 243 check_assist(
247 change_lifetime_anon_to_named, 244 introduce_named_lifetime,
248 r#"fn my_fun() -> &'_<|> X"#, 245 r#"fn my_fun() -> &'_<|> X"#,
249 r#"fn my_fun<'a>() -> &'a X"#, 246 r#"fn my_fun<'a>() -> &'a X"#,
250 ); 247 );
@@ -253,7 +250,7 @@ mod tests {
253 #[test] 250 #[test]
254 fn test_function_param_anon_lifetime() { 251 fn test_function_param_anon_lifetime() {
255 check_assist( 252 check_assist(
256 change_lifetime_anon_to_named, 253 introduce_named_lifetime,
257 r#"fn my_fun(x: X<'_<|>>)"#, 254 r#"fn my_fun(x: X<'_<|>>)"#,
258 r#"fn my_fun<'a>(x: X<'a>)"#, 255 r#"fn my_fun<'a>(x: X<'a>)"#,
259 ); 256 );
@@ -262,7 +259,7 @@ mod tests {
262 #[test] 259 #[test]
263 fn test_function_add_lifetime_to_params() { 260 fn test_function_add_lifetime_to_params() {
264 check_assist( 261 check_assist(
265 change_lifetime_anon_to_named, 262 introduce_named_lifetime,
266 r#"fn my_fun(f: &Foo) -> X<'_<|>>"#, 263 r#"fn my_fun(f: &Foo) -> X<'_<|>>"#,
267 r#"fn my_fun<'a>(f: &'a Foo) -> X<'a>"#, 264 r#"fn my_fun<'a>(f: &'a Foo) -> X<'a>"#,
268 ); 265 );
@@ -271,7 +268,7 @@ mod tests {
271 #[test] 268 #[test]
272 fn test_function_add_lifetime_to_params_in_presence_of_other_lifetime() { 269 fn test_function_add_lifetime_to_params_in_presence_of_other_lifetime() {
273 check_assist( 270 check_assist(
274 change_lifetime_anon_to_named, 271 introduce_named_lifetime,
275 r#"fn my_fun<'other>(f: &Foo, b: &'other Bar) -> X<'_<|>>"#, 272 r#"fn my_fun<'other>(f: &Foo, b: &'other Bar) -> X<'_<|>>"#,
276 r#"fn my_fun<'other, 'a>(f: &'a Foo, b: &'other Bar) -> X<'a>"#, 273 r#"fn my_fun<'other, 'a>(f: &'a Foo, b: &'other Bar) -> X<'a>"#,
277 ); 274 );
@@ -281,7 +278,7 @@ mod tests {
281 fn test_function_not_applicable_without_self_and_multiple_unnamed_param_lifetimes() { 278 fn test_function_not_applicable_without_self_and_multiple_unnamed_param_lifetimes() {
282 // this is not permitted under lifetime elision rules 279 // this is not permitted under lifetime elision rules
283 check_assist_not_applicable( 280 check_assist_not_applicable(
284 change_lifetime_anon_to_named, 281 introduce_named_lifetime,
285 r#"fn my_fun(f: &Foo, b: &Bar) -> X<'_<|>>"#, 282 r#"fn my_fun(f: &Foo, b: &Bar) -> X<'_<|>>"#,
286 ); 283 );
287 } 284 }
@@ -289,7 +286,7 @@ mod tests {
289 #[test] 286 #[test]
290 fn test_function_add_lifetime_to_self_ref_param() { 287 fn test_function_add_lifetime_to_self_ref_param() {
291 check_assist( 288 check_assist(
292 change_lifetime_anon_to_named, 289 introduce_named_lifetime,
293 r#"fn my_fun<'other>(&self, f: &Foo, b: &'other Bar) -> X<'_<|>>"#, 290 r#"fn my_fun<'other>(&self, f: &Foo, b: &'other Bar) -> X<'_<|>>"#,
294 r#"fn my_fun<'other, 'a>(&'a self, f: &Foo, b: &'other Bar) -> X<'a>"#, 291 r#"fn my_fun<'other, 'a>(&'a self, f: &Foo, b: &'other Bar) -> X<'a>"#,
295 ); 292 );
@@ -298,7 +295,7 @@ mod tests {
298 #[test] 295 #[test]
299 fn test_function_add_lifetime_to_param_with_non_ref_self() { 296 fn test_function_add_lifetime_to_param_with_non_ref_self() {
300 check_assist( 297 check_assist(
301 change_lifetime_anon_to_named, 298 introduce_named_lifetime,
302 r#"fn my_fun<'other>(self, f: &Foo, b: &'other Bar) -> X<'_<|>>"#, 299 r#"fn my_fun<'other>(self, f: &Foo, b: &'other Bar) -> X<'_<|>>"#,
303 r#"fn my_fun<'other, 'a>(self, f: &'a Foo, b: &'other Bar) -> X<'a>"#, 300 r#"fn my_fun<'other, 'a>(self, f: &'a Foo, b: &'other Bar) -> X<'a>"#,
304 ); 301 );
diff --git a/crates/ra_assists/src/lib.rs b/crates/ra_assists/src/lib.rs
index 3f8f7ffbf..fb5d59a87 100644
--- a/crates/ra_assists/src/lib.rs
+++ b/crates/ra_assists/src/lib.rs
@@ -112,7 +112,6 @@ mod handlers {
112 mod add_turbo_fish; 112 mod add_turbo_fish;
113 mod apply_demorgan; 113 mod apply_demorgan;
114 mod auto_import; 114 mod auto_import;
115 mod change_lifetime_anon_to_named;
116 mod change_return_type_to_result; 115 mod change_return_type_to_result;
117 mod change_visibility; 116 mod change_visibility;
118 mod early_return; 117 mod early_return;
@@ -122,6 +121,7 @@ mod handlers {
122 mod flip_comma; 121 mod flip_comma;
123 mod flip_trait_bound; 122 mod flip_trait_bound;
124 mod inline_local_variable; 123 mod inline_local_variable;
124 mod introduce_named_lifetime;
125 mod introduce_variable; 125 mod introduce_variable;
126 mod invert_if; 126 mod invert_if;
127 mod merge_imports; 127 mod merge_imports;
@@ -152,7 +152,6 @@ mod handlers {
152 add_turbo_fish::add_turbo_fish, 152 add_turbo_fish::add_turbo_fish,
153 apply_demorgan::apply_demorgan, 153 apply_demorgan::apply_demorgan,
154 auto_import::auto_import, 154 auto_import::auto_import,
155 change_lifetime_anon_to_named::change_lifetime_anon_to_named,
156 change_return_type_to_result::change_return_type_to_result, 155 change_return_type_to_result::change_return_type_to_result,
157 change_visibility::change_visibility, 156 change_visibility::change_visibility,
158 early_return::convert_to_guarded_return, 157 early_return::convert_to_guarded_return,
@@ -162,6 +161,7 @@ mod handlers {
162 flip_comma::flip_comma, 161 flip_comma::flip_comma,
163 flip_trait_bound::flip_trait_bound, 162 flip_trait_bound::flip_trait_bound,
164 inline_local_variable::inline_local_variable, 163 inline_local_variable::inline_local_variable,
164 introduce_named_lifetime::introduce_named_lifetime,
165 introduce_variable::introduce_variable, 165 introduce_variable::introduce_variable,
166 invert_if::invert_if, 166 invert_if::invert_if,
167 merge_imports::merge_imports, 167 merge_imports::merge_imports,
diff --git a/crates/ra_assists/src/tests/generated.rs b/crates/ra_assists/src/tests/generated.rs
index 73d43283d..d17504529 100644
--- a/crates/ra_assists/src/tests/generated.rs
+++ b/crates/ra_assists/src/tests/generated.rs
@@ -288,31 +288,6 @@ pub mod std { pub mod collections { pub struct HashMap { } } }
288} 288}
289 289
290#[test] 290#[test]
291fn doctest_change_lifetime_anon_to_named() {
292 check_doc_test(
293 "change_lifetime_anon_to_named",
294 r#####"
295impl Cursor<'_<|>> {
296 fn node(self) -> &SyntaxNode {
297 match self {
298 Cursor::Replace(node) | Cursor::Before(node) => node,
299 }
300 }
301}
302"#####,
303 r#####"
304impl<'a> Cursor<'a> {
305 fn node(self) -> &SyntaxNode {
306 match self {
307 Cursor::Replace(node) | Cursor::Before(node) => node,
308 }
309 }
310}
311"#####,
312 )
313}
314
315#[test]
316fn doctest_change_return_type_to_result() { 291fn doctest_change_return_type_to_result() {
317 check_doc_test( 292 check_doc_test(
318 "change_return_type_to_result", 293 "change_return_type_to_result",
@@ -477,6 +452,31 @@ fn main() {
477} 452}
478 453
479#[test] 454#[test]
455fn doctest_introduce_named_lifetime() {
456 check_doc_test(
457 "introduce_named_lifetime",
458 r#####"
459impl Cursor<'_<|>> {
460 fn node(self) -> &SyntaxNode {
461 match self {
462 Cursor::Replace(node) | Cursor::Before(node) => node,
463 }
464 }
465}
466"#####,
467 r#####"
468impl<'a> Cursor<'a> {
469 fn node(self) -> &SyntaxNode {
470 match self {
471 Cursor::Replace(node) | Cursor::Before(node) => node,
472 }
473 }
474}
475"#####,
476 )
477}
478
479#[test]
480fn doctest_introduce_variable() { 480fn doctest_introduce_variable() {
481 check_doc_test( 481 check_doc_test(
482 "introduce_variable", 482 "introduce_variable",