Commit Graph

88 Commits

Author SHA1 Message Date
Michael Chisolm
1c32fcfeb4
Fix generated PartialEq::ne 2022-07-20 00:26:50 -04:00
bors
30c4db10ab Auto merge of #12789 - DorianListens:dscheidt/unused-param-overlapping, r=DorianListens
fix: Prevent panic in Remove Unused Parameter assist

Instead of calling `builder.delete` for every text range we find with
`process_usage`, we now ensure that the ranges do not overlap before removing
them. If a range is fully contained by a prior one, it is dropped.

fixes #12784
2022-07-19 22:36:08 +00:00
Amos Wenger
1b416473a3 Upgrade to expect-test@1.4.0
cf. https://github.com/rust-analyzer/expect-test/issues/33
cf. https://github.com/rust-lang/rust/pull/99444#issuecomment-1188844202
2022-07-19 13:00:45 +02:00
Dorian Scheidt
ffb6b23c75 fix: Prevent panic in Remove Unused Parameter assist
Instead of calling `builder.delete` for every text range we find with
`process_usage`, we now ensure that the ranges do not overlap before removing
them. If a range is fully contained by a prior one, it is dropped.

fixes #12784
2022-07-18 16:44:04 -05:00
bors
22e53f1d33 Auto merge of #12549 - bitgaoshu:goto_where_trait_m_impl, r=Veykril
feat: Go to implementation of trait methods

try goto where the trait method implies,  #4558
2022-07-18 16:29:23 +00:00
bors
e2eaa99ca1 Auto merge of #12788 - hasali19:extract-var-mut, r=jonas-schievink
Fix extract variable assist for subexpression in mutable borrow

This checks if the expression is in a mutable borrow and if so makes the extracted variable `mut`.

Closes #12786
2022-07-18 12:42:05 +00:00
harpsword
b5aa3b389e fix: “Generate constant” ignores the path prefix of the identifier 2022-07-18 08:36:10 +08:00
Hasan Ali
ea19e70304 Fix extract variable assist for subexpression in mutable borrow 2022-07-17 22:42:03 +01:00
bors
01d251789f Auto merge of #12539 - soruh:instanciate_empty_structs, r=Veykril
Automatically instaciate trivially instaciable structs in "Generate new" and "Fill struct fields"

As proposed in #12535 this PR changes the "Generate new" and "Fill struct fields" assist/diagnostic to instanciate structs with no fields and enums with a single empty variant.

For example:
```rust
pub enum Bar {
    Bar {},
}
struct Foo<T> {
    a: usize,
    bar: Bar,
    _phantom: std::marker::PhantomData<T>,
}
impl<T> Foo<T> {
    /* generate new */

    fn random() -> Self {
        Self { /* Fill struct fields */ }
    }
}
```

was previously:
```rust
impl<T> Foo<T> {
    fn new(a: usize, bar: Bar, _phantom: std::marker::PhantomData<T>) -> Self {
        Self { a, bar, _phantom }
    }

    fn random() -> Self {
        Self {
            a: todo!(),
            bar: todo!(),
            _phantom: todo!(),
        }
    }
}
```

and is now:
```rust
impl<T> Foo<T> {
  fn new(a: usize) -> Self {
      Self {
          a,
          bar: Bar::Bar {},
          _phantom: std::marker::PhantomData
      }
  }

  fn random() -> Self {
      Self {
          a: todo!(),
          bar: Bar::Bar {},
          _phantom: std::marker::PhantomData,
      }
  }
}
```

I'd be happy about any suggestions.

## TODO
   - [x]  deduplicate `use_trivial_constructor` (unclear how to do as it's used in two separate crates)
   - [x]  write tests

Closes #12535
2022-07-16 16:36:57 +00:00
bors
073b3253c1 Auto merge of #12556 - DorianListens:dscheidt/generic-extract, r=Veykril
fix: Support generics in extract_function assist

This change attempts to resolve issue #7636: Extract into Function does not
create a generic function with constraints when extracting generic code.

In `FunctionBody::analyze_container`, we now traverse the `ancestors` in search
of `AnyHasGenericParams`, and attach any `GenericParamList`s and `WhereClause`s
we find to the `ContainerInfo`.

Later, in `format_function`, we collect all the `GenericParam`s and
`WherePred`s from the container, and filter them to keep only types matching
`TypeParam`s used within the newly extracted function body or param list. We
can then include the new `GenericParamList` and `WhereClause` in the new
function definition.

This change only impacts `TypeParam`s. `LifetimeParam`s and `ConstParam`s are
out of scope for this change.

I've never contributed to this project before, but I did try to follow the style guide. I believe that this change represents an improvement over the status quo, but I think it's also fair to argue that it doesn't fully "fix" the linked issue. I'm totally open to merging this as is, or going further to try to make a more complete solution. Also: if there are other unit or integration tests I should add, please let me know where to look!
2022-07-14 14:29:37 +00:00
bors
fbba1d7acb Auto merge of #12691 - Veykril:proc-macro-diag, r=Veykril
fix: Fix unresolved proc macro diagnostics pointing to macro expansions

Fixes https://github.com/rust-lang/rust-analyzer/issues/12657
2022-07-14 14:21:16 +00:00
Dorian Scheidt
796641b5d8 Make search for applicable generics more precise 2022-07-13 14:54:17 -05:00
Dorian Scheidt
075ab03851 fix: Support generics in extract_function assist
This change attempts to resolve issue #7636: Extract into Function does not
create a generic function with constraints when extracting generic code.

In `FunctionBody::analyze_container`, we now traverse the `ancestors` in search
of `AnyHasGenericParams`, and attach any `GenericParamList`s and `WhereClause`s
we find to the `ContainerInfo`.

Later, in `format_function`, we collect all the `GenericParam`s and
`WherePred`s from the container, and filter them to keep only types matching
`TypeParam`s used within the newly extracted function body or param list. We
can then include the new `GenericParamList` and `WhereClause` in the new
function definition.

This change only impacts `TypeParam`s. `LifetimeParam`s and `ConstParam`s are
out of scope for this change.
2022-07-13 14:54:10 -05:00
soruh
a5ad4de111 add tests 2022-07-13 16:16:48 +02:00
TonalidadeHidrica
eaebead296 Fix config keys regarding imports in docs 2022-07-11 15:43:25 +09:00
Dorian Scheidt
21062f9201 fix: Improve suggested names for extracted variables
When extracting a field expression, if RA was unable to resolve the type of the
field, we would previously fall back to using "var_name" as the variable name.

Now, when the `Expr` being extracted matches a `FieldExpr`, we can use the
`NameRef`'s ident token as a fallback option.

fixes #10035
2022-07-08 18:35:04 -05:00
Dorian Scheidt
603b6fcc68 fix: Extract Function misses locals used in closures
This change fixes #12705.

In `FunctionBody::analyze`, we need to search any `ClosureExpr`s we encounter
for any `NameRef`s, to ensure they aren't missed.
2022-07-08 09:52:01 -05:00
bors
7181a39d4c Auto merge of #12676 - DorianListens:dscheidt/extract-fun-trait-impl, r=jonas-schievink
fix: Extract function from trait impl

This change fixes #10036, "Extract to function assist implements nonexistent
trait methods".

When we detect that the extraction is coming from within a trait impl, and that
a `self` param will be necessary, we adjust which `SyntaxNode` to `insert_after`,
and create a new empty `impl` block for the newly extracted function.
2022-07-08 14:01:36 +00:00
Jonas Schievink
6c6ae965ba Update remaining GitHub URLs 2022-07-08 15:44:49 +02:00
Lukas Wirth
976d07e53e fix: Fix unresolved proc macro diagnostics pointing to macro expansions 2022-07-05 12:46:09 +02:00
bors
75b22326da Auto merge of #12681 - lnicola:bump-deps, r=lnicola
Bump deps
2022-07-03 07:25:03 +00:00
Laurențiu Nicola
e6fcb23445 Bump either 2022-07-03 10:09:35 +03:00
Dorian Scheidt
e3940003a2 fix: Extract function from trait impl
This change fixes #10036, "Extract to function assist implements nonexistent
trait methods".

When we detect that the extraction is coming from within a trait impl, and that
a `self` param will be necessary, we adjust which `SyntaxNode` to `insert_after`,
and create a new empty `impl` block for the newly extracted function.
2022-07-02 15:00:02 -05:00
Dorian Scheidt
0039d6f731 fix: Extract Function produces duplicate fn names
This change fixes issue #10037, in more or less the most naive fashion
possible.

We continue to start with the hardcoded default of "fun_name", and now append a
counter to the end of it if that name is already in scope.

In the future, we can probably apply more heuristics here to wind up with more
useful names by default, but for now this resolves the immediate problem.
2022-07-02 14:24:41 -05:00
bitgaoshu
0dbc091fee add test for suggest_name 2022-06-25 17:33:27 +08:00
bitgaoshu
353829fc4e highlight: trait path 2022-06-24 23:04:35 +08:00
bitgaoshu
9ea8d5806d fix test in qualify_method: stay in trait path 2022-06-24 23:04:35 +08:00
bitgaoshu
9e6bff79f4 fix some test due to resolve to where trait m impl 2022-06-24 19:15:16 +08:00
soruh
f780145c4a apply suggestions 2022-06-22 16:29:59 +02:00
soruh
f52f5fed11 replace TODO with FIXME 2022-06-15 03:16:59 +02:00
soruh
dd0981e3bc fix CI 2022-06-15 03:07:42 +02:00
soruh
6a28cccaee remove dbg 2022-06-15 03:00:43 +02:00
soruh
8cac16b62e cleanup 2022-06-15 02:59:32 +02:00
soruh
8e3bbaa57b instanciate_empty_structs 2022-06-15 02:41:28 +02:00
XFFXFF
e29a6780b1 restrict the assist so that it only appears if the cursor is on the loop keyword 2022-06-11 07:11:56 +08:00
XFFXFF
fac4d28012 change 'loop to 'l, as 'loop is not a valid label name 2022-06-11 07:11:56 +08:00
XFFXFF
0121cc1e29 make generated test pass and make tidy happy 2022-06-11 07:11:56 +08:00
XFFXFF
bb62180714 add more tests and some doc 2022-06-11 07:11:56 +08:00
XFFXFF
872536821c Make add_label_to_loop basically work 2022-06-11 07:11:56 +08:00
bors
7b663a3a4a Auto merge of #12464 - harpsword:fix-inline-variable-mismatched-type, r=Veykril
feat: fix inline variable produce mismatched type

wrap reference for RefExpr initializer to fix #12453
2022-06-10 20:24:06 +00:00
bors
e9d3fe0484 Auto merge of #12502 - Veykril:deps, r=Veykril
internal: Bump Dependencies
2022-06-10 19:51:04 +00:00
Lukas Wirth
76ae5434fa internal: Bump Dependencies 2022-06-10 17:30:02 +02:00
bjorn3
c81608c6d2 Fix a couple of weak warnings found by rust-analyzer itself 2022-06-08 14:35:11 +00:00
Lukas Wirth
fbffe73612 fix: Fix match to if let assist for wildcard pats 2022-06-05 01:02:24 +02:00
harpsword
061c5ef075 feat: fix inline variable produce mismatched type
wrap reference for RefExpr initializer
2022-06-04 17:07:28 +08:00
bors
43d9c3f649 Auto merge of #12460 - Veykril:move-guard, r=Veykril
minor: Reduce move-guard trigger range
2022-06-03 15:00:26 +00:00
Lukas Wirth
b34e27d25e minor: Reduce move-guard trigger range 2022-06-03 17:00:03 +02:00
bors
58b6d46d5a Auto merge of #12333 - nolanderc:order-import-assist, r=Veykril
Order auto-imports by relevance

Fixes #10337.

Basically we sort the imports according to how "far away" the imported item is from where we want to import it to. This change makes it so that imports from the current crate are sorted before any third-party crates. Additionally, we make an exception for builtin crates (`std`, `core`, etc.) so that they are sorted before any third-party crates.

There are probably other heuristics that should be added to improve the experience (such as preferring imports that are common elsewhere in the same crate, and ranking crates depending on the dependency graph). However, I think this is a first good step.

PS. This is my first time contributing here, so please be gentle if I have missed something obvious :-)
2022-06-03 07:49:59 +00:00
iDawer
ea8899a445 Allow merging of multiple selected imports.
The selected imports have to have a common prefix in paths.

Before
```rust
$0use std::fmt::Display;
use std::fmt::Debug;$0
```
After
```rust
use std::fmt::{Display, Debug};
```
2022-06-02 23:15:55 +05:00
bors
2f0814ea35 Auto merge of #12347 - feniljain:fix_extract_module, r=Veykril
fix(extract_module) resolving import panics and improve import resolution

- Should solve #11766
- While adding a test case for this issue, I observed another issue:
For this test case:
```rust
            mod x {
                pub struct Foo;
                pub struct Bar;
            }

            use x::{Bar, Foo};

            $0type A = (Foo, Bar);$0
```
extract module should yield this:

```rust
            mod x {
                pub struct Foo;
                pub struct Bar;
            }

            use x::{};

            mod modname {
                use super::Bar;

                use super::Foo;

                pub(crate) type A = (Foo, Bar);
            }
```

instead it gave:

```rust
            mod x {
                pub struct Foo;
                pub struct Bar;
            }

            use x::{};

            mod modname {
                use x::Bar;

                use x::Foo;

                pub(crate) type A = (Foo, Bar);
            }
```

So fixed this problem with second commit
2022-06-02 12:37:17 +00:00