aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_assists/src/handlers
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/handlers
parentd08232b10d7085e1f5be96b87cca880f6ee56c9e (diff)
Rename assist
Diffstat (limited to 'crates/ra_assists/src/handlers')
-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
1 files changed, 22 insertions, 25 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 );