rust-analyzer/crates/ide-assists/src
bors 84ef3cfa91 Auto merge of #17138 - Kohei316:generate-function-assist-for-new, r=Veykril
feature: Make generate function assist generate a function as a constructor if the generated function has the name "new" and is an asscociated function.

close #17050
This PR makes `generate function assist` generate a function as a constructor if the generated function has the name "new" and is an asscociated function.
If the asscociate type is a record struct, it generates the constructor like this.
```rust
impl Foo {
    fn new() -> Self {
        Self { field_1: todo!(), field_2: todo!() }
    }
}
```
If the asscociate type is a tuple struct, it generates the constructor like this.
```rust
impl Foo {
    fn new() -> Self {
        Self(todo!(), todo!())
    }
}
```
If the asscociate type is a unit struct, it generates the constructor like this.
```rust
impl Foo {
    fn new() -> Self {
        Self
    }
}
```
If the asscociate type is another adt, it generates the constructor like this.
```rust
impl Foo {
    fn new() -> Self {
        todo!()
    }
}
```
2024-04-30 12:09:34 +00:00
..
handlers Auto merge of #17138 - Kohei316:generate-function-assist-for-new, r=Veykril 2024-04-30 12:09:34 +00:00
tests Add convert From to TryFrom assist 2024-04-19 08:29:20 +01:00
utils Attempt resolving name collisions 2024-02-29 13:17:45 +00:00
assist_config.rs Add config for preferring / ignoring prelude modules in find_path 2023-11-11 14:56:38 +01:00
assist_context.rs Import serde derives on converting json to struct 2022-08-06 20:12:21 +04:30
lib.rs Add convert From to TryFrom assist 2024-04-19 08:29:20 +01:00
tests.rs internal: Move ide-assists codegen tests into an xtask codegen command 2024-02-28 16:54:44 +01:00
utils.rs Consider exported_name="main" functions in test modules as tests 2024-04-04 14:51:10 +02:00