Commit graph

748 commits

Author SHA1 Message Date
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
k-nasa
b50cb5c261 Remove neesless clone 2021-10-10 10:50:51 +09:00
Aleksey Kladov
afacdd612d internal: update expect 2021-10-09 17:17:16 +03:00
k-nasa
aeee70397e Apply make_else_arm to general case 2021-10-09 13:19:21 +09:00
k-nasa
388525fa0d Add test casee 2021-10-09 11:13:27 +09:00
bors[bot]
4675410f07
Merge #10477 #10482
10477: parser: fix parsing of macro call inside generic args r=Veykril a=cynecx



10482: fix: fix `inline_call` trying to use an uncached syntax node in Semantics r=Veykril a=Veykril

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

Co-authored-by: cynecx <me@cynecx.net>
Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-10-07 13:05:18 +00:00
Lukas Wirth
12465a8a3c Expose HasSource::source through Semantics with caching behaviour 2021-10-07 15:00:14 +02:00
crauzer
1161fa45af fix tests 2021-10-06 20:45:18 +02:00
crauzer
765d7f20f9 add sourcegen 2021-10-06 20:23:22 +02:00
crauzer
05e58afde2 Add replace_try_expr_with_match assist 2021-10-06 20:11:00 +02:00
bors[bot]
4cfe237a56
Merge #10459
10459: feat: Add generate constant assist r=Veykril a=longfangsong

Close #10330.
![demo(1)](https://user-images.githubusercontent.com/13777628/135885262-c80de86f-5555-4f84-9508-822243f8a876.gif)



Co-authored-by: longfangsong <longfangsong@icloud.com>
Co-authored-by: 龙方淞 <longfangsong@icloud.com>
2021-10-06 09:38:58 +00:00
longfangsong
3fde682bcf cleanup 2021-10-06 10:14:12 +08:00
龙方淞
7228dbadca
Update crates/ide_assists/src/handlers/generate_constant.rs
Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-10-06 10:06:51 +08:00
龙方淞
fab238adf6
Update crates/ide_assists/src/handlers/generate_constant.rs
Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-10-06 10:06:46 +08:00
bors[bot]
86c534f244
Merge #10440
10440: Fix Clippy warnings and replace some `if let`s with `match` r=Veykril a=arzg

I decided to try fixing a bunch of Clippy warnings. I am aware of this project’s opinion of Clippy (I have read both [rust-lang/clippy#5537](https://github.com/rust-lang/rust-clippy/issues/5537) and [rust-analyzer/rowan#57 (comment)](https://github.com/rust-analyzer/rowan/pull/57#discussion_r415676159)), so I totally understand if part of or the entirety of this PR is rejected. In particular, I can see how the semicolons and `if let` vs `match` commits provide comparatively little benefit when compared to the ensuing churn.

I tried to separate each kind of change into its own commit to make it easier to discard certain changes. I also only applied Clippy suggestions where I thought they provided a definite improvement to the code (apart from semicolons, which is IMO more of a formatting/consistency question than a linting question). In the end I accumulated a list of 28 Clippy lints I ignored entirely.

Sidenote: I should really have asked about this on Zulip before going through all 1,555 `if let`s in the codebase to decide which ones definitely look better as `match` :P

Co-authored-by: Aramis Razzaghipour <aramisnoah@gmail.com>
2021-10-05 08:58:40 +00:00
Aramis Razzaghipour
9583dd5725
Replace if let with match where appropriate 2021-10-05 09:00:21 +11:00
Aramis Razzaghipour
f29796da61
Replace if let Some(_) = foo with if foo.is_some() 2021-10-05 09:00:18 +11:00
longfangsong
4d1a4dc0d6 Add generate_constant assist 2021-10-04 23:53:32 +08:00
Aramis Razzaghipour
eff195852d
Fix miscellaneous Clippy lints 2021-10-03 23:53:30 +11:00
bors[bot]
ebe6c38a44
Merge #10438
10438: minor: Simplify r=Veykril a=Veykril

bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-10-03 11:06:06 +00:00
Lukas Wirth
0943c4be8b minor: Simplify 2021-10-03 13:05:42 +02:00
bors[bot]
0618a6f184
Merge #10436
10436: fix: await insertion with try_expr during extract_function r=Veykril a=feniljain

Fixing  #10333

Co-authored-by: vi_mi <fenil.jain2018@vitstudent.ac.in>
2021-10-03 10:07:58 +00:00
vi_mi
61643513b6 fix: await insertion with try_expr during extract_function 2021-10-03 09:41:21 +00:00
bors[bot]
13ec077b91
Merge #10437
10437: fix: Fix extract_variable not allowing to extract macro calls r=Veykril a=Veykril

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

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-10-03 09:10:33 +00:00
Lukas Wirth
a359a1f2e3 Fix extract_variable not allowing to extract macro calls 2021-10-03 11:09:49 +02:00
Aleksey Kladov
d5c5b7cd12 internal: remove deprecated method 2021-10-02 15:28:55 +03:00
Aleksey Kladov
9c74a5b2c0 minor: reduce duplication 2021-10-02 15:24:32 +03:00
Aleksey Kladov
46eb03d99a internal: use naming that matches intended use-case 2021-10-02 12:18:18 +03:00
Benjamin Coenen
2947957199 feat(assist): add new assist to unwrap the result return type
Signed-off-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
2021-10-01 21:24:03 +02:00
Lukas Wirth
816fafd997 Parenthesize expressions in if_to_bool_then assist where required 2021-10-01 12:19:01 +02:00
bors[bot]
26a10767cb
Merge #10401
10401: minor: Test runnables check for test prefix and suffix in attributes only r=Veykril a=Veykril

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

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-09-30 16:03:03 +00:00
Lukas Wirth
b742dd313e Test runnables check for test prefix and suffix in attributes only 2021-09-30 18:02:44 +02:00
bors[bot]
cd9f27d424
Merge #10382
10382: fix: Fix inline_call breaking RecordExprField shorthands r=Veykril a=Veykril

Fixes #10349
bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-09-28 17:23:11 +00:00
Lukas Wirth
774a8cf08b Fix inline_call breaking RecordExprField shorthands 2021-09-28 19:22:32 +02:00
longfangsong
7e3224f419 Address comments 2021-09-28 10:20:35 +08:00