Commit Graph

140 Commits

Author SHA1 Message Date
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
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
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