Commit Graph

982 Commits

Author SHA1 Message Date
Jeroen Vannevel
778e71b15f
fmt 2022-01-07 12:40:41 +00:00
Jeroen Vannevel
76e0429048
concise filtering 2022-01-07 12:34:03 +00:00
Jeroen Vannevel
734193bc23 support const params 2022-01-07 01:09:32 +00:00
Jeroen Vannevel
b6201051b2 Count the type parameters only 2022-01-07 01:02:16 +00:00
Laurențiu Nicola
e14d9208f5 Move pretty-printing test out of assist 2022-01-06 16:38:25 +02:00
Côme ALLART
c2d3f90886 fix: remove brackets if no generic types 2022-01-06 01:51:04 +01:00
bors[bot]
2e33bf23c9
Merge #11204
11204: fix: `replace_qualified_name_with_use` does not use full item path for replacements r=Veykril a=Veykril

bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2022-01-05 22:47:30 +00:00
Lukas Wirth
2d33cdf188 fix: replace_qualified_name_with_use does not use full item path for replacements 2022-01-05 23:46:58 +01:00
bors[bot]
ada51f2ac4
Merge #11195 #11202
11195: Correctly pass through reference modifiers when extracting a variable r=Veykril a=Vannevelj

Fixes https://github.com/rust-analyzer/rust-analyzer/issues/10034

This will parse the field expression and look at whether it is marked `&` or `&mut` and include a modifier if appropriate. The original issue only mentions `&mut params` but I've found that this issue also occurs for `&mut locals` as well as `&params` and `&locals` so I've also added tests for them.

I'd definitely be interested in hearing where I can make my code more idiomatic for Rust.

11202: fix: Fix `apply_demorgan` assist hanging for certain binary expressions r=Veykril a=Veykril

Fixes https://github.com/rust-analyzer/rust-analyzer/issues/10963
bors r+

Co-authored-by: Jeroen Vannevel <jer_vannevel@outlook.com>
Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2022-01-05 21:30:50 +00:00
Lukas Wirth
b92ed115c1 fix: Fix apply_demorgan assist hanging for certain binary expressions 2022-01-05 22:30:19 +01:00
Jeroen Vannevel
035a373a6a
removed double matching 2022-01-05 21:16:24 +00:00
Jeroen Vannevel
771c87f890
no PathExpr arm 2022-01-05 21:12:09 +00:00
Jeroen Vannevel
8c0b848694
.clone() over .to_owned() 2022-01-05 21:10:03 +00:00
Jeroen Vannevel
2724b35490
less wordy ref_kind assignment 2022-01-05 21:08:46 +00:00
bors[bot]
149981fbfc
Merge #11200
11200: Always put a space after dyn in macro pretty-printing r=Veykril a=jplatte

Fixes #11100.

Co-authored-by: Jonas Platte <jplatte+git@posteo.de>
2022-01-05 20:04:49 +00:00
Jonas Platte
f5b789b1dc
Add failing test case for issue 11100 2022-01-05 18:04:36 +01:00
Jeroen Vannevel
053ae2452c
removed trailing whitespace 2022-01-05 02:16:22 +00:00
Jeroen Vannevel
abab0154b6
comment 2022-01-05 01:48:57 +00:00
Jeroen Vannevel
fa0afb9576
additional test for a reference local (on top of mutable reference local) 2022-01-05 01:36:04 +00:00
Jeroen Vannevel
4c1a1b2570
failing test for a reference local 2022-01-05 01:27:15 +00:00
Jeroen Vannevel
cd5ad4e500
Don't include a ref if none was declared 2022-01-05 01:18:55 +00:00
Jeroen Vannevel
817f47828c
support ref params as well 2022-01-05 01:15:54 +00:00
Jeroen Vannevel
056e18fcbd
correctly handle mutable references 2022-01-05 01:03:27 +00:00
Côme ALLART
4a5341e044 fix(gen-doc-assist): remove lifetimes in description of new 2022-01-05 00:23:36 +01:00
bors[bot]
ac3ea3e81c
Merge #11112
11112: Evaluate constants in array repeat expression r=HKalbasi a=HKalbasi

cc #8655 

Co-authored-by: hkalbasi <hamidrezakalbasi@protonmail.com>
2022-01-04 21:51:37 +00:00
hkalbasi
75c2acae6e Evaluate constants in array repeat expression 2022-01-05 01:17:01 +03:30
Jeroen Vannevel
ec61abbe93 reduced the tests to their bare essence 2022-01-04 10:11:04 +00:00
Jeroen Vannevel
5beddf93e7 additional test without further usages 2022-01-04 02:12:53 +00:00
Jeroen Vannevel
95cabfd722 Correctly pass through mutable references when extracting a function 2022-01-04 01:48:08 +00:00
bors[bot]
7409880a07
Merge #11061
11061: Support "move if to guard" for if else chains r=weirane a=weirane

The idea is to first parse the if else chain into a vector of `(Condition, BlockExpr)`s until we reach an iflet branch, an else branch, or the end (the tail). Then add the match arms with guard for the vector, and add the tail with no if guard.

Because the whole original match arm is replaced and the generated code doesn't have redundent commas, I removed redundent commas in some test cases.

Closes #11033.

Co-authored-by: Wang Ruochen <wrc@ruo-chen.wang>
2022-01-03 17:59:00 +00:00
Wang Ruochen
95145d5ab6
Update generated tests 2022-01-03 09:48:50 -08:00
Wang Ruochen
a19a32488d
Don't add pattern if there is a catch all afterwards 2022-01-03 09:38:45 -08:00
Dániel Buga
2e472bb746 Fix replace_match_with_if_let removing blocks with modifiers
Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2022-01-03 14:07:34 +01:00
Kirill Bulatov
03291db801 Allow adding partially resolved types 2022-01-03 01:34:33 +02:00
Laurențiu Nicola
53ddf48df4 Avoid collect_vec from itertools 2022-01-02 12:06:14 +02:00
Laurențiu Nicola
fdf1136e79 Replace folds with for loops 2022-01-02 12:05:35 +02:00
Jeroen Vannevel
b04c4e76df formatting 2021-12-28 18:52:12 +00:00
Jeroen Vannevel
e299fd5475 turbo fish supports multiple type arguments 2021-12-28 18:41:34 +00:00
Aleksey Kladov
660cf34d8c dead code 2021-12-28 19:13:30 +03:00
Petr Nevyhoštěný
d9b3242bcd Fix generic type substitution in impl trait with assoc type 2021-12-23 10:16:24 +01:00
Wang Ruochen
be5205170c
Update comment 2021-12-22 14:17:43 -08:00
Wang Ruochen
44edf63edd
Add pattern when there's no else branch 2021-12-22 10:18:37 -08:00
Wang Ruochen
2bd2960fda
Don't support if-let branches 2021-12-21 16:51:26 -08:00
Wang Ruochen
d0986cd96b
Move variables into the closure 2021-12-21 16:48:02 -08:00
Lukas Wirth
539b0c2582 fix: Fix inline local assist not working in let stmt initializer 2021-12-21 14:03:59 +01:00
Laurențiu Nicola
01143c6600 Fix typo in reformat number assist label 2021-12-21 09:45:20 +02:00
bors[bot]
f46731a230
Merge #11028
11028: Bump MSRV (1.57) r=Veykril a=iDawer

This bumps MSRV on all crates to 1.57 except `la-arena`

#10986 requires >=1.57 

Co-authored-by: iDawer <ilnur.iskhakov.oss@outlook.com>
2021-12-20 13:45:35 +00:00
bors[bot]
2ca3834c9f
Merge #11062
11062: fix: Don't say "a reference to" for `Copy` types in the generate getter assist r=Veykril a=patrick-gu

This changes the generate getter assist to not say "a reference to" in the documentation stub if the type is `Copy`, as the getter does not return a reference.

To determine whether the type is `Copy`, I have added an `is_copy` method to `ReferenceConversion`.

Co-authored-by: patrick-gu <55641350+patrick-gu@users.noreply.github.com>
2021-12-20 09:14:38 +00:00
patrick-gu
76b50f14f7 Don't say "a reference to" for Copy types
This changes the generate getter assist to not say "a reference to" in the documentation stub if the type is Copy, as the getter does not return a reference.
2021-12-19 17:28:31 -08:00
Wang Ruochen
71676ae89d
Support "move if to guard" for if else chains 2021-12-19 09:26:52 -08:00
ucrhh
b289f13c75 fix unwrap_block by removing double trimming 2021-12-18 23:19:53 +01:00
Aleksey Kladov
a022ad68c9 internal: move all the lexing to the parser crate 2021-12-18 17:20:38 +03:00
Laurențiu Nicola
6c799dac1e Fix some clippy lints 2021-12-17 17:46:20 +02:00
Laurențiu Nicola
8ad7c0439c Remove needless clones 2021-12-17 17:35:10 +02:00
Wang Ruochen
ee079561b1
Add comma for "move if to guard" 2021-12-15 15:26:24 -08:00
bors[bot]
4ec6bd6206
Merge #11017
11017: Support "move if to guard" with an else branch r=Veykril a=weirane

Support the assist `move_arm_cond_to_match_guard` when there is an else branch.

I have two questions:
1. How to indent the first line of a match arm? `matcharm.indent()` doesn't seem to work. so I hard coded four spaces here:
95a0de85d5/crates/ide_assists/src/handlers/move_guard.rs (L162-L163)

2. I find a little issue in the original implementation, this code
```rust
let y = match 92 {
    x => {
        if x == 0 {$0
            false
        }
    }
    _ => true,
};
```
will be transformed to
```rust
let y = match 92 {
    x if x == 0 => false
    _ => true,
};
```
a comma is missing after the `false`. Should I also fix that? Or this can go in a separate PR.

Closes #10997.

Co-authored-by: Wang Ruochen <wrc@ruo-chen.wang>
2021-12-15 23:04:51 +00:00
Wang Ruochen
e8d0742997
Add coverage marks 2021-12-15 14:44:47 -08:00
iDawer
676744be6e Bump MSRV (1.57) 2021-12-16 01:56:12 +05:00
Wang Ruochen
95a0de85d5
Support "move if to guard" with an else branch 2021-12-14 10:27:44 -08:00
Lukas Wirth
901c7c7277 match_ast! takes a pattern to allow underscore usage 2021-12-14 12:44:31 +01:00
bors[bot]
791722b70a
Merge #10998
10998: Add number representation assists r=Veykril a=errx

Reimplemented assists from this PR https://github.com/rust-analyzer/rust-analyzer/pull/3683 with current APIs.
![image](https://user-images.githubusercontent.com/462486/145726792-47700215-26f2-4fdc-9520-63d1487901e5.png)
![image](https://user-images.githubusercontent.com/462486/145726802-f528a2f7-9159-41d3-b459-fc3fae033e60.png)


I've decided not to add options about size of the groups so behaviour is similar to clippy's. 
Minimal number length is also taken from clippy.


Co-authored-by: Oleg Matrokhin <matrokhin@gmail.com>
2021-12-13 18:49:06 +00:00
Oleg Matrokhin
60605a24d4 Reuse results from split_into_parts() 2021-12-13 21:16:04 +03:00
Oleg Matrokhin
8b03b41b7a Add number representation assists 2021-12-13 19:35:38 +03:00
bors[bot]
e1f3982a5f
Merge #11001
11001: minor: fixup generate assist priorities r=Veykril a=Veykril

Fixes https://github.com/rust-analyzer/rust-analyzer/issues/10996
bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-12-13 15:51:54 +00:00
bors[bot]
3f550d2e38
Merge #11000
11000: fix: insert whitespaces into assoc items for assist when macro generated r=Veykril a=Veykril

This is obviously only a temporary hack which still produces ugly looking items, but as long as the syntax is valid one can at least have rustfmt fix the formatting again. 
Fixes https://github.com/rust-analyzer/rust-analyzer/issues/6588
bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-12-13 15:43:12 +00:00
Lukas Wirth
1cef532c4d minor: fixup generate assist priorities 2021-12-13 16:42:21 +01:00
Lukas Wirth
749eeef3e7 fix: insert whitespaces into assoc items for assist when macro generated 2021-12-13 16:35:32 +01:00
Lukas Wirth
328419534d Move ws insert rendering for macro expansion into ide_db 2021-12-13 15:55:13 +01:00
bors[bot]
40159150aa
Merge #10951
10951: feat: assist to generate documentation templates r=Veykril a=numero-744

Closes #10878, #1915 and #4767

Full description is in #10878, better read [the tests](https://github.com/rust-analyzer/rust-analyzer/pull/10951/files#diff-7a64e2efb66b2625443340fcbc96d531baff12c17cc0aaf51885ea94f67de254R424) to understand what this feature does.

- [x] There is one remaining thing about non-`pub` functions, what do you think about it?
- [x] In this PR [empty examples are generated](https://github.com/rust-analyzer/rust-analyzer/pull/10951/files#diff-7a64e2efb66b2625443340fcbc96d531baff12c17cc0aaf51885ea94f67de254R99) for `trait` functions, but maybe no examples should be provided at all.
- [x] If there is already a documentation, add another one with a separator ([currently done](https://github.com/rust-analyzer/rust-analyzer/pull/10951/files#diff-7a64e2efb66b2625443340fcbc96d531baff12c17cc0aaf51885ea94f67de254R74)) or simply disable this assist?
- [x] I will check once more that the generated examples are correct (ie. they are easy to fill before that they are built and tested)

Comments appreciated 😄 

Co-authored-by: Côme ALLART <come.allart@etu.emse.fr>
2021-12-11 22:58:49 +00:00
Côme ALLART
0e89f2f346 feat: remove should_panic example generation 2021-12-11 22:46:54 +01:00
Côme ALLART
9e53db274b refactor: use hir to test if a value is returned 2021-12-11 20:52:14 +01:00
Côme ALLART
80a68685db refactor: use Itertools::intersperse 2021-12-11 20:41:23 +01:00
Côme ALLART
7266fdb5a4 refactor: use hir to compare returned and self types 2021-12-11 20:33:08 +01:00
bors[bot]
48cd733c9e
Merge #10956 #10986
10956: minor: Bump deps r=Veykril a=lnicola

bors r+

10986: fix: Fix lint completions not working for unclosed attributes r=Veykril a=Veykril

Fixes #10682
Uses keywords and nested `TokenTree`s as a heuristic to figure out when to stop parsing in case the attribute is unclosed which should work pretty well as attributes are usually followed by either of those.
bors r+

Co-authored-by: Laurențiu Nicola <lnicola@dend.ro>
Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-12-11 14:58:07 +00:00
bors[bot]
d97f2f6b9b
Merge #10976
10976: fix: Show case-insensitive exact matches instead of fuzzy flyimport for short paths r=Veykril a=Veykril

And raise the fuzzy trigger from 2 to 3 chars. This way we keep the ability of flyimporting short names like `Rc`.
Fixes https://github.com/rust-analyzer/rust-analyzer/issues/6917
bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-12-11 13:50:55 +00:00
Lukas Wirth
143a30aa51 Show case-insensitive exact matches instead of fuzzy flyimport for short paths 2021-12-11 14:47:11 +01:00
Lukas Wirth
c81aa68afe Don't show trait flyimports for impl trait and placeholders 2021-12-10 19:18:21 +01:00
Côme ALLART
9c0f9d02bf feat: trait fn: add panicking example only if default panicks 2021-12-10 15:53:43 +01:00
Côme ALLART
f5e0998402 refactor: use hir to check if fn in trait/impl 2021-12-10 15:16:04 +01:00
Côme ALLART
c3d151ada6 fix: check correctly if function is exported 2021-12-10 14:42:31 +01:00
Côme ALLART
dc4e4c7daa fix: add mod files in path in generated examples 2021-12-07 23:34:53 +01:00
Côme ALLART
220137f1cf fix: disable assist for documented functions 2021-12-07 18:02:18 +01:00
Laurențiu Nicola
9a624abc84 Bump deps 2021-12-07 13:15:14 +02:00
Côme ALLART
3a82548c5e fix: reduce assist scope: pub fn's in pub modules 2021-12-06 23:33:24 +01:00
Côme ALLART
d55d3b63cb fix: format assist doc for sourcegen_assists_docs 2021-12-06 19:04:44 +01:00
Côme ALLART
998b91af9c feat: assist to generate documentation templates 2021-12-06 18:32:25 +01:00
rainy-me
79b4e67b4f fix: defer condition construction 2021-12-04 04:50:06 +09:00
rainy-me
fb90bf9cad feat: handle while let to loop 2021-12-04 03:19:19 +09:00
Skyler Rain Ross
5b59a5eca8
refactor(assist/add_return_type): avoid threading needs_whitespace 2021-12-02 10:46:07 -08:00
Skyler Rain Ross
e031267602
fix: add return type works when there's missing whitespace 2021-12-02 09:28:18 -08:00
rainy-me
0bb08ccb8f fix: derive path handling 2021-11-25 00:21:29 +09:00
bors[bot]
b69eee6487
Merge #10809
10809: fix: don't discard formatting of `use` lines r=Veykril a=iDawer

Use mutable syntax trees in `merge_imports`, `split_imports`. This tries to resolve #9013. But I haven't much managed to simplify code of merging.

Also resolve #9361. It reuses a use tree under the cursor so that comments+indentation are preserved. Merged trees are just appended to the end.

This touches bunch of tests. I removed the sorting of use trees as it needs a proper implementation that takes into account comments and line wrapping. I think it is rustfmt's job or at least until we get a close implementation.

Co-authored-by: iDawer <ilnur.iskhakov.oss@outlook.com>
2021-11-22 14:29:24 +00:00
rainy-me
ebffaa4274 fix: check inline left of binary_expression 2021-11-21 01:48:04 +09:00
iDawer
601413df8f Use mutable syntax trees in merge_imports, split_imports 2021-11-19 20:02:27 +05:00
bors[bot]
6c7be6cd84
Merge #10734
10734: fix: add generic parameters in convert to manual impl assist r=Veykril a=TheDoctor314

Fixes #10041.

Co-authored-by: TheDoctor314 <64731940+TheDoctor314@users.noreply.github.com>
2021-11-16 11:27:11 +00:00
Lukas Wirth
92f7db447c minor: Lift out FxIndex{Map/Set} types into ide_db 2021-11-16 12:15:47 +01:00
TheDoctor314
58a24de7d8 Fix impl_def_from_trait
Revert "Fix `impl_trait` function to emit correct ast"

This reverts commit 55a4813151.

Fix `impl_def_from_trait`

It now generates the correct `ast::Impl` using
`generate_trait_impl_text` and parses it to form the right node (copied
from the private fn 'make::ast_from_text').
2021-11-15 22:28:22 +05:30
rainy-me
1f3da38d94 adjust test case and stop deleting newline 2021-11-14 20:56:28 +09:00
rainy-me
c9949c040c add missing match arms end of last arm 2021-11-14 02:32:10 +09:00
TheDoctor314
55a4813151 Fix impl_trait function to emit correct ast
`impl_trait` code copied from `generate_impl_text_inner` to properly
handle the bounds for the generic parameters.
2021-11-11 14:16:59 +05:30
TheDoctor314
e0e8d877c0 Add generic bounds in test 2021-11-11 14:16:29 +05:30
Lukas Wirth
7776aad166 internal: Flatten Definition::ModuleDef variant 2021-11-11 00:05:53 +01:00
TheDoctor314
05b368f065 Add generic parameters for manual impl assist
The `impl_trait` function takes an optional `GenericParamList` to create
the trait impl.
2021-11-10 12:53:48 +05:30
TheDoctor314
4f93fa1213 Add failing tests for generic struct 2021-11-10 12:53:48 +05:30
bors[bot]
c96481e25f
Merge #10691
10691: minor: Use array `into_iter` in more places r=lnicola a=lnicola

bors r+

Co-authored-by: Laurențiu Nicola <lnicola@dend.ro>
2021-11-04 05:52:05 +00:00
Laurențiu Nicola
139bf9b4e1 Use array into_iter in more places 2021-11-04 07:51:20 +02:00
Lukas Wirth
96db0d8bdd Add Semantics::original_ast_node for upmapping nodes out of macro files 2021-11-03 21:12:36 +01:00
Lukas Wirth
7fdbdc4ab2 Enable auto-import and qualify-path in derive attributes 2021-10-28 18:40:38 +02:00
Lukas Wirth
3018ffd85e Refactor ide handling for paths in derive inputs 2021-10-28 16:47:19 +02:00
bors[bot]
210a1d5ece
Merge #10629
10629: Add assist for replacing turbofish with explicit type. r=Veykril a=terrynsun

Converts `::<_>` to an explicit type assignment.

```
let args = args.collect::<Vec<String>>();
```
->
```
let args: Vec<String> = args.collect();
```

Closes #10285

Co-authored-by: Terry Sun <terrynsun@gmail.com>
2021-10-27 21:40:28 +00:00
Terry Sun
d800a1bc93 fixup! rustfmt 2021-10-27 10:58:31 -07:00
Terry Sun
3bbd61d674 fixup! delay to_string() until assist is called 2021-10-27 10:46:25 -07:00
Terry Sun
6abdbdd0c9 fixup! narrow range; method calls; check for only one type 2021-10-26 17:50:25 -07:00
Lukas Wirth
a2365ea18a fix: fix extract_variable not working on macro_call 2021-10-25 21:46:44 +02:00
Terry Sun
324d7d33e8 Add assist for replacing turbofish with explicit type.
Converts `::<_>` to an explicit type assignment.

```
let args = args.collect::<Vec<String>>();
```
->
```
let args: Vec<String> = args.collect();
```

Closes #10285
2021-10-24 17:38:45 -07:00
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
Yoshua Wuyts
f84b0b3242 fix ret type in generic 2021-10-14 18:38:52 +02:00
Yoshua Wuyts
987ab1feda implement feedback from review 2021-10-14 18:19:20 +02:00
Anton Firszov
a17a132617 Narrow add_missing_match_arms assist range 2021-10-14 18:15:00 +02:00
Yoshua Wuyts
68ffe91526 Add support for tuple structs 2021-10-14 14:18:12 +02:00
Yoshua Wuyts
8b6ea8ee86 Update label names 2021-10-14 13:52:31 +02:00
Yoshua Wuyts
680dd9d952 Enable delegation generation for complex types 2021-10-14 13:23:46 +02:00
bors[bot]
641fa374ed
Merge #10309
10309: use `ControlFlow` in "extract function" assist r=Veykril a=dzvon

Fixes #10272 

Co-authored-by: Dezhi Wu <wu543065657@163.com>
2021-10-14 10:47:11 +00:00
Yoshua Wuyts
c9882c8002 Get a make version working! 2021-10-14 12:34:31 +02:00
Yoshua Wuyts
efb4d45ebc Update generate_delegate.rs 2021-10-13 23:59:23 +02:00
Yoshua Wuyts
c14a12edd7 create function 2021-10-13 20:13:36 +02:00
Ryan Levick
0ff89deb69 Add basic support for delegation 2021-10-13 18:05:09 +02:00
k-nasa
bd9bab87ed fix 2021-10-13 23:07:49 +09:00
Dezhi Wu
214e7cc69d merge use statement 2021-10-13 21:24:17 +08:00
Dezhi Wu
93ae993ec4 resolve ControlFlow ourself instead of hard coding. 2021-10-13 21:19:41 +08:00
k-nasa
bc29b75b92 update calc_depth 2021-10-13 22:06:53 +09:00
k-nasa
b3930599a7 calc depth 2021-10-13 22:02:39 +09:00
Lukas Wirth
ccad89a2db Make AssistContext::frange private 2021-10-13 14:39:37 +02:00
k-nasa
ef9c4b666f move test case 2021-10-13 21:03:01 +09:00
k-nasa
a6a052f407 Revert "Apply make_else_arm to general case"
This reverts commit aeee70397e.
2021-10-13 20:36:04 +09:00
Dezhi Wu
5818358bbf import ControlFlow to the module 2021-10-13 09:09:07 +08:00
Dezhi Wu
f888e85f79 use ControlFlow::Break(_) pattern 2021-10-13 09:06:47 +08:00
Dezhi Wu
971a271840 use ControlFlow in "extract function" assist 2021-10-13 09:06:47 +08:00
Lukas Wirth
086563f751 Fix AssistContext panic on sole whitespace selection 2021-10-12 21:29:08 +02:00
bors[bot]
a871da3693
Merge #10529
10529: Generate `PartialOrd` implementations r=Veykril a=yoshuawuyts

_co-authored with `@rylev_`

This closes #5946 (which should've been closed already, lol). This PR makes it so we generate `PartialOrd` code implementations where possible. This is the last of Rust's built-in traits that was missing codegen.

After this has been merged we should look at moving the tests to a better spot, and maybe cleaning up the implementation somewhat (it's rather copy-pasty at the moment).

Either way, this finishes up the functionality. Thanks heaps!

Co-authored-by: Yoshua Wuyts <yoshuawuyts@gmail.com>
2021-10-12 17:32:58 +00:00
bors[bot]
d56c8796d6
Merge #10532
10532: Rename `descend_into_macros` Function per FIXME comment r=Veykril a=mirkoRainer

This renames `descend_into_macros` to  `descend_into_macros_single` and `descend_into_macros_many` into `descend_into_macros`.
 However, this does not touch a function in `SemanticsImpl` of same name.

I was prompted to do this per a FIXME comment, which is removed in this PR.

Co-authored-by: Mirko Rainer <mirkorainer@outlook.com>
2021-10-12 17:24:50 +00:00
Mirko Rainer
eccfa1645b Saw a FIXME comment and decided to fix it.
This renames `descend_into_macros` to  `descend_into_macros_single` and `descend_into_macros_many` into `descend_into_macros`.
 However, this does not touch a function in `SemanticsImpl` of same name.
2021-10-12 11:52:31 -04:00
Yoshua Wuyts
601ed3a10d Simplify generated PartialOrd code 2021-10-12 17:44:57 +02:00
Yoshua Wuyts
5f72bd81a9 impl PartialOrd codegen for tuple enum 2021-10-12 17:05:59 +02:00
Yoshua Wuyts
77b5fe6c52 impl PartialOrd codegen for record enum 2021-10-12 17:05:59 +02:00
Yoshua Wuyts
95eff43cc1 impl PartialOrd codegen for C-style enums 2021-10-12 17:05:58 +02:00
Yoshua Wuyts
c0263fb07a impl PartialOrd codegen for struct records 2021-10-12 17:05:58 +02:00
Yoshua Wuyts
6941fdc49f impl PartialOrd codegen for tuple records 2021-10-12 17:05:58 +02:00
Yoshua Wuyts
bc6aee51b0 init partialord 2021-10-12 17:05:58 +02:00
Lukas Wirth
03fcf1b246 Make selections in assists with trailing/leading whitespace more forgiving 2021-10-12 14:41:59 +02:00
bors[bot]
64ca0f63bf
Merge #10504
10504: Remove needless clone r=lnicola a=k-nasa

## Why

Delete clones for efficiency

## What

- I erased unnecessary clones


Co-authored-by: k-nasa <htilcs1115@gmail.com>
2021-10-10 07:17:52 +00:00