Commit Graph

696 Commits

Author SHA1 Message Date
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
龙方淞
8f5e8e0a13 Update crates/ide_assists/src/handlers/move_from_mod_rs.rs
Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-09-28 10:20:35 +08:00
longfangsong
0049b5b0bc initial commit 2021-09-28 10:20:29 +08:00
Lukas Wirth
b6ed91a6de Rename *Owner traits to Has* 2021-09-27 12:54:24 +02:00
Aleksey Kladov
2bf81922f7 internal: more reasonable grammar for blocks
Consider these expples

        { 92 }
  async { 92 }
    'a: { 92 }
   #[a] { 92 }

Previously the tree for them were

  BLOCK_EXPR
    { ... }

  EFFECT_EXPR
    async
    BLOCK_EXPR
      { ... }

  EFFECT_EXPR
    'a:
    BLOCK_EXPR
      { ... }

  BLOCK_EXPR
    #[a]
    { ... }

As you see, it gets progressively worse :) The last two items are
especially odd. The last one even violates the balanced curleys
invariant we have (#10357) The new approach is to say that the stuff in
`{}` is stmt_list, and the block is stmt_list + optional modifiers

  BLOCK_EXPR
    STMT_LIST
      { ... }

  BLOCK_EXPR
    async
    STMT_LIST
      { ... }

  BLOCK_EXPR
    'a:
    STMT_LIST
      { ... }

  BLOCK_EXPR
    #[a]
    STMT_LIST
      { ... }
2021-09-26 19:16:09 +03:00
bors[bot]
c51a3c78cf
Merge #10358
10358: internal: Remove inherent methods from ast nodes that do non-syntactic complex tasks  r=Veykril a=Veykril



Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-09-26 14:49:25 +00:00
Lukas Wirth
151afdfe5c Remove inherent methods from ast node that carry semantic meaning 2021-09-26 16:49:03 +02:00
bors[bot]
cd7b26c6eb
Merge #10352
10352: feat: Implement inline callers assist r=Veykril a=Veykril

Fixes #7242

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-09-26 14:02:25 +00:00
Lukas Wirth
215a077ee4 Remove imports when inlining all calls in a file 2021-09-26 16:01:54 +02:00
Lukas Wirth
79c70d0ad3 Simplify 2021-09-26 14:56:43 +02:00
Lukas Wirth
1a50f904ef Reject recursive calls in inline_call 2021-09-26 14:55:03 +02:00
Lukas Wirth
1ccb21a0ca feat: Implement inline callers assist 2021-09-25 18:39:43 +02:00
bors[bot]
d401f2a062
Merge #10211
10211: assists: Promote module to folder r=jonas-schievink a=longfangsong

Close part of #10143.

This PR adds a assist to promote module to directory, which means make a .rs file module into a directory style module with the same name.

![未命名(1)](https://user-images.githubusercontent.com/13777628/132958377-14555d6f-a64a-4b9b-9154-90a3b86fd685.gif)


Co-authored-by: longfangsong <longfangsong@icloud.com>
2021-09-25 15:32:00 +00:00
longfangsong
22abbe86f3 Address comments 2021-09-25 22:48:57 +08:00
Aleksey Kladov
d72f7cf3af internal: add => () rule; emphasize n_items rule 2021-09-25 14:10:25 +03:00
zhoufan
8690cfb868 Change the style of the code 2021-09-22 06:32:23 +08:00
zhoufan
7912d3a4b3 Generate function assist creates bad param names for const/static item args 2021-09-22 00:15:57 +08:00
Lukas Wirth
ba84b91e78 Add a mirror function-like proc-macro expander for tests 2021-09-21 14:55:54 +02:00
Lukas Wirth
8b1e8197fe Merge iter_for_each_to_for and for_to_iter_for_each assists modules 2021-09-21 10:34:11 +02:00
Lukas Wirth
8b2be8572f Rename some assists 2021-09-21 00:54:09 +02:00
longfangsong
cd599ec202 Address comments 2021-09-20 21:37:18 +08:00
rainy-me
11fbafdee3 Narrow "if-let to match" assist available range 2021-09-18 05:28:52 +09:00
bors[bot]
d44779f8a5
Merge #10260
10260: fix: fix names generation in `Generate function` r=Veykril a=iDawer

- Improve fn name computation (close #10176).
- Handle tuple indexing expressions in argument position (should close  #10241)

Co-authored-by: Dawer <7803845+iDawer@users.noreply.github.com>
2021-09-17 18:35:36 +00:00
Andrzej Głuszak
11a56f886b assists: turn while into loop 2021-09-16 22:20:27 +02:00
Dawer
1d94e234d5 Handle tuple indexing expression in argument position in Generate function 2021-09-16 23:45:41 +05:00
Dawer
4dc33140a3 Imrove fn name computation in Generate function 2021-09-16 21:03:37 +05:00
Lukas Wirth
747f2d1719 fix: Do not wrap inlined local in parens when at block tail position 2021-09-14 18:29:34 +02:00
Lukas Wirth
a044175412 Simplify 2021-09-13 18:50:19 +02:00
Aleksey Kladov
46cdde75f8 internal: document tribal knowledge of how to assist 2021-09-13 14:19:10 +03:00
Aleksey Kladov
076c972e3b internal: prevent possible bugs when adding magical comments 2021-09-13 13:43:13 +03:00
longfangsong
cafc7e3501 Fix doc test 2021-09-12 11:20:28 +08:00
longfangsong
3edc25dc26 Add docs strings 2021-09-12 10:53:56 +08:00
longfangsong
fede1a3beb Add promote_mod_file assist 2021-09-12 10:45:14 +08:00
Dawer
535761e63f minor: update test 2021-09-04 15:19:44 +05:00
Dawer
3d9d10be39 fix: use placeholder as default type in Extract into function. 2021-09-04 14:25:17 +05:00
Dawer
a6c650edf6 fix: use placeholder as default type in Generate function. 2021-09-04 14:24:54 +05:00
Yotam Ofek
dd9433cc63
Update crates/ide_assists/src/handlers/replace_for_loop_with_for_each.rs
Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2021-09-03 21:02:48 +03:00
Yotam Ofek
0d453cc2be Fix replacing for loops over ranges with for_each. 2021-09-03 19:43:40 +03:00
Lukas Wirth
8e8ea537ab Deduplicate imports for qualify_path 2021-09-01 21:51:28 +02:00
Daiki Ihara
4d005e529b Fix extract_function with macro arg 2021-09-01 11:11:57 +02:00
DropDemBits
3bafb5f025
feat: Use enum's visibility for extracted struct fields 2021-08-30 21:33:19 -04:00
DropDemBits
95bf89d3c8
fix: Keep comments & attrs from enum variant 2021-08-30 21:33:12 -04:00
DropDemBits
681efe6dcb
feat: Properly indent extracted struct and enum 2021-08-30 21:26:21 -04:00
bors[bot]
d250aa77ec
Merge #10015
10015: internal: more declarative re-indentation API r=matklad a=matklad



Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2021-08-30 08:34:49 +00:00
Aleksey Kladov
78365c64c8 internal: slightly improve compile times
As per style guide, avoid monomorphisations
2021-08-29 12:53:56 +03:00
Lukas Wirth
5c3a93ca9e Remove incorrect assertion in extract_function 2021-08-27 19:58:57 +02:00
Aleksey Kladov
d1cd81f387 internal: more declarative re-indentation API 2021-08-24 18:18:43 +03:00
bors[bot]
6287d388c0
Merge #9944
9944: internal: introduce in-place indenting API r=matklad a=iDawer

Introduce `edit_in_place::Indent` that uses mutable tree API and intended to replace `edit::AstNodeEdit`.

Closes #9903 

Co-authored-by: Dawer <7803845+iDawer@users.noreply.github.com>
2021-08-24 13:11:50 +00:00
bors[bot]
43021525e5
Merge #9994
9994: add static method generation assist r=matklad a=mahdi-frms

Adds feature: #9948

Will soon send a GIF for the changelog.

Co-authored-by: mahdi-frms <mahdif1380@outlook.com>
2021-08-24 09:26:52 +00:00
bors[bot]
ced65f77c4
Merge #10001
10001: Sort enum variant r=Veykril a=vsrs

A small fix to the problem noted by `@lnicola` :

> ![sort-fields](https://user-images.githubusercontent.com/308347/129513196-4ffc7937-be58-44d4-9ec7-ba8745dcb460.gif)
> 
> (note the slight inconsistency here: to sort the variants of `Animal` I have to select the enum name, but to sort the fields of `Cat` I have to select the fields themselves)



Co-authored-by: vsrs <vit@conrlab.com>
2021-08-23 22:19:50 +00:00
vsrs
7a8f881a09 Sort enum variant 2021-08-23 20:31:54 +03:00
mahdi-frms
cf5f1c102c add static method generation assist 2021-08-23 12:14:23 +04:30
bors[bot]
107b2f1890
Merge #9972
9972: refactor : function generation assists r=Veykril a=mahdi-frms

Separated code generation from finding position for generated code. This will be ground work for introducing static associated function generation.

Co-authored-by: mahdi-frms <mahdif1380@outlook.com>
2021-08-22 14:53:41 +00:00