Commit graph

882 commits

Author SHA1 Message Date
Graeme Coupar
ee03849017 Convert Into to From assist
This adds a "Convert Into to From" assist, useful since clippy has
recently started adding lints on every `Into`.

It covers converting the signature, and converting any `self`/`Self`
references within the body to the correct types.

It does assume that every instance of `Into` can be converted to a
`From`, which I _think_ is the case now.  Let me know if there's
something I'm not thinking of and I can try and make it smarter.
2021-04-03 15:48:35 +01:00
bors[bot]
75011bbccb
Merge #8210
8210: Implement "Extract type alias" assist r=jonas-schievink a=jonas-schievink



Co-authored-by: Jonas Schievink <jonas.schievink@ferrous-systems.com>
Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
2021-03-31 12:26:57 +00:00
bors[bot]
55d7d71590
Merge #8267
8267: Adding gifs and screenshots for features in manual r=matklad a=MozarellaMan

For #6539

This includes most of gif or screenshot examples of most items in the "Features" header. With the exceptions of:

- **On Typing Assists** - couldn't get it to work for a demo, I'm probably missing something?
- **Structural search and replace** - looked to be already a visual example of the feature
- **Workspace symbol** - wasn't sure how best to show this, all of the examples maybe? Also wasn't sure of the best code example to show it off
- **Semantic Syntax Highlighting** - seemed obvious enough to not need a screenshot, but I could easily add this

All the gifs/pngs are hosted in this [comment](https://github.com/rust-analyzer/rust-analyzer/issues/6539#issuecomment-809574840). Please let me know if any of them aren't suitable (and why) and I'll improve it! Or if you don't like the theme/font

Co-authored-by: Ayomide Bamidele <48062697+MozarellaMan@users.noreply.github.com>
2021-03-31 10:01:56 +00:00
Ayomide Bamidele
276022682b Gifs and screenshots for features in manual 2021-03-31 00:08:10 +01:00
Lukas Wirth
c2a63b97a8 Rename target_ty to self_ty 2021-03-29 17:47:47 +02:00
ivan770
f9d17c6d7c
Apply test style fixes to all empty remove_dbg tests 2021-03-29 16:00:09 +02:00
ivan770
8e5611442e
Update crates/ide_assists/src/handlers/remove_dbg.rs
Apply standard test style fixes

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2021-03-29 16:52:30 +03:00
Jonas Schievink
3c6c1c99b4 Don't use snippets 2021-03-29 13:23:07 +02:00
Jonas Schievink
8c1092455e Use find_node_at_range 2021-03-29 13:17:49 +02:00
Jonas Schievink
b494e47920 Snippet support in extract_type_alias 2021-03-27 18:53:13 +01:00
ivan770
665266bf66
Replace empty dbg with unit in letexprs, better removal in blocks 2021-03-27 17:34:35 +02:00
bors[bot]
ae92014319
Merge #8213
8213: Added support for const generics in impl generation r=Veykril a=ivan770

Closes #8211

Co-authored-by: ivan770 <leshenko.ivan770@gmail.com>
2021-03-27 10:00:37 +00:00
ivan770
5a2ef8d0ca
Added support for const generics in impl generation 2021-03-27 11:37:39 +02:00
ivan770
0a5badbcba
Replace match on option with if 2021-03-27 11:17:17 +02:00
ivan770
c7cd0aff4a
Remove dbg expression and newline as whole 2021-03-27 11:10:20 +02:00
Jonas Schievink
e39979aa91 Implement "Extract type alias" assist 2021-03-26 19:39:20 +01:00
cynecx
5ff3299dd6 syntax: return owned string instead of leaking string 2021-03-26 18:30:59 +01:00
ivan770
2292ff64f1
Show dbg remove assist on empty contents 2021-03-26 16:15:26 +02:00
hi-rustin
eef9bdb441 refine comment style of tests 2021-03-24 19:28:50 +08:00
bors[bot]
776b1ebcb4
Merge #8168
8168: correct `convert to guard return` let_stmt r=Veykril a=hi-rustin

close https://github.com/rust-analyzer/rust-analyzer/issues/8074

Co-authored-by: hi-rustin <rustin.liu@gmail.com>
2021-03-24 10:55:25 +00:00
hi-rustin
e992acf078 correct convert to guard return let_stmt
fix

fix

add check
2021-03-24 11:52:44 +08:00
Aleksey Kladov
8b4240e026 Cleanup 2021-03-23 19:59:33 +03:00
Aleksey Kladov
e33959a888 Simplify code
changelog: skip
2021-03-23 19:41:15 +03:00
Aleksey Kladov
860e069d4d Use styleguide conforming import for ast nodes 2021-03-23 17:44:17 +03:00
Aleksey Kladov
7352f50ec2 Unify test style
changelog skip
2021-03-23 17:38:51 +03:00
Aleksey Kladov
b83c7eedcc Tweak assits API to fit mutable syntax trees
changelog: skip
2021-03-23 17:31:19 +03:00
Aleksey Kladov
9cbf09ec4f rewrite merge use trees assist to use muatable syntax trees
changelog internal
2021-03-22 20:47:46 +03:00
Matthias Krüger
ae7e55c1dd clippy::complexity simplifications related to Iterators 2021-03-21 13:13:34 +01:00
Kirill Bulatov
eaa4fcbbde Less reallocations 2021-03-21 11:45:37 +02:00
Kirill Bulatov
56a7d246d5 Disable unqualified assoc items completion for now 2021-03-20 23:08:44 +02:00
Kirill Bulatov
879432452d Docs 2021-03-20 22:55:34 +02:00
Kirill Bulatov
a631108d2d Do not query item search by name eagerly 2021-03-20 22:33:54 +02:00
bors[bot]
5cc8ad0c4a
Merge #8119
8119:  Don't return a SourceChange on WillRenameFiles when nothing gets refactored r=Veykril a=Veykril

bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-03-20 12:58:28 +00:00
Lukas Wirth
d84912483d Fix add_life_to_type label typo 2021-03-20 13:44:12 +01:00
Aleksey Kladov
ba72308588 simplify
changelog skip
2021-03-19 21:00:20 +03:00
Lukas Wirth
c34a9f10b1 Cleanup qualify_path 2021-03-19 13:12:00 +01:00
Lukas Wirth
34464ede3f Fix associated items not being appended to paths in import_assets 2021-03-18 21:36:52 +01:00
Matthias Krüger
ff5f90d8ae use simpler .map(|x| y) instead of .and_then(|x| Some(y)) for Options. (clippy::bind_instead_of_map) 2021-03-17 02:36:29 +01:00
Matthias Krüger
048dad8c2e don't clone types that are copy (clippy::clone_on_copy) 2021-03-17 01:56:31 +01:00
Aleksey Kladov
d733c9bdad Move more bounds
changelog: skip
2021-03-16 22:28:04 +03:00
Aleksey Kladov
f5a81ec468 Upgrade rowan
Notably, new rowan comes with support for mutable syntax trees.
2021-03-16 16:10:49 +03:00
Chetan Khilosiya
714836959b 7709: Added the check for return type of len function. 2021-03-16 01:16:59 +05:30
Chetan Khilosiya
0c2d4a8a77 7709: Updated the implementation.
The get function from impl method is updated.
and now same method used to get len and is_empty function.
2021-03-15 22:48:50 +05:30
Chetan Khilosiya
2bf3802f21 7709: Added the assist to generate is_empty function
the assist will be shown when the len function is implemented.
is_empty internally uses len function.
2021-03-15 21:31:52 +05:30
Laurențiu Nicola
88cee24c6c Enable thread-local coverage marks 2021-03-15 16:02:50 +02:00
Jake Goulding
63155d66f5 Allow applying De Morgan's law to multiple terms at once 2021-03-12 10:19:54 -05:00
bors[bot]
c0459c5357
Merge #7956
7956: Add assist to convert for_each into for loops r=Veykril a=SaiintBrisson

This PR resolves #7821.
Adds an assist to that converts an `Iterator::for_each` into a for loop: 

```rust
fn main() {
    let vec = vec![(1, 2), (2, 3), (3, 4)];
    x.iter().for_each(|(x, y)| {
        println!("x: {}, y: {}", x, y);
    })
}
```
becomes
```rust
fn main() {
    let vec = vec![(1, 2), (2, 3), (3, 4)];
    for (x, y) in x.iter() {
        println!("x: {}, y: {}", x, y);
    });
}
```

Co-authored-by: Luiz Carlos Mourão Paes de Carvalho <luizcarlosmpc@gmail.com>
Co-authored-by: Luiz Carlos <luizcarlosmpc@gmail.com>
Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-03-12 14:45:04 +00:00
Lukas Wirth
6d35c67b6e Fix convert_iter_for_each_to_for doctest 2021-03-12 15:42:53 +01:00
Luiz Carlos Mourão Paes de Carvalho
e505752442 fix: generated test fixture 2021-03-12 08:53:57 -03:00
Luiz Carlos
7a9230acdf
fix: replace doc-comments with normal comments
Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-03-12 08:44:03 -03:00
Luiz Carlos Mourão Paes de Carvalho
f67861310c refactor: refactored and reduced assist code 2021-03-12 08:06:50 -03:00
Conrad Ludgate
233820d780
fix: add semicolon after type ascription 2021-03-11 10:36:45 +00:00
Luiz Carlos Mourão Paes de Carvalho
6236b1eaf8 fix: remove semicolon 2021-03-10 15:43:57 -03:00
Kirill Bulatov
94bb9cb9ee Fix labels for single import assists 2021-03-10 11:30:25 +02:00
Luiz Carlos Mourão Paes de Carvalho
a224e0087d fix: code formatting 2021-03-10 00:32:25 -03:00
Luiz Carlos Mourão Paes de Carvalho
b7f97715a3 fix: tests should work for convert_iter_for_each_to_for 2021-03-10 00:23:20 -03:00
Luiz Carlos Mourão Paes de Carvalho
87dc9d1fcc refactor: create block expressions and for loops using make 2021-03-09 23:55:26 -03:00
Luiz Carlos Mourão Paes de Carvalho
eea21490e0 feat: add assist to conver for_each into for loops 2021-03-09 22:58:17 -03:00
Aleksey Kladov
842d8ad9c8 Compilation speed 2021-03-09 22:30:58 +03:00
bors[bot]
21913d0fdb
Merge #7873 #7933
7873: Consider unresolved qualifiers during flyimport r=matklad a=SomeoneToIgnore

Closes https://github.com/rust-analyzer/rust-analyzer/issues/7679

Takes unresolved qualifiers into account, providing better completions (or none, if the path is resolved or do not match).

Does not handle cases when both path qualifier and some trait has to be imported: there are many extra issues with those (such as overlapping imports, for instance) that will require large diffs to address.

Also does not do a fuzzy search on qualifier, that requires some adjustments in `import_map` for better queries and changes to the default replace range which also seems relatively big to include here.

![qualifier_completion](https://user-images.githubusercontent.com/2690773/110040808-0af8dc00-7d4c-11eb-83db-65af94e843bb.gif)


7933: Improve compilation speed r=matklad a=matklad

bors r+
🤖

Co-authored-by: Kirill Bulatov <mail4score@gmail.com>
Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2021-03-09 11:58:48 +00:00
bors[bot]
3fdf26a6fc
Merge #7898
7898: generate_function assist: infer return type r=JoshMcguigan a=JoshMcguigan

This PR makes two changes to the generate function assist:

1. Attempt to infer an appropriate return type for the generated function
2. If a return type is inferred, and that return type is not unit, don't render the snippet

```rust
fn main() {
    let x: u32 = foo$0();
    //              ^^^ trigger the assist to generate this function
}

// BEFORE
fn foo() ${0:-> ()} {
    todo!()
}

// AFTER (only change 1)
fn foo() ${0:-> u32} {
    todo!()
}

// AFTER (change  1 and 2, note the lack of snippet around the return type)
fn foo() -> u32 {
    todo!()
}
```

These changes are made as two commits, in case we want to omit change 2. I personally feel like it is a nice change, but I could understand there being some opposition.

#### Pros of change 2
If we are able to infer a return type, and especially if that return type is not the unit type, the return type is almost as likely to be correct as the argument names/types. I think this becomes even more true as people learn how this feature works.

#### Cons of change 2

We could never be as confident about the return type as we are about the function argument types, so it is more likely a user will want to change that. Plus it is a confusing UX to sometimes have the cursor highlight the return type after triggering this assist and sometimes not have that happen.

#### Why omit unit type?

The assumption is that if we infer the return type as unit, it is likely just because of the current structure of the code rather than that actually being the desired return type. However, this is obviously just a heuristic and will sometimes be wrong. But being wrong here just means falling back to the exact behavior that existed before this PR.



Co-authored-by: Josh Mcguigan <joshmcg88@gmail.com>
2021-03-08 22:51:04 +00:00
Josh Mcguigan
b275e60905 generate_function assist don't render snippet if ret type inferred 2021-03-08 14:38:36 -08:00
Kirill Bulatov
5168ab16e1 Add rustdocs and use better names 2021-03-08 23:59:37 +02:00
Kirill Bulatov
dccbb38d2e Less lifetines: derive SemanticsScope in place 2021-03-08 23:59:20 +02:00
Kirill Bulatov
5b7d928075 Enforce the located imports' order 2021-03-08 23:59:20 +02:00
Kirill Bulatov
33c83e72b9 Work towards better import labels 2021-03-08 23:59:20 +02:00
Kirill Bulatov
89d410cef5 Do not propose already imported imports 2021-03-08 23:59:20 +02:00
Kirill Bulatov
9482353fa8 Properly handle turbofishes in qualifiers 2021-03-08 23:59:20 +02:00
Kirill Bulatov
582cee2cdf Return more data about located imports 2021-03-08 23:59:18 +02:00
Kirill Bulatov
309421c117 Draft the qualifier import resolution 2021-03-08 23:58:48 +02:00
Kirill Bulatov
005bc49d74 Test and initial refactoring 2021-03-08 23:58:32 +02:00
Laurențiu Nicola
fc9eed4836 Use upstream cov-mark 2021-03-08 22:19:44 +02:00
Aleksey Kladov
9faf8dd69a Hygiene is an internal implementation detail of the compiler 2021-03-08 22:14:52 +03:00
bors[bot]
d54e1157b6
Merge #7889
7889: Make group imports configurable r=lnicola a=asv1



Co-authored-by: asv <asv7c2@gmail.com>
2021-03-07 08:24:02 +00:00
asv
96fc01a30b Make group imports configurable 2021-03-07 10:15:17 +02:00
Josh Mcguigan
d645b81b28 generate_function assist infer return type 2021-03-06 14:28:54 -08:00
bors[bot]
c44575b485
Merge #7896
7896: Only replace quotes in replace_string_with_char assist r=Veykril a=Veykril

bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-03-06 20:22:36 +00:00
Lukas Wirth
1a276f8959 Only replace quotes in replace_string_with_char assist 2021-03-06 21:21:18 +01:00
bors[bot]
5480bed936
Merge #7800
7800: [WIP] 7708: Initial implementation of generate Default assist. r=Veykril a=chetankhilosiya

The Generate Default impl from new function.

Co-authored-by: Chetan Khilosiya <chetan.khilosiya@gmail.com>
2021-03-06 20:01:50 +00:00
Chetan Khilosiya
d40a4fc92c 7708: rust ideomatic code fixes. 2021-03-07 01:26:05 +05:30
bors[bot]
856c2850cd
Merge #7865
7865: preserve escape sequences when replacing string with char r=Veykril a=jDomantas

Currently it replaces escape sequence with the actual value, which is very wrong for `"\n"`.

Co-authored-by: Domantas Jadenkus <djadenkus@gmail.com>
2021-03-06 19:54:36 +00:00
Chetan Khilosiya
e4b6541c7a 7708: handle both FamousDefs fixture and plain code.
Also fix typo in example.
2021-03-07 00:51:48 +05:30
Chetan Khilosiya
9a84daf47d 7708: Added the updated implementation of is_default_implemented.
The implementation uses hir create to find the implemented trait.
2021-03-07 00:49:03 +05:30
Chetan Khilosiya
b8e6d6a606 7708: Added the logic to check is default impl is already present.
Also added test cases for code present within module.
2021-03-07 00:49:03 +05:30
Chetan Khilosiya
a59a97ae04 7708: Updated generate default fn logic. 2021-03-07 00:49:03 +05:30
Chetan Khilosiya
54b4727fa3 7708: Added the work for review comments.
Also added 1 test case to test multiple struct blocks are present.
2021-03-07 00:49:03 +05:30
Chetan Khilosiya
135c9e2027 7708: Fixed many documentaion example issues. 2021-03-07 00:49:03 +05:30
Chetan Khilosiya
69a6e4c80c 7708: Format code through rust-analyzer formatter. 2021-03-07 00:49:03 +05:30
Chetan Khilosiya
cb3f4d43d9 7708: Initial implementation of generate Default assist.
The Generate Default impl from new function.
2021-03-07 00:49:03 +05:30
Josh Mcguigan
e29b53f1e6 generate function assist convert arg names to lower snake case 2021-03-06 09:53:21 -08:00
bors[bot]
7199d5b56d
Merge #7869
7869: Add support for deref assignments to "pull assignment up" assist. r=Veykril a=Jesse-Bakker

Fixes #7867


Co-authored-by: Jesse Bakker <github@jessebakker.com>
2021-03-05 19:52:15 +00:00
Jesse Bakker
ab84a4746b Add support for deref assignments to "pull assignment up" assist.
Fixes #7867
2021-03-05 20:42:23 +01:00
bors[bot]
2b55cce49e
Merge #7880
7880: Honor snippet capability when using the extract function assist r=lnicola a=Arthamys

This fixes issue #7793

Co-authored-by: san <san@alien.parts>
2021-03-05 16:24:32 +00:00
san
769b3bca28 Honor snippet capability in extract function assist 2021-03-05 17:20:26 +01:00
Domantas Jadenkus
5bb4aec05f preserve escape sequences when replacing string with char 2021-03-03 23:20:18 +02:00
Jesse Bakker
1363d60111 Special-case parenthesized and negated expressions in demorgan assist 2021-03-03 13:18:24 +01:00
bors[bot]
0ce539ec96
Merge #7851
7851: Compress tests r=matklad a=matklad

bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2021-03-02 15:46:02 +00:00
Aleksey Kladov
8471da62e6 Compress tests 2021-03-02 18:35:52 +03:00
Conrad Ludgate
2c3c728e0a
chore: remove redundant tests 2021-03-02 15:26:36 +00:00
Conrad Ludgate
b41e73ac12
chore: codegen 2021-03-02 14:55:37 +00:00
Conrad Ludgate
d4fad2be8d
refactor: re-use add_turbo_fish function 2021-03-02 14:30:11 +00:00
Conrad Ludgate
4a36129c7a
chore: fmt + docs 2021-03-02 14:30:10 +00:00
Conrad Ludgate
218390b9fb
chore: rename var 2021-03-02 14:30:10 +00:00
Conrad Ludgate
705712993f
feat: add type ascription assist 2021-03-02 14:30:10 +00:00
Vladyslav Katasonov
7066e6b362 strip useless methods, and unary ops in suggest_name 2021-03-02 16:25:24 +03:00
Vladyslav Katasonov
afc68277f6 pull out suggest_name::* to utils; enchance heuristics 2021-03-02 16:25:22 +03:00
Vladyslav Katasonov
f915ab79fa suggest parameter name before function name 2021-03-02 16:23:00 +03:00
Vladyslav Katasonov
3b75dda745 try to suggest name when extracting variable 2021-03-02 16:23:00 +03:00
bors[bot]
2183d65c97
Merge #7777
7777: Implement line<->block comment assist r=Veykril a=djrenren

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

Co-authored-by: John Renner <john@jrenner.net>
2021-03-02 08:04:38 +00:00
John Renner
f5cde97aae Apply edits 2021-03-01 11:41:22 -08:00
Aleksey Kladov
406d96c7d4 Use consistent naming for assist 2021-02-28 21:14:34 +03:00
Aleksey Kladov
aa04e3bbb2 Don't spam loop-rewriting assist
The more focused the assist, the better!
2021-02-28 21:08:51 +03:00
Domantas Jadenkus
558bcf4e0b generate try_into instead of into 2021-02-27 12:21:57 +02:00
Domantas Jadenkus
d4b6cbe5b6 rename generate_enum_match_method file to match assist name 2021-02-27 12:21:56 +02:00
Domantas Jadenkus
f098a2b31b move into_ and as_ generation to a separate file 2021-02-27 12:21:06 +02:00
Domantas Jadenkus
6f25fef36a cargo fmt 2021-02-27 12:06:00 +02:00
Domantas Jadenkus
e0f08fcc20 add generate_enum_as_method assist 2021-02-27 12:06:00 +02:00
Domantas Jadenkus
642786986f deduplicate some 2021-02-27 12:05:59 +02:00
Domantas Jadenkus
2dcd5d7a7c add generate_enum_into_method assist 2021-02-27 12:05:59 +02:00
Domantas Jadenkus
4ab285a8e5 make generate_enum_is_method work on any variants 2021-02-27 12:05:59 +02:00
Domantas Jadenkus
f67586066d rename existing assist to generate_enum_is_method 2021-02-27 12:05:59 +02:00
Denys Zadorozhnyi
eb3c23588d
Disable "Flip comma" assist inside a macro call 2021-02-26 19:12:53 +02:00
Sanchith Hegde
3eaec3cd33
docs(ide_assists): Change importMergeBehaviour to importMergeBehavior 2021-02-26 12:54:50 +05:30
John Renner
9eecba4dbf Implement line<->block comment assist 2021-02-24 17:13:00 -08:00
bors[bot]
dc14c432f5
Merge #7741
7741: Add convert_for_to_iter_for_each assist r=mattyhall a=mattyhall

Implements one direction of #7681 

I wonder if this tries to guess too much at the right thing here. A common pattern is:

```rust
let col = vec![1, 2, 3];
for v in &mut col {
  *v *= 2;
}
// equivalent to:
col.iter_mut().for_each(|v| *v *= 2);
```

I've tried to detect this case by checking if the expression after the `in` is a (mutable) reference and if not inserting iter()/iter_mut(). This is just a convention used in the stdlib however, so could sometimes be wrong. I'd be happy to make an improvement for this, but not sure what would be best. A few options spring to mind:
1. Only allow this for types that are known to have iter/iter_mut (ie stdlib types)
2. Try to check if iter/iter_mut exists and they return the right iterator type
3. Don't try to do this and just add `.into_iter()` to whatever is after `in`

Co-authored-by: Matt Hall <matthew@quickbeam.me.uk>
2021-02-24 19:24:22 +00:00
Matt Hall
a28e862825 Address further review comments
* Use known names for iter/iter_mut method (simplifies checking if the
  method exists
* Extract code to check assist with fixtures to function
2021-02-24 19:23:12 +00:00
Lukas Wirth
694f7a7e9f Add tests for apply_demorgan 2021-02-24 11:58:37 +01:00
lbrande
9db970ee08 De Morgan's Law assist now correctly inverts <, <=, >, >=. 2021-02-24 11:58:37 +01:00
lbrande
f7a4a87de2 De Morgan's Law assist now correctly parenthesizes binary expressions. 2021-02-24 11:58:37 +01:00
Matt Hall
98a626450d Address review comments
* Move code to build replacement into closure
* Look for iter/iter_mut methods on types behind reference
2021-02-23 19:19:48 +00:00
Matt Hall
506293ca43 Add convert_for_to_iter_for_each assist 2021-02-23 18:10:01 +00:00
Chetan Khilosiya
e4756cb4f6 7526: Rename crate assists to ide_assists. 2021-02-23 00:59:16 +05:30