Commit Graph

717 Commits

Author SHA1 Message Date
Laurențiu Nicola
8457ae34bd Set MSRV 2021-10-23 15:07:11 +03:00
bors[bot]
fe7c516084
Merge #10602
10602: Add qualify method call assist r=Veykril a=qepasa

This adds `qualify_method_call` assist that allows to replace a method (or trait) call that resolves with its fully qualified path.

For example, for stuct method:
```rust
struct Foo;
impl Foo {
    fn foo(&self) {}
}
```
```
let foo = Foo {};
foo.fo$0o();
```

becomes
```rust
let foo = Foo {};
Foo::foo(&foo);
```

for a trait method:

```rust
struct Foo;
trait FooTrait {
    fn foo(&self) {}
}
impl FooTrait for Foo {
    fn foo(&self) {}
}
```
following call:
```rust
let foo = Foo {};
foo.fo$0o();
```

becomes:
```rust
let foo = Foo {};
FooTrait::foo(&foo);
```

fixes #10453 

Co-authored-by: Paweł Palenica <pawelpalenica11@gmail.com>
2021-10-23 08:34:51 +00:00
bors[bot]
a75353e8ac
Merge #9939
9939: feat: Adding extract_module assist r=Veykril a=feniljain

Should solve https://github.com/rust-analyzer/rust-analyzer/issues/9591

Co-authored-by: vi_mi <fenil.jain2018@vitstudent.ac.in>
Co-authored-by: Laurențiu Nicola <lnicola@dend.ro>
2021-10-22 09:29:16 +00:00
vi_mi
3e73a46660 fix: making tests compatible with new trimmed sel_range 2021-10-22 09:16:56 +00:00
Paweł Palenica
bfc86f64c3 apply code review suggestions 2021-10-21 23:42:14 -07:00
Laurențiu Nicola
ca44b6892e Use array IntoIter 2021-10-22 09:23:29 +03:00
Lukas Wirth
1294bfce86 Migrate to edition 2021 2021-10-21 20:10:40 +02:00
Paweł Palenica
91988f46b7 Add generated docs 2021-10-20 23:54:22 -07:00
Paweł Palenica
c2fd0c48a6 cleanup qualify_path 2021-10-20 23:39:25 -07:00
Paweł Palenica
b3d92052ce Remove comment 2021-10-20 23:38:28 -07:00
Paweł Palenica
c8820d342f Run cargo fmt 2021-10-20 23:35:14 -07:00
Paweł Palenica
bb00b09d22 Add qualify method call assist 2021-10-20 23:28:30 -07:00
bors[bot]
6877240fdf
Merge #10563
10563: feat: Make "Generate getter" assist use semantic info r=agluszak a=agluszak

This PR makes "Generate getter" assist use semantic info instead of dealing with types encoded as strings.
Getters for types which are:
- `Copy` no longer return references
- `AsRef<str>` (i.e. `String`) return `&str` (instead of `&String`)
- `AsRef<[T]>` (i.e. `Vec<T>`) return `&[T]` (instead of `&Vec<T>`)
- `AsRef<T>` (i.e. `Box<T>`) return `&T` (instead of `&Box<T>`)
- `Option<T>` return `Option<&T>` (instead of `&Option<T>`)
- `Result<T, E>` return `Result<&T, &E>` (instead of `&Result<T, E>`)

String, Vec, Box and Option were previously handled as special cases.

Closes #10295


Co-authored-by: Andrzej Głuszak <gluszak.andrzej@gmail.com>
2021-10-20 21:02:46 +00:00
Andrzej Głuszak
88e2f07826 Fixes 2021-10-20 22:35:31 +02:00
Andrzej Głuszak
a2242dcf1b Fixes 2021-10-20 21:35:35 +02:00
rainy-me
1ea2c72386 Fix: remove extra newline 2021-10-19 23:46:43 +09:00
rainy-me
adb3729b91 Fix: expand glob import to empty braces if the glob is unused 2021-10-19 23:31:30 +09:00
bors[bot]
580a6c41eb
Merge #10568
10568: fix(assist): fix #10566 and #10567 r=bnjjj a=bnjjj

close #10566
close #10567

Co-authored-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
2021-10-19 12:57:24 +00:00
Benjamin Coenen
3a5147e9fe fix(assist): delete trailing whitespaces
Signed-off-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
2021-10-19 14:54:29 +02:00
bors[bot]
e77fc481ad
Merge #10587
10587: fix: Fix `add_missing_match_arm` panicking on failed upmapping r=Veykril a=Veykril

Closes https://github.com/rust-analyzer/rust-analyzer/issues/10580#issuecomment-946170475

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-10-19 12:16:30 +00:00
Lukas Wirth
7e1d6e5265 fix: Fix add_missing_match_arm panicking 2021-10-19 14:00:24 +02:00
Yoshua Wuyts
e346d32e69 fix Ordering::Equal path 2021-10-18 14:45:24 +02:00
Yoshua Wuyts
41fd824415 Revert "Simplify generated PartialOrd code"
This reverts commit 601ed3a10d.
2021-10-18 14:41:38 +02:00
Yoshua Wuyts
a9ec345cf7 Fix PartialOrd codegen 2021-10-18 12:44:05 +02:00
Benjamin Coenen
7ee1a77235 fix(assist): fix #10566 and #10567
Signed-off-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
2021-10-17 20:24:40 +02:00
Andrzej Głuszak
98676efdc5 Semantic getter 2021-10-17 16:33:14 +02:00
bors[bot]
401daa5f77
Merge #10417
10417: feat(assist): add new assist to unwrap the result return type r=bnjjj a=bnjjj

do the opposite of assist "wrap the return type in Result"

Co-authored-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
Co-authored-by: Coenen Benjamin <benjamin.coenen@hotmail.com>
2021-10-17 13:32:35 +00:00
Coenen Benjamin
ccf05debfe
Update crates/ide_assists/src/handlers/unwrap_result_return_type.rs
Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-10-17 15:24:20 +02:00
Laurențiu Nicola
2bf5f14666 Use trimmed selection range 2021-10-16 13:39:55 +03:00
vi_mi
2efcff7f75 fix: Adding tuple fields in ADT, chore: test action section
unindentation
2021-10-16 13:36:06 +03:00
vi_mi
227490c069 fix: arbitary noop of assist and same file double writes 2021-10-16 13:36:06 +03:00
vi_mi
32b95ea310 feat: Adding extract_module assist 2021-10-16 13:36:06 +03:00
Laurențiu Nicola
cd0c45fdbc Hide private methods in generate_delegate_methods 2021-10-16 13:16:22 +03:00
bors[bot]
c67db1b952
Merge #10543
10543: Narrow add_missing_match_arms assist range r=Veykril a=antonfirsov

Contributes to #10220 with logic borrowed from #10267.

Note: if anyone has recommendations for further analyzers to check, I'm happy to (hard to do it on my own, I'm completely new to the language).

Co-authored-by: Anton Firszov <antonfir@gmail.com>
2021-10-15 16:05:15 +00:00
Anton Firszov
3d9ce6b6ce cov_mark for add_missing_match_arms special cases 2021-10-15 17:53:01 +02:00
Anton Firszov
1c0eed5f97 undo unnecessary test changes 2021-10-15 14:45:11 +02:00
Anton Firszov
cc6eee1b60 cosmetics 2021-10-15 14:36:37 +02:00
Anton Firszov
e25b20e48d update generated.rs 2021-10-15 14:33:44 +02:00
Anton Firszov
a01a4bae18 fix sample + cosmetics + one more test 2021-10-15 14:30:22 +02:00
Anton Firszov
4e16cfbdf4 simple implementation 2021-10-15 13:19:46 +02:00
Anton Firszov
1e303cc035 cursor_inside_simple_match_arm_list -- tests 2021-10-15 12:15:52 +02:00
bors[bot]
3a79af7e27
Merge #10491
10491: Support nested type on replace if let with match r=k-nasa a=k-nasa

## Why

close: https://github.com/rust-analyzer/rust-analyzer/issues/8690

Now, Replacing if-let with match cant't output exhaustive patterns code.
This was because the `else` conversion used specific types (ex. Option, Result) instead of wildcards.

I thought it was more of a problem to generate non-exhaustive patterns than the benefits of using the concrete one.

How about using wildcards in `else`? 
Is this change policy acceptable?

## What

- using wildcards on `make_else_arm`
- Change test cases

Co-authored-by: k-nasa <htilcs1115@gmail.com>
2021-10-14 22:41:06 +00:00
bors[bot]
0af9d1fc8a
Merge #10546
10546: feat: Implement promote_local_to_const assist r=Veykril a=Veykril

Fixes #7692, that is now one can invoke the `extract_variable` assist on something and then follow that up with this assist to turn it into a const.
bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-10-14 19:51:34 +00:00
Lukas Wirth
06286ee90b Implement promotoe_local_to_const assist 2021-10-14 21:49:46 +02:00
Anton Firszov
68a50150d6 use ctx.selection_trimmed() instead of ctx.frange.range 2021-10-14 20:45:10 +02:00
Anton Firszov
0a8a56b77a apply formatting recommendations 2021-10-14 20:38:06 +02:00
Anton Firszov
01e3022521 update generated.rs 2021-10-14 20:35:59 +02:00
Anton Firszov
8cca6242f8 make it work from macro 2021-10-14 20:31:33 +02:00
bors[bot]
e52d47a3b8
Merge #10539
10539: Add "generate delegate methods" assist r=Veykril a=yoshuawuyts

_Co-authored with `@rylev_.`

This patch adds a new assist: "generate delegate method" which creates a method that calls to a method defined on an inner field. Delegation is common when authoring newtypes, and having IDE support for this is the best way we can make this easier to author in Rust, bar adding language-level support for it. Thanks!

Closes #5944.

## Example

__before__
```rust
struct Age(u8);
impl Age {
    fn age(&self) -> u8 {
        self.0
    }
}

struct Person {
    ag$0e: Age,
}
```

__after__
```rust
struct Age(u8);
impl Age {
    fn age(&self) -> u8 {
        self.0
    }
}

struct Person {
    age: Age,
}

impl Person {
    $0fn age(&self) -> u8 {
        self.age.age()
    }
}
```

Co-authored-by: Ryan Levick <me@ryanlevick.com>
Co-authored-by: Yoshua Wuyts <yoshuawuyts@gmail.com>
2021-10-14 18:16:17 +00:00
Anton Firszov
fb47a65ab2 apply necessary test changes 2021-10-14 19:31:27 +02:00