Commit graph

748 commits

Author SHA1 Message Date
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
mahdi-frms
c1edbfbacc better assist label 2021-08-22 12:31:16 +04:30
mahdi-frms
50923ad741 func gen: seperate generation form position(3) 2021-08-21 19:13:14 +04:30
mahdi-frms
1ac9400100 func gen: seperate generation form position(2) 2021-08-21 17:31:37 +04:30
bors[bot]
4aa2a44a55
Merge #9962
9962: Add empty-body check to replace_match_with_if_let and re-prioritize choices r=elkowar a=elkowar

This PR changes some behaviour of the `replace_match_with_if_let` ide-assist.
Concretely, it makes two changes:

it introduces a check for empty expression bodies. This means that checks of the shape
```rs
match x {
  A => {}
  B => {
    println!("hi");
  }
}
```
will prefer to use the B branch as the first (and only) variant.

It also reprioritizes the importance of "happy" and "sad" patterns.
Concretely, if there are reasons to prefer having the sad pattern be the first (/only) pattern,
it will follow these.
This means that in the case of 
```rs
match x {
  Ok(_) => {
    println!("Success");
  }
  Err(e) => {
    println!("Failure: {}", e);
  }
}
```
the `Err` variant will correctly be used as the first expression in the generated if.
Up until now, the generated code was actually invalid, as it would generate
```rs
if let Ok(_) = x {
  println!("Success");
} else {
  println!("Failure: {}", e);
}
```
where `e` in the else branch is not defined.


Co-authored-by: elkowar <5300871+elkowar@users.noreply.github.com>
2021-08-21 10:12:17 +00:00
elkowar
e47c9743cf
Fix smaller nitpicks 2021-08-21 12:02:21 +02:00
elkowar
7cff930393
Use NameClass::classify to check for ConstReference 2021-08-21 11:11:27 +02:00
elkowar
75f0701211
Add heuristic to determine type of IdentPat, make check for empty expressions correct 2021-08-21 11:00:43 +02:00
mahdi-frms
87439b1d6a func gen: seperate generation form position(1) 2021-08-21 13:29:15 +04:30
mahdi-frms
e2c233a42b simplify 2021-08-21 11:52:07 +04:30
elkowar
d6695286ee
Add empty-body check to replace_match_with_if_let and re-prioritize choices 2021-08-20 15:20:54 +02:00
bors[bot]
59aa091866
Merge #9855
9855: feature: Destructure Tuple Assist r=Veykril a=Booksbaum

Part of #8673. This PR only handles tuples, not TupleStruct and RecordStruct.

Code Assist to destructure a tuple into its items:
![Destructure_Tuple_Assist](https://user-images.githubusercontent.com/15612932/129020107-775d7c94-dca7-4d1f-a0a2-cd63cabf4132.gif)



* Should work in nearly all pattern positions, like let assignment, function parameters, match arms, for loops, and nested variables (`if let Some($0t) = Some((1,2))`)  
  -> everywhere `IdentPat` is allowed
  * Exception: If there's a sub-pattern (``@`):`
    ```rust
    if let t @ (1..=3, 1..=3) = ... {}
    //     ^
    ```
    -> `t` must be a `Name`; `TuplePat` (`(_0, _1)`) isn't allowed
    * inside subpattern is ok:
      ```rust
      let t @ (a, _) = ((1,2), 3);
      //       ^
      ```
      ->
      ```rust
      let t @ ((_0, _1), _) = ((1,2), 3);
      ```
* Assist triggers only at tuple declaration, not tuple usage.  
  (might be useful especially when it creates a sub-pattern (after ``@`)` and only changes the usage under cursor -- but not part of this PR).

### References
References can be destructured:
```rust
let t = &(1,2);
//  ^
let v = t.0;
```
->
```rust
let (_0, _1) = &(1,2);
let v = _0;
```
BUT: `t.0` and `_0` have different types (`i32` vs. `&i32`) -> `v` has now a different type.

I think that's acceptable: I think the destructure assist is mostly used in simple, immediate scopes and not huge existing code.

Additional Notes:
* `ref` has same behaviour (-> `ref` is kept for items)
  ```rust
  let ref t = (1,2);
  //      ^
  ```
  ->
  ```rust
  let (ref _0, ref _1) = (1,2);
  ```
* Rust IntelliJ Plugin: doesn't trigger with `&` or `ref` at all 

### mutable
```rust
let mut t = (1,2);
//      ^
```
->
```rust
let (mut _0, mut _1) = (1,2);
```
and
```rust
let t = &mut (1,2);
//  ^
```
->
```rust
let (_0, _1) = &mut (1,2);
```
Again: with reference (`&mut`), `t.0` and `_0` have different types (`i32` vs `&mut i32`).  
And there's an additional issue with `&mut` and assignment:
```rust
let t = &mut (1,2);
//  ^
t.0 = 9;
```
->
```rust
let (_0, _1) = &mut (1,2);
_0 = 9;
//   ^
//   mismatched types
//   expected `&mut {integer}`, found integer
//   consider dereferencing here to assign to the mutable borrowed piece of memory
```
But I think that's quite a niche use case, so I don't catch that (`*_0 = 9;`)

Additional Notes:
* Rust IntelliJ Plugin: removes the `mut` (`let mut t = ...` -> `let (_0, _1) = ...`), doesn't trigger with `&mut`

### Binding after ``@``
Destructure tuple in sub-pattern is implemented:
```rust
let t = (1,2);
//  ^
let v = t.0;
let f = t.into();
```
->
```rust
let t @ (_0, _1) = (1,2);
let v = _0;
let f = t.into();
```
BUT: Bindings after ``@`` aren't currently in stable and require `#![feature(bindings_after_at)]` (though should be generally [available quite soon](https://github.com/rust-lang/rust/pull/85305#event-5072889913) (with `1.56.0`)).  
But I don't know how to check for an enabled feature -> Destructure tuple in sub-pattern [isn't enabled](a4ee6c7954/crates/ide_assists/src/handlers/destructure_tuple_binding.rs (L32)) yet.

* When Destructure in sub-pattern is enabled there are two assists:
  * `Destructure tuple in place`:
    ```rust
    let t = (1,2);
    //  ^
    ```
    ->
    ```rust
    let (_0, _1) = (1,2);
    let v = _0;
    let f = /*t*/.into();
    ```
  * `Destructure tuple in sub-pattern`:
    ```rust
    let t = (1,2);
    //  ^
    let v = t.0;
    let f = t.into();
    ```
    ->
    ```rust
    let t @ (_0, _1) = (1,2);
    let v = _0;
    let f = t.into();
    ```
* When Destructure in sub-pattern is disabled, only the first one is available and just named `Destructure tuple`

<br/>
<br/>

### Caveats
* Unlike in #8673 or IntelliJ rust plugin, I'm not leaving the previous tuple name at function calls.  
  **Reasoning**: It's not too unlikely the tuple variable shadows another variable. Destructuring the tuple while leaving the function call untouched, results in still a valid function call -- but now with another variable:
  ```rust
  let t = (8,9);
  let t = (1,2);
  //  ^
  t.into()
  ```
  => Destructure Tuple
  ```rust
  let t = (8,9);
  let (_0, _1) = (1,2);
  t.into()
  ```
  `t.into()` is still valid -- using the first tuple.  
  Instead I comment out the tuple usage, which results in invalid code -> must be handled by user:
  ```rust
  /*t*/.into()
  ```
  * (though that might be a biased decision: For testing I just declared a lot of `t`s and quite ofen in lines next to each other...)
  * Issue: there are some cases that results in still valid code:
    * macro that accept the tuple as well as no arguments:
      ```rust
      macro_rules! m {
          () => { "foo" };
          ($e:expr) => { $e; "foo" };
      }
      let t = (1,2);
      m!(t);
      m!(/*t*/);
      ```
      -> both calls are valid ([test](a4ee6c7954/crates/ide_assists/src/handlers/destructure_tuple_binding.rs (L1474)))  
    * Probably with tuple as return value. Changing the return value most likely results in an error -- but in another place; not where the tuple usage was. 

  -> not sure that's the best way....  
  Additional the tuple name surrounded by comment is more difficult to edit than just the name.
* Code Assists don't support snippet placeholder, and rust analyzer just the first `$0` -> unfortunately no editing of generated tuple item variables. Cursor (`$0`) is placed on first generated item.

<br/>
<br/>

### Issues
* Tuple index usage in macro calls aren't converted:
  ```rust
  let t = (1,2);
  //  ^
  let v = t.0;
  println!("{}", t.0);
  ```
  ->
  ```rust
  let (_0, _1) = (1,2);
  let v = _0;
  println!("{}", /*t*/.0);
  ```
  ([tests](a4ee6c7954/crates/ide_assists/src/handlers/destructure_tuple_binding.rs (L1294)))
  * Issue is:  
    [name.syntax()](a4ee6c7954/crates/ide_assists/src/handlers/destructure_tuple_binding.rs (L242-L244)) in each [usage](a4ee6c7954/crates/ide_assists/src/handlers/destructure_tuple_binding.rs (L108-L113)) of a tuple is syntax & text_range in its file.  
    EXCEPT when tuple usage is in a macro call (`m!(t.0)`), the macro is expanded and syntax (and range) is based on that expanded macro, not in actual file.  
    That leads to several things:
    * I cannot differentiate between calling the macro with the tuple or with tuple item:
      ```rust
      macro_rules! m {
          ($t:expr, $i:expr) => { $t.0 + $i };
      }
      let t = (1,2);
      m!(t, t.0);
      ```
      -> both `t` usages are resolved as tuple index usage
    * Range of resolved tuple index usage is in expanded macro, not in actual file  
     -> don't know where to replace index usage

    -> tuple items passed into a macro are ignored, and only the tuple name itself is handled (uncommented)
* I'm not checking if the generated names conflict with already existing variables.
  ```rust
  let _0 = 42;            // >-|
  let t = (1,2);          //   |
  let v = _0;             // <-|
  //  ^ 42
  ```
  => deconstruct tuple
  ```rust
  let _0 = 42;
  let (_0, _1) = (1,2);     // >-|
  let v = _0;               // <-|
  //  ^ now 1
  ```
  * I tried to get the scope at tuple declaration and its usages. And then iterate all names with [`process_all_names`](145b51f9da/crates/hir/src/semantics.rs (L935)). But that doesn't find all local names for declarations (`let t = (1,2)`) (for usages it does)
  * This isn't unique to this Code Assist, but happen in others too (like `extract into variable` or `extract into function`). But here a name conflict is more likely (when destructuring multiple tuples, for examples nested ones (`let t = ((1,2),3)` -> `let (_0, _1) = ...` -> `let ((_0, _1), _1) = ...` -> error))
  * IntelliJ rust plugin does handle this (-> name is `_00`)

Co-authored-by: BooksBaum <15612932+Booksbaum@users.noreply.github.com>
2021-08-19 15:19:06 +00:00
BooksBaum
8a9feeddd3
Remove match_ast usage 2021-08-19 14:17:23 +02:00
BooksBaum
2c27adc0a3
Remove match_ast! macro call
Add node about uncommenting tuple in macro call
2021-08-19 14:09:52 +02:00
Yoshua Wuyts
586d6fca8c Fix codegen for is_method documentation
Previously the generated paths were invalid. This fixes that.
2021-08-19 13:31:16 +02:00
Dawer
08694dc1ef minor: address review comments 2021-08-18 19:04:10 +05:00
Dawer
98847e4d5b internal: use the new edit_in_place::Indent API 2021-08-18 18:08:14 +05:00
BooksBaum
b1ebb82f32
Add deref (*) handling for usages of ref tuples 2021-08-17 19:23:07 +02:00
BooksBaum
384fae7fcd
Switch order of assists
Destructure in sub-pattern before Destructure in place to favor the
first one
2021-08-17 19:23:06 +02:00
BooksBaum
d0cf28322a
Add generated doctest 2021-08-17 19:23:06 +02:00
BooksBaum
5b9f8e7e8e
Fix errors from rebase master
Note:
2nd Assist description is moved down: generated doc tests extracts now
all tests (previously only the first one). But it uses the first
`Assist` name -- which is the wrong one for the 2nd test. And 2nd assist
is currently disabled -> would fail anyway.
2021-08-17 19:23:06 +02:00
BooksBaum
b441aa2046
Cleanup according to style-requirements in tests 2021-08-17 19:23:06 +02:00
BooksBaum
45ef57bd23
Fix: different assist ids in doc and code 2021-08-17 19:23:05 +02:00
BooksBaum
0d2490f785
Handle tuple in macro call
Only tuple name is handled (uncommented), not tuple index
2021-08-17 19:23:05 +02:00
BooksBaum
450a9c5b12
Add destructure in sub-pattern (after @) 2021-08-17 19:23:05 +02:00
BooksBaum
3e4051938d
Handle mut & ref 2021-08-17 19:23:04 +02:00
BooksBaum
478b2988c0
Add Destructure Tuple 2021-08-17 19:22:57 +02:00
Laurențiu Nicola
c9f448a834 Fix some clippy lints 2021-08-16 22:04:26 +03:00
Yoshua Wuyts
067dc660ae implement feedback from review 2021-08-16 18:23:51 +02:00
Yoshua Wuyts
9374d526da fix debug tuple structs 2021-08-16 17:39:08 +02:00
Yoshua Wuyts
b67378f53e fix debug record structs 2021-08-16 12:58:06 +02:00
Aleksey Kladov
3c49a9f079 minor: move functionality to a better place 2021-08-14 20:43:28 +03:00
Aleksey Kladov
e300f58d2c internal: remove one more usage of old editing API. 2021-08-14 20:17:16 +03:00
Aleksey Kladov
a26b1c3923 internal: remove old editing API 2021-08-14 19:45:47 +03:00
bors[bot]
5d7ff6efe3
Merge #9894
9894: internal: use standard test style r=matklad a=matklad

bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2021-08-14 15:59:47 +00:00
Aleksey Kladov
c3bbeb947c internal: use standard test style 2021-08-14 18:53:21 +03:00
Lukas Wirth
37ad9cb2a5 Don't use non cache syntaxnodes in generate_function for lookups 2021-08-14 17:51:11 +02:00
Aleksey Kladov
a78decc466 internal: make assist naming consistent 2021-08-14 18:39:56 +03:00
Aleksey Kladov
dc17b35e62 internal: remove a remnant of old editing infra 2021-08-14 18:24:42 +03:00
Aleksey Kladov
90357a9090 internal: merge hir::BinaryOp and ast::BinOp 2021-08-14 18:10:01 +03:00
Aleksey Kladov
6df00f8495 internal: make naming consistent 2021-08-14 17:01:28 +03:00
Aleksey Kladov
beca92b245 internal: make invert binary op more robust
Previously, we only inverted comparison operators (< and the like) if
the type implemented Ord. This doesn't make sense: if `<` works, then
`>=` will work as well!

Extra semantic checks greatly reduce robustness and predictability of
the assist, it's better to keep things simple.
2021-08-14 16:40:00 +03:00
bors[bot]
43af7920af
Merge #9871
9871: Jump to generated func r=mahdi-frms a=rylev

Worked on this with `@yoshuawuyts.`

We thought we ran into an issue with the `generate_function` assist where the code was not being generated in a certain situations. However, it wasn't actually a bug just a very confusing implementation where the cursor is not moved to the newly generated function. This happened when the return type was successfully inferred (and not unit). The function would be generated, but selection would not be changed.

This can be very confusing: If the function is generated somewhat far from where the assist is being invoked, the user never sees that the code was generated (nor are they given the chance to actually implement the function body). 

This PR makes it so that the cursor is _always_ moved to somewhere in the newly generated function. In addition, if we can infer unit as the type, then we do not still generate `-> ()` as the return type. Instead, we simply omit the return type.

This means the selection will move to either one of two places:
* A generated `-> ()` return type when we cannot successfully infer the return type.
* The `todo!()` body when we can successfully infer the return type.

Co-authored-by: Ryan Levick <me@ryanlevick.com>
2021-08-13 11:19:16 +00:00
Ryan Levick
1cc43ab7f4 Add documentation on how whether a generated return type should be focused or not 2021-08-13 11:46:08 +02:00
Jonas Schievink
d568e7686a Support if let match guards 2021-08-13 00:25:14 +02:00
bors[bot]
baf1494374
Merge #9807
9807: Implicit `Sized` bounds r=iDawer a=iDawer

This should close #8984 

`hir_ty`:
- Type parameters, associated types and `impl Trait` are `Sized` by deafault except `Self` in a trait.
- Implicit `Sized` bound is added to end of predicate list. It does not check if such bound is present already. Also it does not track the bound is implicit.
- Allowed ambiguous unsize coercion if Chalk returns definite guidance.
- Allowed ambiguous autoderef if Chalk returns definite guidance.

`hir_def`:
- `ItemTree` pretty printing shows `?Sized` bounds.

`HirDisplay`:
- `impl Trait` with weird bounds rendered correctly.
- `Sized`/`?Sized` bounds are not shown if they are default.

### Perf
`./target/rust-analyzer-baseline_8a843113 -q analysis-stats --memory-usage .`
```
Database loaded:     1.63s, 287minstr, 91mb
  crates: 38, mods: 741, decls: 15914, fns: 11835
Item Collection:     26.80s, 73ginstr, 338mb
  exprs: 318994, ??ty: 398 (0%), ?ty: 435 (0%), !ty: 174
Inference:           50.28s, 116ginstr, 516mb
Total:               77.08s, 189ginstr, 855mb
```

`./target/rust-analyzer-sized-fixed_ambig_coercion-de074fe6 -q analysis-stats --memory-usage .`
```
Database loaded:     1.63s, 287minstr, 91mb
  crates: 38, mods: 741, decls: 15914, fns: 11835
Item Collection:     26.95s, 73ginstr, 338mb
  exprs: 318994, ??ty: 398 (0%), ?ty: 435 (0%), !ty: 166
Inference:           96.39s, 234ginstr, 543mb
Total:               123.33s, 307ginstr, 881mb
```


Co-authored-by: Dawer <7803845+iDawer@users.noreply.github.com>
2021-08-12 17:55:29 +00:00
Dawer
6c366ade00 Clean up 2021-08-12 21:20:28 +05:00
Ryan Levick
a5c46e5a88 Factor out return type handling for both function and method 2021-08-12 16:05:32 +02:00
Ryan Levick
0834e05045 Always fall back to focusing on generated function body 2021-08-12 14:56:39 +02:00
Ryan Levick
e8de34b6b3 Use term on label for generating method impl 2021-08-12 14:01:15 +02:00
bors[bot]
1376ece497
Merge #9863
9863: feat: Generate default trait fn impl when generating `PartialEq` r=yoshuawuyts a=yoshuawuyts

Implements a default trait function body when generating the `PartialEq` trait for a type. Thanks!

r? `@veykril`

Co-authored-by: Yoshua Wuyts <yoshuawuyts@gmail.com>
2021-08-12 10:18:02 +00:00
Yoshua Wuyts
97ec6a27ec add make::ext::path_from_idents 2021-08-12 12:17:09 +02:00
Yoshua Wuyts
df19895ba6 implement feedback from review 2021-08-12 11:50:01 +02:00
Yoshua Wuyts
8ed24029c1 rm remaining todo comment 2021-08-11 23:30:00 +02:00
Yoshua Wuyts
2fff019b6b improve codegen 2021-08-11 20:33:13 +02:00
Yoshua Wuyts
6c4a94b03a finishing touches 2021-08-11 20:04:05 +02:00
Yoshua Wuyts
c4e10c81b9 gen partialeq for tuple enums 2021-08-11 20:01:19 +02:00
Yoshua Wuyts
741e27b414 dedup PartialEq for Record enums 2021-08-11 19:40:47 +02:00
Lukas Wirth
6045059916 extract_variable handles selection ranges better 2021-08-11 17:52:09 +02:00
Yoshua Wuyts
fc17eb482d gen PartialEq for Record enums
Co-Authored-By: Ryan Levick <rylev@users.noreply.github.com>
2021-08-11 17:15:12 +02:00
bors[bot]
f438dbb100
Merge #9860
9860: fix: Fix extract_function tagging params as mut unnecessarily r=Veykril a=Veykril

Fixes #9822
bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-08-11 15:10:26 +00:00
Lukas Wirth
6d960ab032 Fix extract_function tagging params as mut unnecessarily 2021-08-11 17:09:51 +02:00
Aleksey Kladov
629c68e80d internal: document that ascription is preferred to a turbo fish 2021-08-11 14:16:15 +03:00
Yoshua Wuyts
1cf7af7032 wip enum record/tuple generation 2021-08-10 22:08:14 +02:00
Yoshua Wuyts
65ce87cad8 gen PartialEq for basic enums 2021-08-10 21:05:23 +02:00
Yoshua Wuyts
f8a64c044a gen PartialEq for structs 2021-08-10 19:49:06 +02:00
Yoshua Wuyts
3cad2c4feb add partial_eq gen tests 2021-08-10 19:48:50 +02:00
bors[bot]
e1dcec0e02
Merge #9846
9846: feat: Generate default trait fn impl when generating `Clone` r=Veykril a=yoshuawuyts

Implements a default trait function body when generating the `Clone` trait for a type. Thanks!

r? `@\veykril`

Co-authored-by: Yoshua Wuyts <yoshuawuyts@gmail.com>
2021-08-10 13:18:09 +00:00
Yoshua Wuyts
2f866974d9 gen clone for tuple enums 2021-08-10 15:07:13 +02:00
Yoshua Wuyts
e0adb39de3 gen clone for record enums 2021-08-10 14:43:20 +02:00
Lukas Wirth
7e6eb67f0d Substitute generic types in inline_call 2021-08-10 14:39:56 +02:00
Yoshua Wuyts
7ddc26aea1 add clone generation for structs and bare enums 2021-08-10 13:55:26 +02:00
Yoshua Wuyts
7d7a50daf7 Add clone generation tests 2021-08-10 13:20:24 +02:00
Lukas Wirth
b7d7dd6163 Implement bool_then_to_if assist 2021-08-10 13:17:45 +02:00
Yoshua Wuyts
4b5139e8a5 impl gen hash for structs 2021-08-10 12:37:10 +02:00
Yoshua Wuyts
ec2535e9ce impl gen hash for enums 2021-08-10 12:37:10 +02:00
Yoshua Wuyts
326890753c implement feedback from review 2021-08-10 12:21:48 +02:00
Yoshua Wuyts
d6b788a9ee Add trait codegen to add_missing_impl_members assist 2021-08-10 10:27:52 +02:00
Yoshua Wuyts
4d2e25a034 move trait body gen code to utils 2021-08-09 21:47:44 +02:00
bors[bot]
8e4fb4f518
Merge #9804
9804: Generate method from call r=matklad a=mahdi-frms

Needs a bit of refactoring. Tests also should be added.

Co-authored-by: mahdi-frms <mahdif1380@outlook.com>
2021-08-09 17:09:13 +00:00
bors[bot]
63427afb69
Merge #9825
9825: Generate default impl when converting #[derive(Default)] to manual impl r=Veykril a=yoshuawuyts

Similar to https://github.com/rust-analyzer/rust-analyzer/pull/9814, but for `#[derive(Default)]`. Thanks!

## Follow-up steps
I've added the tests inside `handlers/replace_derive_with_manual_impl.rs` again, but I'm planning a follow-up PR to extract these to `utils/` so we can share them between assists - and maybe even add another assist just for the purpose of testing these impls (e.g. `generate_default_trait_body`).

The step after _that_ is likely to fill out the remaining traits, so we can make it so whenever RA auto-completes a trait which also can be derived, we provide a default function body.


Co-authored-by: Yoshua Wuyts <yoshuawuyts@gmail.com>
2021-08-09 16:59:10 +00:00
mahdi-frms
05a789c09d refactor method generation assist 2021-08-09 21:06:24 +04:30
mahdi-frms
9217f6dcf7 method gen assist usable in all of expression 2021-08-09 21:06:24 +04:30
mahdi-frms
311dc5b04f add test for method generation assist 2021-08-09 21:06:24 +04:30
mahdi-frms
3c31f3831d One assist for function and method generation 2021-08-09 21:06:24 +04:30
mahdi-frms
02f5b5e0e2 method generation assist: store owned ast nodes 2021-08-09 21:06:24 +04:30
mahdi-frms
6240b2dae2 generate method adds pub keyword 2021-08-09 21:06:24 +04:30
mahdi-frms
d38f36e5af generate method assist uses existing impl blocks 2021-08-09 21:06:24 +04:30
mahdi-frms
99570f32d8 refactor: use single next space 2021-08-09 21:06:24 +04:30
mahdi-frms
b777e498fe refactor: use single fn_args 2021-08-09 21:06:24 +04:30
mahdi-frms
9ca73528ee generate method assist 2021-08-09 21:06:24 +04:30
Yoshua Wuyts
13749e782e move code around 2021-08-09 18:27:01 +02:00
Yoshua Wuyts
457eede795 Add gen default for tuple structs 2021-08-09 17:40:50 +02:00
Yoshua Wuyts
423860cd7e Add default body when implementing Default by hand 2021-08-09 17:12:18 +02:00
bors[bot]
caac771439
Merge #9735
9735: Add assist to sort members alphabetically. r=matklad a=vsrs

Supports traits, impls, structs, unions and enums (including inner struct variants). Does not support modules yet.

```rust
en┃um Animal {
  Dog(String, f64),
  Cat { weight: f64, name: String },
}
```
->
```rust
enum Animal {
  Cat { weight: f64, name: String },
  Dog(String, f64),
}
```
---
```rust
enum Animal {
  Dog(String, f64),
  Cat {┃ weight: f64, name: String },
}
```
->
```rust
enum Animal {
  Dog(String, f64),
  Cat { name: String, weight: f64 },
}
```
---
More samples in docs 0b7835619a/crates/ide_assists/src/handlers/sort_items.rs (L12-L83).

Relates #6110


Co-authored-by: vsrs <vit@conrlab.com>
2021-08-09 10:21:14 +00:00
bors[bot]
5664a2b0b3
Merge #9814
9814: Generate default impl when converting `#[derive(Debug)]` to manual impl r=yoshuawuyts a=yoshuawuyts

This patch makes it so when you convert `#[derive(Debug)]` to a manual impl, a default body is provided that's equivalent to the original output of `#[derive(Debug)]`. This should make it drastically easier to write custom `Debug` impls, especially when all you want to do is quickly omit a single field which is `!Debug`.

This is implemented for enums, record structs, tuple structs, empty structs - and it sets us up to implement variations on this in the future for other traits (like `PartialEq` and `Hash`).

Thanks!

## Codegen diff
This is the difference in codegen for record structs with this patch:
```diff
struct Foo {
    bar: String,
}

impl fmt::Debug for Foo {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
-        todo!();
+        f.debug_struct("Foo").field("bar", &self.bar).finish()
    }
}
```

Co-authored-by: Irina Shestak <shestak.irina@gmail.com>
Co-authored-by: Yoshua Wuyts <yoshuawuyts@gmail.com>
Co-authored-by: Yoshua Wuyts <yoshuawuyts+github@gmail.com>
2021-08-08 22:30:37 +00:00
Yoshua Wuyts
59cdb51ef3 Remove unwraps 2021-08-09 00:29:38 +02:00
Yoshua Wuyts
f64aacc0c1 Use minicore 2021-08-08 18:58:42 +02:00
Lukas Wirth
3b7c713af3 Implement if_to_bool_then assist 2021-08-08 17:56:34 +02:00
Yoshua Wuyts
dcbf385ffc use make::name_ref 2021-08-08 16:31:28 +02:00
Yoshua Wuyts
e26ba72333 Update replace_derive_with_manual_impl.rs 2021-08-08 16:26:25 +02:00
Yoshua Wuyts
a2e5fc659d Improve naming and add comments 2021-08-08 16:26:25 +02:00
Yoshua Wuyts
720508a2df dedup struct debug impl code 2021-08-08 16:26:25 +02:00
Yoshua Wuyts
cc3ff1b486 Fix enum debug indent level 2021-08-08 16:26:25 +02:00
Yoshua Wuyts
4b7ae9fedc generate Debug for enums 2021-08-08 16:26:25 +02:00
Yoshua Wuyts
a1f2c7adcd rename variables
According to https://github.com/rust-analyzer/rust-analyzer/blob/master/docs/dev/style.md#variable-naming
2021-08-08 16:26:25 +02:00
Yoshua Wuyts
aa09141a8a finish debug_struct impls 2021-08-08 16:26:25 +02:00
Yoshua Wuyts
fd7236c791 debug for record field structs 2021-08-08 16:26:25 +02:00
Yoshua Wuyts
e2ab2e12a0 wip 2021-08-08 16:24:54 +02:00
Irina Shestak
f2e547d587 impl Debug def from trait 2021-08-08 16:24:54 +02:00
Lukas Wirth
c4a119f433 Simplify 2021-08-07 22:16:15 +02:00
Lukas Wirth
b6d574642d extract_type_alias extracts generics correctly 2021-08-05 02:54:06 +02:00
Lukas Wirth
01413dd7d4 extract_function does not move locals defined outside of loops 2021-08-04 20:00:45 +02:00
Dawer
0f6621fbfa Fix tests. 2021-08-04 20:20:14 +05:00
Lukas Wirth
29c4ae6f9a extract_assist is aware of the expression owner 2021-08-03 20:47:51 +02:00
Lukas Wirth
9edaf0cad8 extract_function is const aware 2021-08-03 18:43:28 +02:00
Lukas Wirth
e62ce6f61a Reorganize functions in extract_function assist 2021-08-03 18:24:33 +02:00
Lukas Wirth
027a99fc70 Do no tear comments apart in extract_function assist 2021-08-03 17:39:49 +02:00
Lukas Wirth
b96f1adf5c Give TypeInfo fields and methods more appropriate names 2021-08-03 17:28:51 +02:00
Lukas Wirth
8afa2722b2 Revise TypeInfo::ty usage 2021-08-03 17:24:43 +02:00
Lukas Wirth
25ff7171c4 Introduce TypeInfo 2021-08-03 16:41:53 +02:00
vsrs
cc33b0dc82 Update the docs 2021-08-02 20:24:18 +03:00
vsrs
6031dee145 Enable assist only if an item is selected 2021-08-02 19:58:41 +03:00
vsrs
e71b239d37 fix generated tests 2021-08-02 19:49:36 +03:00
vsrs
0088f84c88 Allow several samples in "// Assist:" comments. 2021-08-02 19:49:36 +03:00
vsrs
580e5e277a Some comment tests 2021-08-02 19:49:36 +03:00
vsrs
4fa66f1e1e Sort struct enum variant fields 2021-08-02 19:49:36 +03:00
vsrs
6f8888cfe7 Sort enums 2021-08-02 19:49:36 +03:00
vsrs
2c7e99b209 Sort unions 2021-08-02 19:49:36 +03:00
vsrs
b31bf74c13 cargo fmt 2021-08-02 19:49:36 +03:00
vsrs
0694f18636 Sort struct fields 2021-08-02 19:49:36 +03:00
vsrs
643f3931f7 Sort trait and impl methods 2021-08-02 19:49:36 +03:00
Lukas Wirth
432bb222c3 Simplify inline_local_variable assist 2021-08-02 15:27:47 +02:00
bors[bot]
93873b0ce1
Merge #9739
9739: generate function assist favors deref cmpt types r=matklad a=mahdi-frms

Fixes #9713

Although that's still not relying on sematic info.

Co-authored-by: mahdi-frms <mahdif1380@outlook.com>
2021-07-31 15:08:29 +00:00
Lukas Wirth
b363755901 Fix hover range for derive inputs 2021-07-31 14:59:31 +02:00
Lukas Wirth
7c7c4543da Replace useless types 2021-07-31 14:29:15 +02:00
Lukas Wirth
778e6e8ba8 add_explicit_type is applicable for closure parameters 2021-07-31 14:04:34 +02:00
mahdi-frms
a5edf6de79 generate function assist favors deref cmpt types 2021-07-31 16:34:09 +04:30
bors[bot]
1f817833e7
Merge #9727
9727: internal: Simplify extract_function assist r=Veykril a=Veykril

also fixes #7839(blocked on #9728)

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-07-30 14:56:50 +00:00
Lukas Wirth
3e351cc0ba Add trailing comma when extracting match arm expressions into functions 2021-07-30 16:48:13 +02:00
bors[bot]
4cc961007f
Merge #9731
9731: feat: Add `replace_char_with_string` assist r=Veykril a=Veykril

Adds the counterpart for the `replace_string_with_char` assist and fixes the assist not escaping the `'` in the string `"'"` when transforming that to a char.
bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-07-30 14:47:38 +00:00
Lukas Wirth
17a47a830b Add replace_char_with_string assist 2021-07-30 16:46:06 +02:00
bors[bot]
0a3ac7a96c
Merge #9728
9728: fix: Attach comma token to MATCH_ARM instead of MATCH_ARM_LIST r=Veykril a=Veykril

bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-07-30 14:11:37 +00:00
Lukas Wirth
82c1e61887 Fix assists assuming comma belonging to MATCH_ARM_LIST 2021-07-30 16:01:26 +02:00
Lukas Wirth
322513b06c Reorder definitions in extract_function 2021-07-29 22:10:40 +02:00
Lukas Wirth
b21f66fce3 Simplify extract_function assist 2021-07-29 22:07:56 +02:00
bors[bot]
8232804d3e
Merge #9706
9706: minor: perf and grammar fixes r=lnicola a=lnicola



Co-authored-by: Laurențiu Nicola <lnicola@dend.ro>
2021-07-29 16:14:10 +00:00
Lukas Wirth
b537cb186e Use more strictly typed syntax nodes for analysis in extract_function assist 2021-07-29 17:26:37 +02:00
Lukas Wirth
2b461c50d7 Refine extraction targets of extract_function assist 2021-07-29 15:45:05 +02:00
Jonas Schievink
18f86baa62 Stop reexporting hir_def's ItemInNs from HIR 2021-07-28 17:39:04 +02:00
Laurențiu Nicola
636933153d Small grammar fix 2021-07-28 12:40:21 +03:00
Lukas Wirth
456f5c6d09 Don't qualify self as crate in add_missing_impl_members assist 2021-07-27 19:29:47 +02:00
bors[bot]
d571ca814e
Merge #9593
9593: fix: Adding remove_unused_param for method and fixing same for assoc func r=matklad a=feniljain

Solves #9571 

Co-authored-by: vi_mi <fenil.jain2018@vitstudent.ac.in>
2021-07-26 10:36:31 +00:00
Lukas Wirth
0a13259fc6 Kepp catch-all arm in fill_match_arms if it has a non-empty expression 2021-07-25 15:51:47 +02:00
Lukas Wirth
bfe0fa009e Resolve derive attribute input macro paths in ide layer 2021-07-24 20:35:43 +02:00
bors[bot]
0bee7cb716
Merge #9453
9453: Add first-class limits. r=matklad,lnicola a=rbartlensky

Partially fixes #9286.

This introduces a new `Limits` structure which is passed as an input
to `SourceDatabase`. This makes limits accessible almost everywhere in
the code, since most places have a database in scope.

One downside of this approach is that whenever you query limits, you
essentially do an `Arc::clone` which is less than ideal.

Let me know if I missed anything, or would like me to take a different approach!

Co-authored-by: Robert Bartlensky <bartlensky.robert@gmail.com>
2021-07-22 10:33:05 +00:00
bors[bot]
f2736c969c
Merge #9663
9663: fix: Don't offer extract_variable assist when there is no surrounding block r=Veykril a=Veykril

Fixes #9143
bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-07-21 16:00:08 +00:00
Lukas Wirth
9279c1c939 Don't offer extract_variable assist when there is no surrounding block 2021-07-21 17:52:54 +02:00
bors[bot]
1c8cfa4310
Merge #9652
9652: Don't concat path in replace_qualified assist when they start with a keyword r=Veykril a=Veykril

Also keep the path if we can't find a path to the item instead of becoming non applicable.
bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-07-20 16:58:30 +00:00
Lukas Wirth
4f99c6467b Don't concat path in replace_qualified assist when they start with a keyword 2021-07-20 18:57:12 +02:00
Aleksey Kladov
60e7c1de83 minor: address review comments 2021-07-20 17:49:33 +03:00
Aleksey Kladov
3c5827cc18 internal: remove one usage of a slow method 2021-07-20 17:11:09 +03:00
Aleksey Kladov
8e0630e728 internal: remove one usage of a slow method 2021-07-20 17:02:37 +03:00
Robert Bartlensky
0b3d0cde8b Add Limit struct.
Fixes #9286.
2021-07-19 13:26:11 +01:00
vi_mi
0898d3b637 add: fix: Adding remove_unused_param for method and fixing same for associative func 2021-07-18 12:06:21 +05:30
bors[bot]
a2f83c956e
Merge #9614
9614: Parse input expressions for dbg! invocations in remove_dbg r=Veykril a=Veykril

Instead of inspecting the input tokentree manually, parse the input as `,` delimited expressions instead and act on that. This simplifies the assist quite a bit.

Fixes #8455

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-07-16 13:48:23 +00:00
Lukas Wirth
c5bcd56433 Cleanup tests 2021-07-16 15:47:59 +02:00
Lukas Wirth
da00208ab9 Parse input expressions in for dbg! in remove_dbg 2021-07-16 15:20:50 +02:00
Kirill Bulatov
8a5b24eb7e Explicitly connect an ambiguous import path case logic with the test on it 2021-07-16 00:41:00 +03:00
patrick-gu
6c591a9275 fix: Single-line and nested blocks in unwrap_block
Rework the system for stripping whitespace and braces in the
unwrap_block assist to allow correct unwrapping of `{$0 { 0 } }`
2021-07-14 12:02:38 -07:00
Lukas Wirth
c41f1279a3 Inline name classification reference calls 2021-07-11 15:39:09 +02:00
Lukas Wirth
c65bb7f8b9 Explicitly check for reference locals or fields in Name classification 2021-07-11 15:04:40 +02:00
bors[bot]
87621de2b9
Merge #9567 #9568
9567: remove unneded special case r=matklad a=matklad

bors r+
🤖

9568: feat: add 'for' postfix completion r=lnicola a=mahdi-frms


![Peek 2021-07-11 16-45](https://user-images.githubusercontent.com/62165556/125194692-a0aaf780-e267-11eb-952a-81de7955d9a1.gif)


adds #9561

used ```ele``` as identifier for each element in the iteration

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
Co-authored-by: mahdi-frms <mahdif1380@outlook.com>
2021-07-11 12:51:33 +00:00
Lukas Wirth
c6b6f18520 Simplify Semantics::type_of_expr_with_coercion 2021-07-11 14:44:10 +02:00
Aleksey Kladov
1171dc74e0 internal: remove unused param 2021-07-11 15:08:00 +03:00
Aleksey Kladov
5021f10660 internal: add a test for broken refactor 2021-07-11 15:05:16 +03:00
Aleksey Kladov
f42648e305 internal: remove needless distinction between a carte and its root mod 2021-07-11 14:55:24 +03:00
bors[bot]
2e52d6ea93
Merge #9557
9557: fix: Respect coercions in `inline_call` r=Veykril a=Veykril

bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-07-10 17:25:16 +00:00
Lukas Wirth
9e1eb77f6b Respect coercions in inline_call 2021-07-10 19:24:49 +02:00
Lukas Wirth
7e6f40b6f1 Expose coercions for patterns and expressions in semantics 2021-07-10 19:03:46 +02:00
bors[bot]
f83f069f94
Merge #9552
9552: internal: `add_explicit_type` respects coercions r=Veykril a=Veykril

or so I'd like to say but there is one odd case here where it doesn't work(see [review](https://github.com/rust-analyzer/rust-analyzer/pull/9552#discussion_r667351856))

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

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-07-10 16:25:58 +00:00
Lukas Wirth
576e3a4e12 add_explicit_type respects coercions 2021-07-10 18:19:46 +02:00
bors[bot]
2d7727fe31
Merge #9553
9553: minor: Disambiguate replace with if let assist labels r=Veykril a=Veykril

Turns out we have two assists for replacing something with `if let` constructs, so having the cursor on a `let` keyword inside a match gave you two identical assist labels which is rather confusing.
bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-07-10 16:07:01 +00:00
Lukas Wirth
0796288ed2 Disambiguate replace with if let assist labels 2021-07-10 18:00:22 +02:00
bors[bot]
4337f5e456
Merge #9555 #9556
9555: feat: Enable `auto_import` on ident patterns r=Veykril a=Veykril

Helpful for when you want to import a type in a pattern right before destructuring it.

9556: Bump deps r=lnicola a=lnicola

bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
Co-authored-by: Laurențiu Nicola <lnicola@dend.ro>
2021-07-10 15:59:26 +00:00
Lukas Wirth
79614c486b Enable auto_import on ident patterns 2021-07-10 17:57:33 +02:00
Lukas Wirth
0db5992311 replace_qualified_name_with_use keeps qualifier for import 2021-07-10 17:03:24 +02:00
vi_mi
57f119b5fa fix: Adding async keyword when await is present in generate_function assist 2021-07-09 20:04:55 +05:30
Lukas Wirth
d91704cac5 Invert boolean literals in assist negation logic 2021-07-06 20:30:26 +02:00
bors[bot]
112e53f10e
Merge #9500
9500: internal: Only inline closure, literal and local arguments when used once r=Veykril a=Veykril

See https://github.com/rust-analyzer/rust-analyzer/pull/9474#discussion_r663881507 for reasoning.

This still inlines single use closures and literals as naming these is usually not as useful. Prime examples being the Option/Result consuming functions like `map_or` etc.

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-07-06 16:20:54 +00:00
Lukas Wirth
e71ae68b2d Only inline closure, literal and local arguments when used once 2021-07-05 16:43:16 +02:00
Lukas Wirth
46c42166d6 Yeet replace_unwrap_with_match in favor of inline_call 2021-07-05 15:47:55 +02:00
Lukas Wirth
dafbe6940e Wrap inlined closures in parens when inlined in an expression in inline_call 2021-07-05 15:42:11 +02:00
Lukas Wirth
2579dc6d82 Update inline_call assist doc example 2021-07-05 14:24:25 +02:00
bors[bot]
2bc4f9e371
Merge #9474
9474: fix: Inline parameters in `inline_call` if possible r=Veykril a=Veykril

Fixes #9491

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-07-05 11:50:18 +00:00
Lukas Wirth
ea02d27a1e Fixup emitted whitespace in most cases 2021-07-05 13:44:42 +02:00
Aleksey Kladov
86720f2953 minor: drop dummy authors field 2021-07-05 14:19:41 +03:00
Lukas Wirth
e41b5348b8 replace_qualified_name_with_use insert qualified import paths 2021-07-03 23:42:59 +02:00
bors[bot]
e73328f22a
Merge #9477
9477: fix: Don't show an import per namespace in auto_import r=Veykril a=Veykril

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

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-07-03 20:13:14 +00:00
Lukas Wirth
05ec824ab7 Don't show an import per namespace in auto_import 2021-07-03 22:11:01 +02:00
Lukas Wirth
6181154d50 Add some more inline_call tests 2021-07-03 21:42:59 +02:00
bors[bot]
336194c09b
Merge #9476
9476: internal: overhaul codegen r=matklad a=matklad

bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2021-07-03 19:26:04 +00:00
Aleksey Kladov
58d2ece88a internal: overhaul code generation
* Keep codegen adjacent to the relevant crates.
* Remove codgen deps from xtask, speeding-up from-source installation.

This regresses the release process a bit, as it now needs to run the
tests (and, by extension, compile the code).
2021-07-03 22:11:03 +03:00
Lukas Wirth
d308f17a21 Inline parameters in inline_call if possible 2021-07-03 20:05:54 +02:00
bors[bot]
888bb6c452
Merge #9468
9468: feat: Make `inline_function` work on methods r=Veykril a=Veykril

Now called `inline_call`.

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-07-03 16:13:06 +00:00
Lukas Wirth
14e18bfa38 Merge the inline function/method assists into inline_call 2021-07-03 18:07:03 +02:00
Lukas Wirth
9c923068fb Don't hide meta lines 2021-07-03 12:16:07 +02:00
Lukas Wirth
688398febc feat: Implement inline_method assist 2021-07-03 01:33:34 +02:00
Lukas Wirth
fbdcb49d48 Simplify 2021-07-03 01:31:41 +02:00
Lukas Wirth
26dd0c4e5b wrap_return_type_in_result works on the HIR 2021-07-02 23:19:32 +02:00
Lukas Wirth
eb3f90b301 Don't check sad pattern equality by text 2021-07-02 21:10:44 +02:00
Lukas Wirth
251f0c6090 replace_match_with_if_let works on more binary matches 2021-07-02 21:05:10 +02:00
Lukas Wirth
f1819525f5 Simplify 2021-07-02 19:50:37 +02:00
bors[bot]
d18cfd4467
Merge #9458
9458: minor: Remove make::match_arm_with_guard r=Veykril a=Veykril

bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-07-01 23:47:38 +00:00
Lukas Wirth
071ac48b6c Remove make::match_arm_with_guard 2021-07-02 01:44:54 +02:00
bors[bot]
cd3d633850
Merge #9455
9455: feat: Handle not let if expressions in replace_if_let_with_match r=Veykril a=Veykril

Transforms bare `if cond {}` into `_ if cond` guard patterns in the match as long as at least one `if let` is in the if chain, otherwise the assist wont be applicable.

bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-07-01 23:00:50 +00:00
Lukas Wirth
8967856d78 Handle not let if expressions in replace_if_let_with_match 2021-07-02 00:58:56 +02:00
bors[bot]
51d85e1060
Merge #9454
9454: feat: Empower `replace_if_let_with_match` r=Veykril a=Veykril

Now instead of only working on `if let ... {} else {}` if expressions it now works on all of them where the condition expression is the same text-wise.

This includes if let expressions without an else block, in which case a simple `_ => ()` will be generated in the resulting match but also in more complex cases where multiple `if let` expressions are chained.

bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-07-01 22:24:17 +00:00
Lukas Wirth
20be999304 Empower replace_if_let_with_match 2021-07-02 00:21:21 +02:00
bors[bot]
564fa0146e
Merge #9450
9450: internal: Add ModuleOrItem guess to import granularity guessing r=Veykril a=Veykril

I think this should be the last fix needed for this(🤞)
bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-07-01 19:33:53 +00:00
Lukas Wirth
3d2490ca97 Simplify 2021-07-01 21:10:45 +02:00
Lukas Wirth
04f1104179 Don't classify NameRef paths inside attribute TokenTrees 2021-06-30 21:51:28 +02:00
Lukas Wirth
3ce5c66ca1 Deduplicate ast expression walking logic 2021-06-27 01:11:57 +02:00
Daiki Ihara
873aa904f2 Fix var name 2021-06-21 22:47:39 +09:00
Daiki Ihara
7a04f72220 Fix pointed out 2021-06-21 18:42:25 +09:00
Daiki Ihara
cd1ef8de18 Fix extract_function with await 2021-06-21 18:31:53 +09:00
Lukas Wirth
2113c46797 Cleanup insert_use tests 2021-06-19 22:33:29 +02:00
Lukas Wirth
344cb5e76a Don't insert imports outside of cfg attributed items 2021-06-18 23:56:43 +02:00
bors[bot]
d9666ce509
Merge #9334
9334: feat: Allow to disable import insertion on single path glob imports r=Veykril a=Veykril

On by default as I feel like this is something the majority would prefer.

Closes #8490

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-06-18 21:23:22 +00:00
Lukas Wirth
2ee090faaf Allow to disable import insertion on single path glob imports 2021-06-18 23:11:56 +02:00
Aleksey Kladov
3762cc7465 minor: use minicore 2021-06-18 23:59:47 +03:00
Aleksey Kladov
a9623f3165 minor: use minicore 2021-06-18 23:38:19 +03:00
Aleksey Kladov
181184a350 minor: use minicore 2021-06-18 23:28:37 +03:00
Aleksey Kladov
2e4df27132 minor: use minicore 2021-06-18 22:25:35 +03:00
Aleksey Kladov
15c4b3fa7f internal: add Copy to minicore 2021-06-18 22:10:52 +03:00
bors[bot]
0657812bc2
Merge #9321
9321: Inline generics in const and function trait completions r=Veykril a=RDambrosio016

This PR does a couple of things:
- moves path_transform from ide_assists to ide_db to be shared by both assists and completions
- when completing a const or a function for a trait, it will "inline" any generics in those associated items instead 
of leaving the generic's name. For example:
```rust
trait Foo<T> {
    const BAR: T;
    fn foo() -> T;
}
struct Bar;

impl Foo<u32> for Bar {
    // autocompletes to this
    fn foo() -> u32;

    // and not this (old)
    fn foo() -> T;

    // also works for associated consts and where clauses
    const BAR: u32 = /* */
}
```

Currently this does not work for const generics, because `PathTransform` does not seem to account for them. If this should work on const generics too, `PathTransform` will need to be changed. However, it is uncommon to implement a trait only for a single const value, so this isnt a huge concern.

Co-authored-by: rdambrosio <rdambrosio016@gmail.com>
2021-06-18 16:47:58 +00:00
Laurențiu Nicola
e3ce88f6f2 Minor clippy perf fixes 2021-06-18 14:40:51 +03:00
rdambrosio
8e08b86304 Feat: inline generics in const and func trait completions 2021-06-17 19:54:28 -04:00
Aleksey Kladov
89c2dff58a minor: simplify 2021-06-18 00:36:25 +03:00
Aleksey Kladov
ebb591a570 internal: add derive and ord support to minicore 2021-06-18 00:30:22 +03:00
Aleksey Kladov
ca99aaa053 internal: add From to minicore 2021-06-17 21:04:12 +03:00
Aleksey Kladov
08c220ab2c internal: add default to minicore 2021-06-17 20:49:49 +03:00
Lukas Wirth
b6cb6d5abe simplify 2021-06-17 17:58:26 +02:00
Lukas Wirth
95c8c65139 Nest all the or-patterns! 2021-06-17 17:37:14 +02:00
bors[bot]
3b58d8f785
Merge #9308
9308: fix: Create modules in correct directory for nested modules in move_module assist r=Veykril a=Veykril

bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-06-17 10:10:25 +00:00
Lukas Wirth
cd5f4121e3 Create modules in correct directory for nested modules in move_module assist 2021-06-17 12:09:28 +02:00
Aleksey Kladov
a43bba760e internal: switch some tests to minicore 2021-06-17 11:41:36 +03:00
Aleksey Kladov
c42cdff3d2 internal: minimize minicore
We want to keep minicore small, so let's split out iterator adapters and
sources into a separate `iterators` region, and use them only when
needed.
2021-06-17 11:28:44 +03:00
Aleksey Kladov
35772256f8 internal: cleanup tests 2021-06-16 23:27:46 +03:00