Skip to content

Commit e6bb047

Browse files
authored
Merge pull request rust-lang#19221 from Giga-Bowser/generate-trait-impl-tabstop
minor: Add tabstop to impl body in `generate_trait_impl` assist
2 parents a9dbd49 + 1ff2593 commit e6bb047

File tree

3 files changed

+18
-14
lines changed

3 files changed

+18
-14
lines changed

src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_impl.rs

+15-11
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ pub(crate) fn generate_impl(acc: &mut Assists, ctx: &AssistContext<'_>) -> Optio
7878
// data: T,
7979
// }
8080
//
81-
// impl<T: Clone> ${0:_} for Ctx<T> {}
81+
// impl<T: Clone> ${1:_} for Ctx<T> {$0}
8282
// ```
8383
pub(crate) fn generate_trait_impl(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()> {
8484
let nominal = ctx.find_node_at_offset::<ast::Adt>()?;
@@ -102,6 +102,10 @@ pub(crate) fn generate_trait_impl(acc: &mut Assists, ctx: &AssistContext<'_>) ->
102102
if let Some(trait_) = impl_.trait_() {
103103
edit.add_placeholder_snippet(cap, trait_);
104104
}
105+
106+
if let Some(l_curly) = impl_.assoc_item_list().and_then(|it| it.l_curly_token()) {
107+
edit.add_tabstop_after_token(cap, l_curly);
108+
}
105109
}
106110

107111
insert_impl(impl_, &edit.make_mut(nominal));
@@ -278,7 +282,7 @@ mod tests {
278282
r#"
279283
struct Foo {}
280284
281-
impl ${0:_} for Foo {}
285+
impl ${1:_} for Foo {$0}
282286
"#,
283287
);
284288
}
@@ -293,7 +297,7 @@ mod tests {
293297
r#"
294298
struct Foo<T: Clone> {}
295299
296-
impl<T: Clone> ${0:_} for Foo<T> {}
300+
impl<T: Clone> ${1:_} for Foo<T> {$0}
297301
"#,
298302
);
299303
}
@@ -308,7 +312,7 @@ mod tests {
308312
r#"
309313
struct Foo<'a, T: Foo<'a>> {}
310314
311-
impl<'a, T: Foo<'a>> ${0:_} for Foo<'a, T> {}
315+
impl<'a, T: Foo<'a>> ${1:_} for Foo<'a, T> {$0}
312316
"#,
313317
);
314318
}
@@ -326,7 +330,7 @@ mod tests {
326330
struct Foo<'a, T: Foo<'a>> {}
327331
328332
#[cfg(feature = "foo")]
329-
impl<'a, T: Foo<'a>> ${0:_} for Foo<'a, T> {}
333+
impl<'a, T: Foo<'a>> ${1:_} for Foo<'a, T> {$0}
330334
"#,
331335
);
332336
}
@@ -341,7 +345,7 @@ mod tests {
341345
r#"
342346
struct Defaulted<T = i32> {}
343347
344-
impl<T> ${0:_} for Defaulted<T> {}
348+
impl<T> ${1:_} for Defaulted<T> {$0}
345349
"#,
346350
);
347351
}
@@ -356,7 +360,7 @@ mod tests {
356360
r#"
357361
struct Defaulted<'a, 'b: 'a, T: Debug + Clone + 'a + 'b = String, const S: usize> {}
358362
359-
impl<'a, 'b: 'a, T: Debug + Clone + 'a + 'b, const S: usize> ${0:_} for Defaulted<'a, 'b, T, S> {}
363+
impl<'a, 'b: 'a, T: Debug + Clone + 'a + 'b, const S: usize> ${1:_} for Defaulted<'a, 'b, T, S> {$0}
360364
"#,
361365
);
362366
}
@@ -371,7 +375,7 @@ mod tests {
371375
r#"
372376
struct Defaulted<const N: i32 = 0> {}
373377
374-
impl<const N: i32> ${0:_} for Defaulted<N> {}
378+
impl<const N: i32> ${1:_} for Defaulted<N> {$0}
375379
"#,
376380
);
377381
}
@@ -398,10 +402,10 @@ mod tests {
398402
inner: T,
399403
}
400404
401-
impl<T> ${0:_} for Struct<T>
405+
impl<T> ${1:_} for Struct<T>
402406
where
403407
T: Trait,
404-
{
408+
{$0
405409
}
406410
"#,
407411
);
@@ -476,7 +480,7 @@ mod tests {
476480
mod foo {
477481
struct Bar {}
478482
479-
impl ${0:_} for Bar {}
483+
impl ${1:_} for Bar {$0}
480484
}
481485
"#,
482486
);

src/tools/rust-analyzer/crates/ide-assists/src/tests/generated.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1961,7 +1961,7 @@ struct Ctx<T: Clone> {
19611961
data: T,
19621962
}
19631963
1964-
impl<T: Clone> ${0:_} for Ctx<T> {}
1964+
impl<T: Clone> ${1:_} for Ctx<T> {$0}
19651965
"#####,
19661966
)
19671967
}

src/tools/rust-analyzer/docs/book/src/assists_generated.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ fn main() {
280280

281281

282282
### `apply_demorgan_iterator`
283-
**Source:** [apply_demorgan.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/apply_demorgan.rs#L132)
283+
**Source:** [apply_demorgan.rs](https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-assists/src/handlers/apply_demorgan.rs#L147)
284284

285285
Apply [De Morgan's law](https://en.wikipedia.org/wiki/De_Morgan%27s_laws) to
286286
`Iterator::all` and `Iterator::any`.
@@ -2161,7 +2161,7 @@ struct Ctx<T: Clone> {
21612161
data: T,
21622162
}
21632163

2164-
impl<T: Clone> ${0:_} for Ctx<T> {}
2164+
impl<T: Clone> ${1:_} for Ctx<T> {}
21652165
```
21662166

21672167

0 commit comments

Comments
 (0)