Commit Graph

972 Commits

Author SHA1 Message Date
bors[bot]
63d2df1e36
Merge #11699
11699: feat: assist to remove unneeded `async`s r=Ethiraric a=Ethiraric

This should fix #11392 

This PR adds a quickfix on functions marked with `async` that suggests, if and only if no `await` expression in find in the body of the function (it relies on `SyntaxNode::descendants()` to recursively traverse blocks), to remove the `async` keyword.

The lint is made so that it triggers only if the cursor is not in the body of the function, so that it does not pollute the quickfix list.

It does not trigger a diagnostic. I don't know if this repository is the place to implement those (`clippy`?). If it is, I would very much like pointers on where to start looking.

If there are test cases I haven't thought about, please do suggest.

Co-authored-by: Ethiraric <ethiraric@gmail.com>
2022-04-03 12:42:52 +00:00
Ethiraric
520557d45c feat: assist to remove unneeded asyncs 2022-04-03 14:34:08 +02:00
bors[bot]
ba9aed19c7
Merge #11877
11877: fix: splitting path of a glob import wrongly adds `self` r=Veykril a=iDawer

Close  #11703 

`ast::UseTree::split_prefix` handles globs now.
Removed an extra branch for globs in `ide_db::imports::merge_imports::recursive_merge` (superseeded by split_prefix).

Co-authored-by: iDawer <ilnur.iskhakov.oss@outlook.com>
2022-04-02 22:12:59 +00:00
bors[bot]
0e02522b1b
Merge #11874
11874: minor: enum variant wording r=Veykril a=jakevossen5

As discussed on Zulip: https://rust-lang.zulipchat.com/#narrow/stream/185405-t-compiler.2Frust-analyzer/topic/generate.20_.20for.20.22an.20enum.20variant.22



Co-authored-by: Jake Vossen <jake@vossen.dev>
2022-04-01 21:30:32 +00:00
Jake Vossen
93a8fcf7a8 enum variant wording 2022-04-01 14:22:49 -06:00
bors[bot]
ce8e028e9b
Merge #11872
11872: internal: Remove `PathResolution::AssocItem` r=Veykril a=Veykril

bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2022-04-01 17:12:44 +00:00
Lukas Wirth
c290e68ff9 internal: Remove PathResolution::AssocItem 2022-04-01 18:32:05 +02:00
iDawer
b4c608896c fix: splitting path of a glob import wrongly adds self
`ast::UseTree::split_prefix` handles globs now.
Removed an extra branch for globs in `ide_db::imports::merge_imports::recursive_merge` (superseeded by split_prefix).
2022-04-01 19:12:50 +05:00
Jake Vossen
bccf013010 create generate is, as, try_into group 2022-03-31 21:22:08 -06:00
Lukas Wirth
75689f2ad8 internal: Enforce Resolver to always have a module scope 2022-03-31 11:12:08 +02:00
Lukas Wirth
ef92453dfe internal: Refactor FamousDefs builtin crate search 2022-03-30 22:23:54 +02:00
Gibson Fahnestock
6b38c2d75e
docs(auto_import): change by_self -> self and by_crate -> crate
Keep things consistent with the package.json , which uses `self` and
`crate` instead of `by_self` and `by_crate`. Both names are in fact
allowed as aliases, but we should be consistent so that people reading
the docs and using a schema do not see red squiggles.
2022-03-30 12:33:07 +01:00
Florian Diebold
0c4bdd2f32 Fix duplicate type mismatches with blocks
E.g. when there's a type mismatch on the return value of a function. To
fix this, we have to return the expected type as the type of the block
when there's a mismatch. That meant some IDE code that expected
otherwise had to be adapted, in particular the "add return type" assist.
For the "wrap in Ok/Some" quickfix, this sadly means it usually can't be applied
in all branches of an if expression at the same time anymore, because
there's a type mismatch for each branch that has the wrong type.
2022-03-29 18:06:52 +02:00
Laurențiu Nicola
03cb7d9448 Revert "Emit #[must_use] in Generate new assist"
This reverts commit 7e05e10495.
2022-03-26 20:39:36 +02:00
bors[bot]
1a92ee5db5
Merge #11792
11792: minor: Bump dependencies r=Veykril a=Veykril



Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2022-03-22 21:00:24 +00:00
Lukas Wirth
8e91bb7660 minor: Bump dependencies 2022-03-22 17:42:24 +01:00
Ole Strohm
b3bd547dda applied rustfmt 2022-03-22 11:10:48 +00:00
Ole Strohm
94113b0ac6 fix: fill_match_arms doesn't add wildcard pat for local enums 2022-03-22 10:56:20 +00:00
bors[bot]
b594f9c441
Merge #11690
11690: feat: Add an assist for inlining type aliases r=Veykril a=steven-joruk

I'm working towards implementing #10881, but I'd like to get this in first with earlier feedback.

Is `inline_type_alias` a good enough name? I guess the follow up assist would be called `inline_type_alias_into_all_users` based on that.

![valid_inlines](https://user-images.githubusercontent.com/1277939/158020510-fed78b5c-4c7e-46d1-9151-3044a29b9990.gif)

![invalid_inlines](https://user-images.githubusercontent.com/1277939/158020516-8a2deb6d-c6ec-4adf-a15b-c514fc97dc43.gif)



Co-authored-by: Steven Joruk <steven@joruk.com>
2022-03-20 21:15:49 +00:00
Steven Joruk
1381a2de23 refactor: Do more work in inline_type_alias closure 2022-03-20 20:53:03 +00:00
bors[bot]
631b504991
Merge #11741
11741: Emit #[must_use] in Generate enum is_variant assist r=lnicola a=lnicola

bors r+

Co-authored-by: Laurențiu Nicola <lnicola@dend.ro>
2022-03-17 13:23:22 +00:00
bors[bot]
0a18e4355a
Merge #11740
11740: Insert #[must_use] in generate_is_empty_from_len r=lnicola a=Walther

Inserts `#[must_use]` for the generated `is_empty` methods. I also added the `#[must_use]` for the `len()` methods in the documentation examples and tests for this generator while at it, to make sure they too encourage the use of the annotation.

From discussion in https://github.com/rust-analyzer/rust-analyzer/issues/11736 and https://github.com/rust-analyzer/rust-analyzer/pull/11738

Co-authored-by: Walther <veeti.haapsamo@gmail.com>
2022-03-17 13:14:26 +00:00
Laurențiu Nicola
de53232ada Emit #[must_use] in Generate enum is_variant assist 2022-03-17 15:10:25 +02:00
Walther
217b30568e Insert #[must_use] in generate_is_empty_from_len 2022-03-17 15:03:02 +02:00
bors[bot]
502e30e676
Merge #11737 #11739
11737: Emit `#[must_use]` in `Generate new` assist r=lnicola a=lnicola

Closes #11736

11739: Insert #[must_use] in generate_getter r=lnicola a=Walther

Inserts `#[must_use]` for the generated getter methods.

From discussion in https://github.com/rust-analyzer/rust-analyzer/issues/11736 and https://github.com/rust-analyzer/rust-analyzer/pull/11738

Co-authored-by: Laurențiu Nicola <lnicola@dend.ro>
Co-authored-by: Walther <veeti.haapsamo@gmail.com>
2022-03-17 12:58:14 +00:00
Walther
e5adbd88e9 Insert #[must_use] in generate_getter 2022-03-17 14:49:22 +02:00
Laurențiu Nicola
7e05e10495 Emit #[must_use] in Generate new assist 2022-03-17 14:21:42 +02:00
Steven Joruk
1981a3dc65 test: Make imported_external test that the full path is replaced 2022-03-13 13:25:06 +00:00
Morgan Thomas
14e20047c4 broke a test trying to make the diff look better... 2022-03-12 10:35:26 -08:00
Morgan Thomas
3fafbca32e fix: "Extract to function" assist preserves break and continue labels
Adds a label / lifetime parameter to `ide_assists::handlers::extract_function::FlowKind::{Break, Continue}`, adds support for emitting labels to `syntax::ast::make::{expr_break, expr_continue}`, and implements the required machinery to let `extract_function` make use of them.

This does modify the external API of the `syntax` crate, but the changes there are simple, not used outside `ide_assists`, and, well, we should probably support emitting `break` and `continue` labels through `syntax` anyways, they're part of the language spec.

Closes #11413.
2022-03-12 08:54:06 -08:00
Steven Joruk
2e00fa208f chore: Remove unused import 2022-03-12 15:59:00 +00:00
Steven Joruk
d7517d8323 refactor: Veykril's code review suggestions 2022-03-12 15:55:47 +00:00
Matthias Krüger
f39cac17ce fix clippy::needless_late_init 2022-03-12 16:50:49 +01:00
Matthias Krüger
5a0078c9d1 more clippy fixes:
clippy::search_is_some
clippy::redundant_static_lifetimes
clippy::match_single_binding
clippy::match_ref_pats
clippy::map_entry
clippy::manual_map
clippy::iter_overeager_cloned
clippy::into_iter_on_ref
clippy::extra_unused_lifetimes
2022-03-12 16:50:49 +01:00
Matthias Krüger
56e4ea59d9 more clippy fixes:
clippy::match_like_matches_macro
clippy::to_string_in_format_args
clippy::single_char_add_str
clippy::filter_map_identity
clippy::clone_on_copy
clippy::useless_format
clippy::unused_unit
2022-03-12 16:50:49 +01:00
Matthias Krüger
77790f2b8e fix clippy::needless_return 2022-03-12 16:50:49 +01:00
Matthias Krüger
62ed658311 fix clippy::useless_conversion 2022-03-12 16:50:49 +01:00
Matthias Krüger
451fcd3c79 fix clippy::redundant_closure 2022-03-12 16:50:49 +01:00
Matthias Krüger
1f70886b15 fix clippy::single_char_pattern 2022-03-12 16:50:49 +01:00
Matthias Krüger
7912e33ed6 fix clippy::needless_borrow 2022-03-12 16:50:49 +01:00
Steven Joruk
5b712bd821 feat: Add an assist for inlining type aliases
This intends to lead to a more useful assist to replace all users of an
alias with its definition.
2022-03-12 13:42:24 +00:00
Steven Joruk
cdeb1b2c78 chore: fill_match_arms was renamed - update its usage in a comment 2022-03-12 13:41:23 +00:00
Lukas Wirth
a8b76b632c Expand into pseudo-derive attribute expansions in completions 2022-03-10 20:53:50 +01:00
Lukas Wirth
533f178a52 minor: Access parser internals through ide_db for ide crates 2022-03-10 17:07:28 +01:00
bors[bot]
a7d440e368
Merge #11662
11662: fix: extract_module selection inside impl r=Veykril a=feniljain

Should close: #11508 

From issue:
Concern 1: Seems to be fixed in latest `rust-analyzer` build
Concern 2 and 3: Should be fixed by this PR
Concern 4: Got fixed in #11472 

Points to note:

- Here I have seperated use items and other items, this is becuase the new `impl` block which we will be creating cannot contain use items as immediate children. As they are the only one item that can be generated by our assist, so seperating them helps in handling their inclusion in new `impl` block inside new `module`

- There's also a new method added which helps in removing remaning left over indentation after removing `impl` or other `item`

Co-authored-by: vi_mi <fkjainco@gmail.com>
2022-03-10 15:49:03 +00:00
Lukas Wirth
eba90936c1 Move ide crates to new hir::Macro 2022-03-08 23:52:26 +01:00
vi_mi
5789caf60e fix: extract_module selection inside impl 2022-03-09 01:38:53 +05:30
Lukas Wirth
ab21cf2f4f internal: Re-arrange ide_db modules 2022-03-06 19:04:04 +01:00
bors[bot]
8f504dc873
Merge #11598
11598: feat: Parse destructuring assignment r=Veykril a=ChayimFriedman2

Part of #11532.

Lowering is not as easy and may not even be feasible right now as it requires generating identifiers: `(a, b) = (b, a)` is desugared into
```rust
{
    let (<gensym_a>, <gensym_b>) = (b, a);
    a = <gensym_a>;
    b = <gensym_b>;
}
```

rustc uses hygiene to implement that, but we don't support hygiene yet.

However, I think parsing was the main problem as lowering will just affect type inference, and while `{unknown}` is not nice it's much better than a syntax error.

I'm still looking for the best way to do lowering, though.

Fixes #11454.

Co-authored-by: Chayim Refael Friedman <chayimfr@gmail.com>
2022-03-05 11:31:29 +00:00
Lukas Wirth
32bf7af83e Support locals with multiple declaration sites 2022-03-04 19:49:08 +01:00