Commit Graph

418 Commits

Author SHA1 Message Date
bors
6c3ab563de Auto merge of #13527 - unexge:use-let-else-stmt-in-convert-to-guarded-return-assist, r=jonas-schievink
Use let-else statements in `Convert to guarded return` assist

Follow up for https://github.com/rust-lang/rust-analyzer/pull/13516, addresses remaining part of https://github.com/rust-lang/rust-analyzer/issues/13254#issuecomment-1250408527
2022-11-02 11:06:54 +00:00
bors
af1f48deab Auto merge of #13359 - feniljain:feat-must-use-option, r=Veykril
feat: add config for inserting must_use in `generate_enum_as_method`

Should fix #13312

Didn't add a test because I was not sure on how to add test for a specific configuration option, tried to look for the usages for other `AssistConfig` variants but couldn't find any in `tests`. If there is a way to test this, do point me towards it.

I tried to extract the formatting string as a common `template_string` and only have if-else for that, but it didn't compile :(

Also it seems these tests are failing:

```
test config::tests::generate_config_documentation ... FAILED
test config::tests::generate_package_json_config ... FAILED
```

Can you also point me to how to correct these 😅  ( I guess there is some command to automatically generate these? )
2022-11-02 10:50:08 +00:00
feniljain
691ce306df
fix: indentation after inserting #must_use
Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2022-11-02 16:09:12 +05:30
unexge
62a6cdfe46 Use let-else statements in Convert to guarded return assist 2022-11-01 23:02:10 +00:00
bors
a8e97bcf3c Auto merge of #13508 - koka831:fix/13492, r=jonas-schievink
fix: async trait method for `unnecessary_async`

Fix https://github.com/rust-lang/rust-analyzer/issues/13492
2022-11-01 16:38:40 +00:00
Jonas Schievink
72d5b456e1 Fix doc test 2022-11-01 17:23:32 +01:00
Jonas Schievink
9f1bb17a1b Import option in the tests 2022-11-01 17:18:13 +01:00
unexge
f0a14346ee Update auto generated tests 2022-10-30 00:00:53 +01:00
unexge
48efc9d303 Add Convert match to let-else assist 2022-10-29 23:45:13 +01:00
koka
cf90e4f32b
Simplify the procedure
fix: remove unused import
2022-10-30 00:59:20 +09:00
koka
4a7f5cac9d
fix: async trait method for unnecessary_async 2022-10-29 01:14:44 +09:00
feniljain
4bf9b9b003 refactor: remove repetitive string interpolation and doc changes 2022-10-24 21:12:31 +05:30
feniljain
c4bdb8e516 feat: add config for inserting must_use in generate_enum_as_method 2022-10-24 13:18:24 +05:30
Cameron
3dd2f99c49 fix tests 2022-10-22 06:23:23 +01:00
Cameron
5b56d7bd90 remove duplicate mod definition 2022-10-22 05:43:57 +01:00
Cameron
9ea57f19be add wrapping/checked/saturating assist 2022-10-22 05:41:28 +01:00
Justin Mott
e4ef0e5df9 addressed https://github.com/rust-lang/rust-analyzer/issues/12536 2022-10-21 13:28:59 -04:00
feniljain
5bff6c55de feat: add multiple getters mode in generate_getter
This commit adds two modes to generate_getter action.
First, the plain old working on single fields.
Second, working on a selected range of fields.
2022-10-20 16:47:23 +05:30
bors
a2e4f783a2 Auto merge of #13399 - DropDemBits:assists-format-args-capture-pt2, r=Veykril
Migrate assists to format args captures, part 2

Continuation of #13379

Migrates:

- `generate_constant`
- `generate_default_from_enum_variant`
- `generate_default_from_new`
- `generate_delegate_methods`
- `generate_deref`
- `generate_documentation_template`
- `generate_enum_is_method`
- `generate_enum_projection_method`
- `generate_from_impl_for_enum`
- `generate_function`
- `generate_getter`
- `generate_impl`
- `generate_new`
- `generate_setter`
2022-10-17 09:54:07 +00:00
Volkan Sagcan
dd4d3f0a09 fix #13105: Ignore auto-import assist on parameter names 2022-10-15 18:00:32 +02:00
bors
855cd5c280 Auto merge of #13418 - lnicola:bump-deps, r=lnicola
Bump deps
2022-10-15 11:27:12 +00:00
Laurențiu Nicola
cbce0cda08 Bump anyhow, arbitrary, itertools, semver, serde 2022-10-15 12:52:34 +03:00
DropDemBits
b1909a80af Migrate assists to format args captures, part 3 2022-10-12 02:28:41 -04:00
DropDemBits
d7fb8d51d6 Migrate assists to format args captures, part 2 2022-10-12 02:23:35 -04:00
DropDemBits
d439fb2bc8 Migrate assists to format args captures, part 1 2022-10-10 15:56:21 -04:00
DropDemBits
0f46f2773a Migrate most of ide_assists::utils to format arg capture 2022-10-10 10:47:54 -04:00
bors
3a69435af7 Auto merge of #13333 - feniljain:fix_assists, r=Veykril
fix(generate_method): correct method indentation inside generated impl and change gen loc

should fix #10619
2022-10-10 08:36:18 +00:00
bors
dcf1d71bb8 Auto merge of #13303 - jplatte:convert-named-struct-to-tuple-struct, r=Veykril
Add convert_named_struct_to_tuple_struct assist

Closes #11643, since the assist for converting in the other direction is already there (I based most of the implementation and all of the tests on it).
2022-10-10 08:24:37 +00:00
DropDemBits
bfe6ec9b77 Add {TypeParam, ConstParam}::remove_default
Also includes a drive-by refactor of `utils::generate_impl_text_inner`,
since that's what drove this change
2022-10-09 18:46:31 -04:00
DropDemBits
75f641799e Add GenericParamList::to_generic_args 2022-10-09 18:44:23 -04:00
bors
5b7e40014e Auto merge of #13321 - Veykril:format-str-args, r=Veykril
Fix move_format_string_arg being tokentree unaware

Fixes https://github.com/rust-lang/rust-analyzer/issues/13261
2022-09-30 22:42:40 +00:00
Lukas Wirth
3ad0334718 Fix move_format_string_arg being tokentree unaware 2022-10-01 00:42:16 +02:00
Jonas Platte
a3d79b5172
Update outside test and generated code 2022-09-27 20:40:51 +02:00
Jonas Platte
2c666a08b0
Add convert_named_struct_to_tuple_struct assist 2022-09-27 20:39:48 +02:00
bors
ad752bd521 Auto merge of #13301 - Veykril:empty-assist-source-changes, r=Veykril
Make assist tests panic again on empty source changes
2022-09-27 15:54:54 +00:00
Lukas Wirth
f5fe6b157f Make assist tests panic again on empty source changes 2022-09-27 17:48:00 +02:00
harudagondi
c2dc32c48e return None instead of assert 2022-09-21 09:11:02 +08:00
harudagondi
ed0cf1c5fa Add functionality to unwrap tuple declarations 2022-09-17 15:57:45 +08:00
feniljain
37ff07e1ff fix(generate_module): generate new impl near its ADT 2022-09-15 19:33:19 +05:30
feniljain
d0f2db3bf4 fix(generate_method): correct method indentation inside generated impl 2022-09-15 17:22:44 +05:30
bors
125d43cb2c Auto merge of #13227 - Veykril:core-pref, r=Veykril
Restructure `find_path` into a separate functions for modules and non-module items

Follow up to https://github.com/rust-lang/rust-analyzer/pull/13212
Also renames `prefer_core` imports config to `prefer_no_std` and changes the behavior of no_std path searching by preferring `core` paths `over` alloc

This PR turned into a slight rewrite, so it unfortunately does a few more things that I initially planned to (including a bug fix for enum variant paths)
2022-09-13 13:16:57 +00:00
Lukas Wirth
a8ecaa1979 Restructure find_path into a separate functions for modules and non-module items
Also renames `prefer_core` imports config to `prefer_no_std` and changes the behavior of no_std path searching by preferring `core` paths `over` alloc
2022-09-13 15:15:27 +02:00
bors
f64c95600c Auto merge of #13216 - DesmondWillowbrook:move_format_string_arg, r=DesmondWillowbrook
New assist: move_format_string_arg

The name might need some improving.

```rust
fn main() {
    print!("{x + 1}");
}
```
to
```rust
fn main() {
    print!("{}"$0, x + 1);
}
```

fixes #13180

ref to #5988 for similar work

* extracted `format_like`'s parser to it's own module in `ide-db`
* reworked the parser's API to be more direct
* added assist to extract expressions in format args
2022-09-12 15:50:42 +00:00
Kartavya Vashishtha
54e9324e93
Update crates/ide-assists/src/handlers/move_format_string_arg.rs
Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2022-09-12 05:45:11 -07:00
Kartavya Vashishtha
fb5ae9906b
suggest ExtractRefactor if no expressions found
Added `Ident` variant to arg enum.
2022-09-11 10:39:25 +05:30
Kartavya Vashishtha
a5cbee4d11
remove false positive 2022-09-10 21:04:25 +05:30
Kartavya Vashishtha
cc7200891b
new lint: move_format_string_arg
The name might need some improving.

extract format_like's parser to it's own module in ide-db

reworked the parser's API to be more direct

added assist to extract expressions in format args
2022-09-10 20:13:46 +05:30
Kartavya Vashishtha
2584d48508
wip 2022-09-10 20:13:46 +05:30
Lukas Wirth
7d19971666 Add config to unconditionally prefer core imports over std
Fixes https://github.com/rust-lang/rust-analyzer/issues/12979
2022-09-09 20:04:56 +02:00
ice1000
364d9c4910 Fmt 2022-09-02 21:18:36 +00:00
ice1000
68eabf1bf1 Fix test 2022-09-02 21:18:36 +00:00
ice1000
a695e900f6 Create trait Removable, replace ted APIs with builder APIs 2022-09-02 21:18:36 +00:00
ice1000
37e20decad Address comments 2022-09-02 21:18:36 +00:00
ice1000
277df02ff5 This should work, but I got mysterious errors 2022-09-02 21:18:36 +00:00
ice1000
79e5c366cd Extract shared logic 2022-09-02 21:18:36 +00:00
ice1000
fcc61337a8 Remove alias definition naively 2022-09-02 21:18:36 +00:00
Tiddo Langerak
d5e6aa39c1
Pre-cast impl nodes to ast::Impl in find_non_trait_impl 2022-09-01 08:43:41 +03:00
bors
7f38581372 Auto merge of #13120 - Austaras:master, r=jonas-schievink
turn `unwrap_or` into `unwrap_or_else` and vice versa

closes #12983
2022-08-31 13:55:29 +00:00
bors
79a578ae84 Auto merge of #13005 - pocket7878:convert-two-arm-bool-match-to-matches-macro, r=jonas-schievink
feature: Assist to turn match into matches! invocation

Resolves #12510

This PR adds an assist, which convert 2-arm match that evaluates to a boolean into the equivalent matches! invocation.
2022-08-31 13:47:40 +00:00
bors
cf05b7db4d Auto merge of #13051 - DropDemBits:attrs-and-comments-on-enum-variant, r=jonas-schievink
fix: Only move comments when extracting a struct from an enum variant

Motivating example:

```rs
#[derive(Debug, thiserror::Error)]
enum Error {
    /// Some explanation for this error
    #[error("message")]
    $0Woops {
        code: u32
    }
}
```
now becomes
```rs
/// Some explanation for this error
#[derive(Debug, thiserror::Error)]
struct Woops{
    code: u32
}

#[derive(Debug, thiserror::Error)]
enum Error {
    #[error("message")]
    Woops(Woops)
}
```
(the `thiserror::Error` derive being copied and the struct formatting aren't ideal, though those are issues for another day)
2022-08-31 13:34:43 +00:00
Pocket7878
7464b6dbc4 feature: Check if first_arm bool and second_arm bool is inverted or not. 2022-08-31 18:47:45 +09:00
Masato Sogame
5a1b45dcc1 feature: Simplfy branch check logics
Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2022-08-31 18:47:45 +09:00
Pocket7878
a5d2463b1d fix: Simplify logics to allow two-arm enum match. 2022-08-31 18:47:45 +09:00
Pocket7878
4661a60aa9 Add convert_two_arm_bool_match_to_matches_macro ide-assists 2022-08-31 18:47:44 +09:00
austaras
43e8d9644f change title 2022-08-31 17:31:23 +08:00
bors
e0e18cc2a7 Auto merge of #13151 - ChayimFriedman2:replace-turbofish-other-type, r=Veykril
Use correct type in "Replace turbofish with type"

And support `?` and `.await` expressions.

Fixes #13148.

The assist can still show up even if the turbofish's type is not used at all, e.g.:
```rust
fn foo<T>() {}
let v = foo::<i32>();
```
2022-08-31 07:47:53 +00:00
Chayim Refael Friedman
bcdacfe501 Support ? and .await in "Replace turbofish with explicit type"
Now that we use type information this is easy.
2022-08-31 01:24:36 +00:00
Chayim Refael Friedman
e5e979906b Use type information to deduce the correct type for "Replace turbofish with explicit type", even when it is not exactly the same as the turbofish type
I implemented that by checking the expressions' type.
This could probably be implemented better by taking the function's return type and substituting the generic parameter with the provided turbofish, but this is more complicated.
2022-08-31 01:07:41 +00:00
DropDemBits
45dac9a3ef Move comments to the extracted struct 2022-08-30 14:47:08 -04:00
Chayim Refael Friedman
5f132e666d feat: Add a "Unmerge match arm" assist to split or-patterns inside match expressions 2022-08-30 09:42:12 +00:00
austaras
42486b6e94 change as requested 2022-08-29 00:24:56 +08:00
austaras
f9c180ffd1 update tests 2022-08-29 00:24:56 +08:00
austaras
0dd9eef1b9 add type check 2022-08-29 00:24:56 +08:00
austaras
dbaf2ce76e turn unwrap_or into unwrap_or_else and vice versa 2022-08-29 00:24:56 +08:00
Kartavya Vashishtha
0d7ba13b72
style: run tidy tests 2022-08-25 13:17:50 +05:30
Kartavya Vashishtha
9480b38189
extract const generic in ArrayType 2022-08-25 13:11:51 +05:30
Kartavya Vashishtha
71c15f2a44
add test 2022-08-25 13:11:14 +05:30
ice1000
148bdf85f2 Do not substitute Self when in same impl block 2022-08-23 01:52:47 -04:00
DropDemBits
7d777759bf Insert newline after extracted struct's attributes 2022-08-19 09:27:29 -04:00
DropDemBits
6669ea81c3 Leave attrs on the variant, not the extracted struct 2022-08-19 09:27:28 -04:00
bors
2f02ea03b0 Auto merge of #13041 - DorianListens:dscheidt/gen-fn-self-assoc-2, r=Veykril
feat: Generate static method using Self::assoc() syntax

This change improves the `generate_function` assist to support generating static methods/associated functions using the `Self::assoc()` syntax. Previously, one could generate a static method, but only when specifying the type name directly (like `Foo::assoc()`). After this change, `Self` is supported as well as the type name.

Fixes #13012
2022-08-19 10:57:02 +00:00
ice1000
5a6c51ebb8 fix: use functional programming 2022-08-19 01:22:43 +00:00
ice1000
b6fe46055b feat: Improved inline_call to replace Self 2022-08-19 01:06:00 +00:00
Dorian Scheidt
48ea3825b8 Introduce and use get_fn_target_info 2022-08-18 18:39:42 -05:00
Dorian Scheidt
d8e7419c64 Generate and use TargetInfo::new 2022-08-18 18:32:35 -05:00
Dorian Scheidt
2e4a4f1a9c Cleanup inline 2022-08-18 18:28:43 -05:00
Dorian Scheidt
96c04c5e1c inline assoc_fn_target 2022-08-18 18:28:14 -05:00
Dorian Scheidt
2086c48cff Remove mut out params via assoc_fn_target_info 2022-08-18 18:26:54 -05:00
Dorian Scheidt
e27af5fae3 Reorder args with flip_comma 2022-08-18 18:21:58 -05:00
Dorian Scheidt
e513d7b504 Replace tuple with TargetInfo struct 2022-08-18 18:20:06 -05:00
Dorian Scheidt
30eabeb95d extract fn_target_info 2022-08-18 18:14:51 -05:00
Dorian Scheidt
6130860789 use fn_name instead of name_ref.text() 2022-08-18 18:12:53 -05:00
Dorian Scheidt
d39677c1eb Rename static_method_target -> assoc_fn_target 2022-08-18 18:10:37 -05:00
bors
5543dd88c9 Auto merge of #13036 - sancho20021:10881-inline_type_alias_uses, r=Veykril
feat: Add an assist for inlining all type alias uses

## Description
`inline_type_alias_uses` assist tries to inline all selected type alias occurrences.

### Currently
Type alias used in `PathType` position are inlined.

### Not supported
- Removing type alias declaration if all uses are inlined.
- Removing redundant imports after inlining all uses in the file.
- Type alias not in `PathType` position, such as:
  - `A::new()`
  - `let x = A {}`
  - `let bits = A::BITS`
  - etc.

## Demonstration

![example](https://user-images.githubusercontent.com/45790125/184905226-9cb8ac81-1439-4387-a13b-e18ad4ecf208.gif)

## Related Issues
Partially fixes #10881
2022-08-18 08:02:37 +00:00
bors
1da9156b0d Auto merge of #12982 - jridgewell:into_future, r=Veykril
Implement IntoFuture type inference

One of my projects is using [IntoFuture](https://doc.rust-lang.org/std/future/trait.IntoFuture.html) to make our async code a little less verbose. However, rust-analyzer can't infer the output type of an await expression if the value uses `IntoFuture` to convert into another type. So we're getting `{unknown}` types everywhere since switching.

`foo.await` itself [desugars](e4417cf020/compiler/rustc_ast_lowering/src/expr.rs (L644-L658)) into a `match into_future(foo) {}`, with every `Future` impl getting a [default](e4417cf020/library/core/src/future/into_future.rs (L131-L139)) `IntoFuture` implementation. I'm not sure if we want to disable the old `future_trait` paths, since this only recently [stabilize](https://github.com/rust-lang/rust/pull/98718).
2022-08-18 07:37:47 +00:00
Dezhi Wu
23747419ca fix: a bunch of typos
This PR will fix some typos detected by [typos].

There are also some other typos in the function names, variable names, and file
names, which I leave as they are. I'm more certain that typos in comments
should be fixed.

[typos]: https://github.com/crate-ci/typos
2022-08-17 21:44:58 +08:00
Aleksandr Pak
313b004ef7
fixup! feat: add inline_type_alias_uses assist 2022-08-17 12:50:33 +03:00
Dorian Scheidt
39d17efde7 feat: Generate static method using Self::assoc() syntax
This change improves the `generate_function` assist to support generating static methods/associated functions using the `Self::assoc()` syntax. Previously, one could generate a static method, but only when specifying the type name directly (like `Foo::assoc()`). After this change, `Self` is supported as well as the type name.

Fixes #13012
2022-08-16 15:37:24 -05:00
Aleksandr Pak
6d6356b103
fixup! feat: add inline_type_alias_uses assist 2022-08-16 18:29:22 +03:00
Aleksandr Pak
14db080933
feat: add inline_type_alias_uses assist 2022-08-16 17:24:56 +03:00
Tiddo Langerak
7402366877
Avoid cloning IMPL node if we don't have to 2022-08-10 17:03:15 +03:00
Tiddo Langerak
7c568961fd
Feat: extracted method from trait impl is placed in existing impl
Previously, when triggering a method extraction from within a trait
impl block, then this would always create a new impl block for
the struct, even if there already is one. Now, it'll put the extracted
method in the matching existing block if it exists.
2022-08-10 13:07:02 +03:00
Edwin Cheng
c47914c6cf Fixes tests 2022-08-10 16:29:23 +08:00
Justin Ridgewell
5810c8188a Implement IntoFuture type inference 2022-08-08 21:05:56 -04:00
bors
3805067bf5 Auto merge of #12905 - HKalbasi:master, r=Veykril
Generate rust type from json

fix #10118

Should this be a diagnostic? I made it a diagnostic because of issue label.
2022-08-08 11:46:22 +00:00
hkalbasi
851f6db7f7 Import serde derives on converting json to struct 2022-08-06 20:12:21 +04:30
Dorian Scheidt
1980c1192c Support PathPat paths in generate_enum_variant 2022-08-02 14:37:12 -04:00
Dorian Scheidt
111694d85b Be more strict about supported Paths in generate_enum_variant
PathType path parents don't support this assist
2022-08-02 14:37:12 -04:00
Dorian Scheidt
e4638def7a Support record fields in generate_enum_variant 2022-08-02 14:37:12 -04:00
Dorian Scheidt
15d8049fa9 Support tuple fields in generate_enum_variant 2022-08-02 14:37:12 -04:00
Dorian Scheidt
bea1fec7a2 convert generate_enum_variant to use add_variant 2022-08-02 14:37:12 -04:00
Lukas Wirth
f867ddc621 fix: Order ItemScope::entries results 2022-07-28 19:28:56 +02:00
Zachary S
add33b65dd Remove FIXME comment for unreachable fallback. 2022-07-26 10:59:19 -05:00
Zachary S
e45a250f8c fix: Insert spaces when inlining a function defined in a macro. 2022-07-25 15:45:17 -05:00
Amos Wenger
0d04e63627 Merge remote-tracking branch 'origin/master' into sync-from-rust-2 2022-07-25 14:07:07 +02:00
Ryo Yoshida
71225c35bf
Replace debug_assert! with stdx::always! 2022-07-25 18:41:10 +09:00
bors
894d6a232c Auto merge of #12832 - lowr:fix/impl-default-members-no-codegen, r=Veykril
fix: don't replace default members' body

cc #12779, #12821
addresses https://github.com/rust-lang/rust-analyzer/pull/12821#issuecomment-1190157506

`gen_trait_fn_body()` only attempts to implement required trait member functions, so we shouldn't call it for `Implement default members` assist.

This patch also documents the precondition of `gen_trait_fn_body()` and inserts `debug_assert!`, but I'm not entirely sure if the assertions are appropriate.
2022-07-24 12:46:08 +00:00
Amos Wenger
b351e115d6 Move cfg attrs up to the mod definitions to disable sourcegen 2022-07-24 10:38:34 +02:00
Amos Wenger
0bffdf2627 Disable all source-gen tests at compile time 2022-07-24 10:38:28 +02:00
Ralf Jung
ff041bfa68 fix generate_new doc 2022-07-23 11:09:01 -04:00
Ryo Yoshida
7e0bd377c2
fix: don't replace default members' body 2022-07-20 22:30:16 +09:00
Amos Wenger
7e285e1ef5 Run cargo fmt 2022-07-20 15:06:15 +02:00
Amos Wenger
816f7fe12a Run cargo fix --edition-idioms 2022-07-20 15:02:08 +02:00
Amos Wenger
23d25a3094 Enable extra warnings required by rust-lang/rust 2022-07-20 15:00:17 +02:00
bors
84544134f6 Auto merge of #12811 - TopGunSnake:12790, r=Veykril
fix: Insert `pub(crate)` after doc comments and attribute macros

Fixes #12790

Original behavior was to insert `pub(crate)` at the `first_child_or_token`, which for an item with a comment or attribute macro, would put the visibility marker before the comment or macro, instead of after.

This merge request alters the call to find the node with appropriate `SyntaxKind` in the `children_or_tokens`. It also adds a test case to the module to verify the behavior. Test case verifies function, module, records, enum, impl, trait, and type cases.
2022-07-20 06:29:06 +00:00
Michael Chisolm
1c32fcfeb4
Fix generated PartialEq::ne 2022-07-20 00:26:50 -04:00
TopGunSnake
6df414faa2 Inverted the match logic to skip comments, attribute macros, and whitespace before the appropriate keywords. 2022-07-19 18:08:05 -05: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
TopGunSnake
09da74a35d Added case for const 2022-07-18 20:48:01 -05:00
TopGunSnake
3cb78ffa82 Cleaned up trailing whitespace for tidy::files_are_tidy 2022-07-18 20:29:13 -05:00
TopGunSnake
3203cb124e Added coverage for trait, mod, impl, and enum cases. 2022-07-18 20:17:42 -05:00
TopGunSnake
27b65ec91d Add test case and token finder to address 12790 2022-07-18 19:55:33 -05: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
feniljain
8a1ef52f5c fix(extract_module): Remove redundancy causing else, and also add import fix loop for names 2022-05-31 09:51:42 +05:30
Christofer Nolander
8e5b318d99 Cleanup auto-import ordering
Addresses issues raised by @Veykril in #12333
2022-05-28 11:32:07 +02:00
Amos Wenger
c06c4f9682 Make test pass 2022-05-25 18:31:08 +02:00
Amos Wenger
05563805b1 Add test for #12372 (generate enum variant in different file) 2022-05-25 18:18:08 +02:00
Amos Wenger
89e27ed0b9 Generate variant: insert code in file with enum definition
Closes #12372
2022-05-25 16:43:15 +02:00
Lukas Wirth
86d1d9067e fix: Insert whitespace into trait-impl completions when coming from macros 2022-05-24 22:56:33 +02:00
Amos Wenger
ae2c0db67f Pull text creation into the closure 2022-05-22 18:38:14 +02:00
Amos Wenger
796c4d8a10 Better lowercase/uppercase checks 2022-05-22 18:31:12 +02:00
feniljain
89f449b75d fix(extract_module): import resolution for items of submodules 2022-05-22 17:11:15 +05:30
feniljain
ddd59b9a9a fix(extract_module): nearby imports deletion causing panic 2022-05-21 19:13:49 +05:30
Christofer Nolander
068b138c87 Remove unecessary unwrap 2022-05-21 10:25:12 +02:00
Amos Wenger
707a5683b1 Still suggest generating enum methods if the name ref starts with a lowercase letter 2022-05-21 01:43:05 +02:00
Amos Wenger
0ed85beb15 Don't suggest enum variant if name_ref start with ASCII lowercase letter 2022-05-21 01:36:26 +02:00
Amos Wenger
7d716cbeb9 Simplify with adt.source() 2022-05-21 01:32:25 +02:00
Amos Wenger
2347da8c8d Generate enum variant assist
This also disables "generate function" when what we clearly want is to
generate an enum variant.

Co-authored-by: Maarten Flippo <maartenflippo@outlook.com>
2022-05-21 01:18:35 +02:00
Christofer Nolander
aef16300f7 Order auto-imports by relevance
This first attempt prefers items that are closer to the module they are
imported in.
2022-05-21 00:07:06 +02:00
Jonas Schievink
e52d463524 Revert the "Add attribute" assist 2022-05-20 14:39:22 +02:00
Jonas Schievink
5279cdbefb Include self type in generated getter/setter docs 2022-05-18 19:22:04 +02:00
Jonas Schievink
93b62dbe85 Improve docs generation assist 2022-05-18 18:05:21 +02:00
bors
187bd7d48a Auto merge of #12130 - weirane:let-else-let-match, r=weirane
Turn let-else statements into let and match

Fixes #11906.
2022-05-17 19:01:18 +00:00
weirane
4a0821f332 Simplify const reference check
Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2022-05-17 11:43:53 -07:00
Jonas Schievink
cb135ae71b Add a "Add attribute" assist 2022-05-17 20:28:25 +02:00
Jonas Schievink
1df6560fd8 Improve "Generate Deref impl" assist 2022-05-16 20:10:46 +02:00
Jonas Schievink
54c8c39da0 Don't generate documentation in generate_setter 2022-05-16 19:27:27 +02:00
Jonas Schievink
f1b6e45fba Handle getters and setters in documentation template assist 2022-05-16 19:10:38 +02:00
bors
bfb241afa3 Auto merge of #12188 - Veykril:auto-import, r=Veykril
fix: Allow auto importing starting segments of use items
2022-05-07 14:16:00 +00:00
Lukas Wirth
61e074f016 fix: Allow auto importing starting segments of use items 2022-05-07 15:52:22 +02:00
Lukas Wirth
0c4e23b8ef internal: Remove unqualified_path completions module 2022-05-05 22:21:42 +02:00
Wang Ruochen
8d7a393008 Check const reference 2022-05-05 11:44:11 -07:00
Wang Ruochen
81d7cbbbe2 Avoid allocations 2022-05-05 10:14:11 -07:00
Maybe Waffle
e315124798 Remove "Sort methods by trait definition" assist
It was replaced by the "Sort items by trait definition" assist.
2022-05-04 00:59:23 +04:00
Maybe Waffle
2b20a05fc6 Add "Sort items by trait definition" 2022-05-03 19:57:39 +04:00
Maybe Waffle
d7ed351573 Fix some typos in ide-assists/src/lib.rs 2022-05-03 19:41:07 +04:00
Wang Ruochen
a70beea9e9 Trigger only when cursor is on else 2022-05-02 15:20:13 -07:00
Wang Ruochen
59cdb31874 Turn let-else statements into let and match 2022-05-01 09:43:51 -07:00
Peh
c9a8c69ee0 update diagnostic-docs crate name 2022-05-01 10:48:58 +00:00
Peh
e53bf7e9c2 updated ide-assist new dir name 2022-05-01 10:48:58 +00:00
Peh
1f011fa4a3 style: rename crates to kebab case 2022-05-01 10:48:58 +00:00