Commit graph

10242 commits

Author SHA1 Message Date
Lukas Wirth
02e9440e23 Complete while let 2021-03-03 23:04:11 +01:00
Domantas Jadenkus
5bb4aec05f preserve escape sequences when replacing string with char 2021-03-03 23:20:18 +02:00
Lukas Wirth
1914b7723f Don't complete super unless its valid in paths 2021-03-03 21:58:48 +01:00
bors[bot]
d0fa7abc50
Merge #7863
7863: Prevent renaming SelfType and BuiltinType r=Veykril a=Veykril

bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-03-03 18:49:43 +00:00
Lukas Wirth
e194f2edc4 Prevent renaming SelfType and BuiltinType 2021-03-03 19:48:53 +01:00
Lukas Wirth
183ba483a9 Reorder functions in rename.rs 2021-03-03 19:48:35 +01:00
Jonas Schievink
1c057dc3c1 Remove incorrect broken test
`Struct` cannot be named at all in that position, since `super` doesn't
resolve to the block scope
2021-03-03 19:10:56 +01:00
Jesse Bakker
1363d60111 Special-case parenthesized and negated expressions in demorgan assist 2021-03-03 13:18:24 +01:00
kjeremy
41d1b4cd26 Update lexer 2021-03-02 15:33:22 -05: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
bors[bot]
f8152171bb
Merge #7850
7850: Don't add space when joining line to opening quote r=matklad a=matklad

bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2021-03-02 14:19:45 +00:00
Aleksey Kladov
e2fc9411f1 Don't add space when joining line to opening quote 2021-03-02 17:18:45 +03:00
bors[bot]
6a585c6ee2
Merge #7795
7795: Show docs on hover for keywords and primitives r=matklad a=Veykril

![lAWFadkziX](https://user-images.githubusercontent.com/3757771/109369534-eeb4f500-789c-11eb-8f2b-2f9c4e129de3.gif)

It's a bit annoying that this requires the `SyntaxNode` and `Semantics` to be pulled through `hover_for_definition` just so we can get the `std` crate but I couldn't think of a better way.

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-03-02 13:46:50 +00:00
Lukas Wirth
8d305680e6 Show docs on hover for keywords and primitives 2021-03-02 14:41:01 +01:00
bors[bot]
657ec3616f
Merge #7335 #7691
7335: added region folding r=matklad a=LucianoBestia

Regions of code that you'd like to be folded can be wrapped with  `// #region` and `// #endregion` line comments.
This is called "Region Folding". It is originally available for many languages in VSCode. But Rust-analyzer has its own folding function and this is missing.
With this Pull Request I am suggesting a simple solution. 
The regions are a special kind of comments, so I added a bit of code in the comment folding function.
The regex to match are: `^\s*//\s*#?region\b` and `^\s*//\s*#?endregion\b`.
The number of space characters is not important. There is an optional # character. The line can end with a name of the region.
Example:
```rust
// 1. some normal comment
// region: test
// 2. some normal comment
calling_function(x,y);
// endregion: test
```
I added a test for this new functionality in `folding_ranges.rs`.
Please, take a look and comment. 
I found that these exact regexes are already present in the file `language-configuration.json`, but I don't find a way to read this configuration. So my regex is hardcoded in the code.

7691: Suggest name in extract variable r=matklad a=cpud36

Generate better default name in extract variable assist as was mentioned in issue #1587

# Currently supported
(in order of declining precedence)
1. Expr is argument to a function; use corresponding parameter name
2. Expr is result of a function or method call; use this function/method's name
3. Use expr type name (if possible)
4. Fallback to `var_name` otherwise

# Showcase

![generate_derive_variable_name_from_method](https://user-images.githubusercontent.com/4218373/108013304-72105400-701c-11eb-9f13-eec52e74d0cc.gif)
![generate_derive_variable_name_from_param](https://user-images.githubusercontent.com/4218373/108013305-72a8ea80-701c-11eb-957e-2214f7f005de.gif)

# Questions

* Should we more aggressively strip known types? E.g. we already strip `&T -> T`; should we strip `Option<T> -> T`, `Result<T, E> -> T`, and others?
* Integers and floats use `var_name` by default. Should we introduce a name, like `i`, `f` etc?
* Can we return a list and suggest a name when renaming(like IntelliJ does)?
* Should we add counters to remove duplicate variables? E.g. `type`, `type1`, type2`, etc.


Co-authored-by: Luciano Bestia <LucianoBestia@gmail.com>
Co-authored-by: Luciano <31509965+LucianoBestia@users.noreply.github.com>
Co-authored-by: Vladyslav Katasonov <cpud47@gmail.com>
2021-03-02 13:32:06 +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]
91bf5fa827
Merge #7513
7513: NFA parser for mbe matcher r=matklad a=edwin0cheng

Almost straight porting from rustc one, but a little bit slow :(

```
rust-analyzer analysis-stats -q . 
```

From:
```log
Database loaded:     636.11ms, 277minstr
  crates: 36, mods: 594, decls: 11527, fns: 9017
Item Collection:     10.99s, 60ginstr
  exprs: 249618, ??ty: 2699 (1%), ?ty: 2101 (0%), !ty: 932
Inference:           28.94s, 123ginstr
Total:               39.93s, 184ginstr
```

To:
```log
Database loaded:     630.90ms, 277minstr
  crates: 36, mods: 594, decls: 11528, fns: 9018
Item Collection:     13.70s, 77ginstr
  exprs: 249482, ??ty: 2699 (1%), ?ty: 2101 (0%), !ty: 932
Inference:           30.27s, 133ginstr
Total:               43.97s, 211ginstr
```

Fixes #4777

Co-authored-by: Edwin Cheng <edwin0cheng@gmail.com>
2021-03-02 13:20:47 +00:00
bors[bot]
8eee9149e8
Merge #7848
7848: Bump cargo_metadata r=matklad a=lnicola



Co-authored-by: Laurențiu Nicola <lnicola@dend.ro>
2021-03-02 12:31:15 +00:00
Laurențiu Nicola
b20708f6ee Bump cargo_metadata 2021-03-02 14:27:29 +02:00
Aleksey Kladov
3038579c8e Switch from pico-args to xflags 2021-03-02 15:08:20 +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
bors[bot]
b7fa6dfabc
Merge #7844
7844: Fix ProcMacroClient dropped too early in cli r=edwin0cheng a=edwin0cheng

Fix #7843

bors r+

Co-authored-by: Edwin Cheng <edwin0cheng@gmail.com>
2021-03-02 05:20:32 +00:00
Edwin Cheng
877521325f Fix ProcMacroClient dropped too early in cli 2021-03-02 13:14:05 +08:00
bors[bot]
477c1ac105
Merge #7827
7827: Fix proc macro TokenStream::from_str token ids r=vlad20012 a=vlad20012

To be honest, I don't know what it changes from a user perspective.

Internally, this fixes spans (token ids) of a `TokenStream` parsed from a string:

```rust
#[proc_macro_derive(FooDerive)]
pub fn foo_derive(item: TokenStream) -> TokenStream {
    "fn foo() {}".parse().unwrap()
}
```

Previously, `TokenStream` was constructed from tokens with incremental ids (that conflicted with call-site tokens). Now they are `-1`.

Co-authored-by: vlad20012 <beskvlad@gmail.com>
2021-03-02 00:01:14 +00:00
John Renner
f5cde97aae Apply edits 2021-03-01 11:41:22 -08:00
bors[bot]
a6ee8e9e76
Merge #7829 #7833
7829: Bump deps r=matklad a=lnicola

Unfortunately, this brings a bunch of proc macros dep because `cargo-metadata` went full-in on `derive-builder`. I'm not sure what we can do here..

7833: Use chalk_ir::Mutability r=Veykril a=Veykril



Co-authored-by: Laurențiu Nicola <lnicola@dend.ro>
Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-03-01 19:31:01 +00:00
Lukas Wirth
7072f59fc6 Use chalk_ir::Mutability 2021-03-01 19:57:36 +01:00
Jonas Schievink
0dcec31553 Fix find_path when inner items are present 2021-03-01 19:39:17 +01:00
vlad20012
a157f19bf5
Fix proc macro TokenStream::from_str token ids 2021-03-01 19:55:30 +03:00
Laurențiu Nicola
63e8bdb8a2 Bump chalk 2021-03-01 18:17:03 +02:00
Laurențiu Nicola
a445584029 Use an unversioned profile dependency in mbe 2021-03-01 18:11:12 +02:00
bors[bot]
f3139d46b0
Merge #7778
7778: Fix lowering trailing self paths in UseTrees r=Veykril a=Veykril

Noticed that hovering over `self` in a use tree like `use foo::bar::{self}` showing documentation and such for the current module instead of `bar`.

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-03-01 14:50:58 +00:00
Lukas Wirth
5d121cdb45 Introduce Ty::Alias 2021-03-01 14:24:00 +01:00
bors[bot]
cda13d5461
Merge #7823
7823: Being Ty::InferenceVar closer to chalk equivalent r=flodiebold a=Veykril



Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-03-01 12:57:26 +00:00
Lukas Wirth
4b7fc69315 Assert index relationship between type_variable_table and var_unification_table 2021-03-01 13:54:17 +01:00
Lukas Wirth
11a1f13cd1 Being Ty::InferenceVar closes to chalk equivalent 2021-03-01 12:41:29 +01:00
bors[bot]
1c7b2b8c07
Merge #7822
7822: Paperover a bug in cargo-workspace for publish RA r=lnicola a=edwin0cheng

r? @lnicola 

See also https://github.com/pksunkara/cargo-workspaces/issues/39

Co-authored-by: Edwin Cheng <edwin0cheng@gmail.com>
2021-03-01 11:29:47 +00:00
Edwin Cheng
43f52a965c Paperover a bug in cargo-workspace for publish RA 2021-03-01 19:23:45 +08:00
bors[bot]
4e5c496199
Merge #7819 #7820
7819: Speedup heavy tests r=matklad a=matklad

bors r+
🤖

7820: Update vscode README with a small features list r=matklad a=Veykril

Nothing grande but I figured this is a bit better than showing almost nothing 

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-03-01 11:15:19 +00:00
Lukas Wirth
91ff47ef6a Update vscode README with a small features list 2021-03-01 11:08:26 +01:00
Aleksey Kladov
4d14617636 Speedup heavy tests
We used to skip sysroot, but this logic got bitrotted, reinstalling.
2021-03-01 12:14:16 +03:00
Dániel Buga
cb39f2df94 Clean up unused field warning 2021-03-01 09:12:42 +01:00
Dániel Buga
2f7b03b01c Remove redundant semicolon 2021-03-01 09:05:14 +01:00
bors[bot]
5df3ee8274
Merge #7816
7816: Lift Ty::Fn into a struct r=Veykril a=Veykril

bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-02-28 22:54:07 +00:00
Lukas Wirth
407196b8c0 Lift FnPointer into a struct 2021-02-28 23:53:21 +01:00
Lukas Wirth
ca7cd41a48 Fix lowering trailing self paths in UseTrees 2021-02-28 23:44:49 +01:00
cynecx
2cdd1ff1b5 hir_ty: use default type generic for box expressions 2021-02-28 21:18:30 +01:00
Lukas Wirth
a3fd2faba5 Remove Substs from Ty::ForeignType 2021-02-28 20:44:09 +01:00
Lukas Wirth
0e995adcf6 Turn Ty::Tuple variant into a tuple-variant 2021-02-28 20:39:43 +01:00
bors[bot]
2fc137b70f
Merge #7813
7813: Inline TypeCtor into Ty r=flodiebold a=Veykril

This removes the `ApplicationTy` variant from `Ty` bringing the representation a lot closer to chalk's `TyKind`.

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-02-28 19:16:51 +00:00
Lukas Wirth
faf2dd49e4 Fix code_model::Type::walk not walking all types 2021-02-28 20:15:56 +01:00
Aleksey Kladov
406d96c7d4 Use consistent naming for assist 2021-02-28 21:14:34 +03:00
Lukas Wirth
a3f5491a1a Inline TypeCtor into Ty 2021-02-28 19:13:37 +01: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
Edwin Cheng
cff2201c30 NFA parser for mbe matcher 2021-03-01 00:11:14 +08:00
bors[bot]
803ff2e55e
Merge #7804
7804: Introduce TypeCtor::Scalar r=lnicola a=Veykril

`TypeCtor::Int(..) | TypeCtor::Float(..) | TypeCtor::Char | TypeCtor::Bool` => `TypeCtor::Scalar(..)`, in this case we can actually just straight up use `chalk_ir::Scalar` already since its just a POD without any IDs or anything.

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-02-28 13:36:44 +00:00
bors[bot]
7f57a01b3d
Merge #7808
7808: Fix assert split exprs on comma r=edwin0cheng a=edwin0cheng

bors r+

Co-authored-by: Edwin Cheng <edwin0cheng@gmail.com>
2021-02-28 12:53:21 +00:00
Edwin Cheng
30402beeb2 Fix assert split exprs on comma 2021-02-28 20:46:24 +08:00
Vincent Esche
c4e2f32d73 Fixed remaining references to AnalysisChange (now: Change)
(The type was renamed/moved in 8716c4cec3)
2021-02-28 12:57:41 +01:00
Aleksey Kladov
05729fd3c4 For unresolved macros, hightlight only the last segment 2021-02-28 14:29:10 +03:00
Lukas Wirth
7c2dd85a32 Use chalk_ir::Scalar directly 2021-02-28 11:06:37 +01:00
Edwin Cheng
bf8bc5c882 Fix non-latin characters doc comment for mbe 2021-02-28 13:49:08 +08:00
bors[bot]
e0437f899c
Merge #7802
7802: Fix builtin macros split exprs on comma r=edwin0cheng a=edwin0cheng

Fixes #7640

bors r+

Co-authored-by: Edwin Cheng <edwin0cheng@gmail.com>
2021-02-28 05:07:09 +00:00
Edwin Cheng
f5bf1a9650 Fix builtin macros split exprs on comma 2021-02-28 13:06:17 +08:00
Jonas Schievink
6990b89b26 Restrict visibilities to the containing DefMap 2021-02-28 04:47:38 +01:00
Lukas Wirth
5183c9f083 Introduce TypeCtor::Scalar 2021-02-28 01:20:04 +01:00
bors[bot]
f682627da4
Merge #7797
7797: Format generated lints and features manually r=matklad a=lnicola

As `quote` and `rustfmt` leave them on a single line, which makes running `grep` in the repository quite annoying.

Also removes a dead `gen_features.rs` file (`gen_lint_completions.rs` does the same thing).

Co-authored-by: Laurențiu Nicola <lnicola@dend.ro>
2021-02-27 14:56:24 +00:00
bors[bot]
a8cf346b97
Merge #7566
7566: Add benchmark tests for mbe r=matklad a=edwin0cheng

This PR add more real world tests dumped from `rust-analyzer analysis-stats .` to benchmark its performance.

cc #7513

r? @matklad 

Co-authored-by: Edwin Cheng <edwin0cheng@gmail.com>
2021-02-27 14:39:22 +00:00
Laurențiu Nicola
0fb01367f5 Format generated features manually instead of relying on rustfmt 2021-02-27 16:25:06 +02: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
kjeremy
d42730b76e bump crates 2021-02-25 10:34:48 -05:00
John Renner
9eecba4dbf Implement line<->block comment assist 2021-02-24 17:13:00 -08:00
Edwin Cheng
23dbf36c7d Add benchmark test for mbe 2021-02-25 05:47:13 +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
Lukas Wirth
9e8f4d31a4 Pickup ConstReference patterns in FindUsages 2021-02-23 23:31:53 +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
Jonas Schievink
338823f73a is_visible_from_def_map: handle block expressions 2021-02-23 17:56:16 +01:00
Jonas Schievink
cf456d72db Add test 2021-02-23 14:54:01 +01:00
Chetan Khilosiya
eb6cfa7f15 7526: Renamed create ssr to ide_ssr. 2021-02-23 00:59:16 +05:30
Chetan Khilosiya
e4756cb4f6 7526: Rename crate assists to ide_assists. 2021-02-23 00:59:16 +05:30
Jonas Bushart
bd525c9d20 Add isize to the list of suffixed integers in typed_integer
The missing `isize` in `typed_integers` seems to just be an oversight.

Might fix: #7751
2021-02-22 14:48:56 +01:00
Aleksey Kladov
58be1edfbb Make more common assist easier to ues 2021-02-22 16:07:08 +03:00
Laurențiu Nicola
d03cfe141c Add test from #7273 2021-02-21 19:22:14 +02:00
Laurențiu Nicola
48ae948b22 Bump deps 2021-02-21 19:13:11 +02:00
Scott McMurray
0fe44d099a Stop mixing Result and Option with ? in inline_local_variable
Depending on the discussion in RFC#3058 this might not end up being necessary, but I think it's a reasonable change regardless.
2021-02-20 14:45:30 -08:00
bors[bot]
62bc753f8b
Merge #7732
7732: Don't lower TypeBound::Lifetime as GenericPredicate::Error r=flodiebold a=Veykril

Basically we just discard the typebound for now instead when lowering to `GenericPredicate`. I think this shouldn't have any other side effects?

Fixes #7683(hopefully for real this time)

I also played around with introducing `GenericPredicate::LifetimeOutlives` and `GenericPredicate::TypeOutlives`(see b9d6904845) but that won't fix this issue(at least not for now) due to lifetime predicate mismatches when resolving methods so I figure this is a good way to fix it for now.

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-02-20 20:17:14 +00:00
Jeremy Kolb
1f3c637a1d Update tests 2021-02-20 14:59:05 -05:00
Lukas Wirth
0799288f01 Don't write trailing whitespace when formatting empty GenericPredicates 2021-02-20 20:43:04 +01:00
Lukas Wirth
9e5192d917 Don't lower TypeBound::Lifetime as GenericPredicate::Error 2021-02-20 19:08:20 +01:00
Matt Hall
8497b5bd75 Use format_to! to make logic a bit nicer 2021-02-20 17:11:04 +00:00
Matt Hall
b963893349 Fix #7712 retain visibility extracting mod to file 2021-02-20 16:51:16 +00:00
Laurențiu Nicola
4c589aded0 Remove documentation of obsolete extend selection command 2021-02-20 17:18:53 +02:00
bors[bot]
1349f6a791
Merge #7726
7726: feat(completion): add doc(hidden) completion for attributes r=lnicola a=bnjjj



Co-authored-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
2021-02-20 14:18:34 +00:00
Benjamin Coenen
cf32dbd9bf feat(completion): add doc(hidden) completion for attributes
Signed-off-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
2021-02-20 15:16:05 +01:00
Benjamin Coenen
d8559588c0 fix(assist): display where predicates when we want to generate impl
Signed-off-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
2021-02-20 15:05:01 +01:00
Kirill Bulatov
4fe5786c0c Consider import prefix config settings during flyimports 2021-02-20 13:53:50 +02:00
Laurențiu Nicola
c1d37f030f Add test 2021-02-20 12:43:52 +02:00
Laurențiu Nicola
af4148970a Fix incorrect missing field diagnostic with box patterns 2021-02-20 12:36:17 +02:00
Luciano Bestia
864fb063a0 rustfmt 1.4.30-stable 2021-02-18 16:51:21 +01:00
Aleksey Kladov
3db64a400c rename completion -> ide_completion
We don't have completion-related PRs in flight, so lets do it
2021-02-17 17:53:31 +03:00
Lukas Wirth
2887426da0 Revert "Replace usage of ast::NameOrNameRef with ast::NameLike"
This reverts commit e1dbf43cf8.
2021-02-17 15:00:44 +01:00
bors[bot]
4054525c41
Merge #7699
7699: Implement ast::AstNode for NameLike and move it to node_ext r=matklad a=Veykril

With this `search`(and 2 other modules) don't necessarily go through 3 calls of `find_node_at_offset_with_descend` to find the correct node. Also makes the code that searches for NameLikes a bit easier on the eyes imo, though that can be fixed with just a helper function as well so its not that relevant.

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-02-17 13:45:27 +00:00
bors[bot]
056601b41f
Merge #7705
7705: Show hover info of the definition of ConstReference patterns instead of its type r=Veykril a=Veykril

Closes #7671
bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-02-17 13:17:15 +00:00
Lukas Wirth
51dda8ea8e Show hover info of the definition of ConstReference patterns instead of its type 2021-02-17 14:14:58 +01:00
Lukas Wirth
e1dbf43cf8 Replace usage of ast::NameOrNameRef with ast::NameLike 2021-02-17 14:02:34 +01:00
Michał Muskała
528a0bcf9b Avoid transmitting unchanged diagnostics
Reading through the code for diagnostics and observing debug logs, I noticed
that diagnostics are transmitted after every change for every opened file,
even if they haven't changed (especially visible for files with no diagnostics).

This change avoids marking files as "changed" if diagnostics are the same to what
was already sent before. This will only work if diagnostics are always produced in
the same order, but from my limited testing it seems this is the case.
2021-02-17 12:45:17 +01:00
bors[bot]
b3c848ee28
Merge #7703
7703: Allow comments between newlines in chaining hints r=Veykril a=unratito

Currently, chaining hints are not generated if there are comments between newlines, which is a very common pattern:

```rust
let vec = (0..10)
    // Multiply by 2
    .map(|x| x * 2)
    // Add 3
    .map(|x| x + 3)
    .collect::<Vec<i32>>();
```

Besides, it seems a bit weird that this piece of code generates a chaining hint:

```rust
let vec = (0..10)



    .collect::<Vec<i32>>();
```

But this one doesn't:

```rust
let vec = (0..10)

    // This is a comment

    .collect::<Vec<i32>>();
```


Co-authored-by: Paco Soberón <unratito@gmail.com>
2021-02-17 01:24:25 +00:00
bstrie
3c922072ae Remove use of deprecated std::collections::Bound 2021-02-16 18:22:14 -05:00
Paco Soberón
e0eb80eaee Allow comments between newlines in chaining hints 2021-02-17 00:09:56 +01:00
Lukas Wirth
e52bdc55ef Implement ast::AstNode for NameLike and move it to node_ext 2021-02-16 19:27:08 +01:00
bors[bot]
054caa81c5
Merge #7690
7690: Extract `fn load_workspace(…)` from `fn load_cargo(…)` r=matklad a=regexident

Unfortunately in https://github.com/rust-analyzer/rust-analyzer/pull/7595 I forgot to `pub use` (rather than just `use`) the newly introduced `LoadCargoConfig`.

So this PR fixes this now.

It also:

- splits up `fn load_cargo` into a "workspace loading" and a "project loading" phase
- adds a `progress: &dyn Fn(String)` to allow third-parties to provide CLI progress updates, too

The motivation behind both of these is the fact that rust-analyzer currently does not support caching.
As such any third-party making use of `ra_ap_…` needs to providing a caching layer itself.
Unlike for rust-analyzer itself however a common use-pattern of third-parties is to analyze a specific target (`--lib`/`--bin <BIN>`/…) from a specific package (`--package`). The targets/packages of a crate can be obtained via `ProjectWorkspace::load(…)`, which currently is performed inside of `fn load_cargo`, effectively making the returned `ProjectWorkspace` inaccessible to the outer caller. With this information one can then provide early error handling via CLI (in case of ambiguities or invalid arguments, etc), instead of `fn load_cargo` failing with a possibly obscure error message. It also allows for annotating the persisted caches with its specific associated package/target selector and short-circuit quickly if a matching cache is found on disk, significantly cutting load times.

Before:

```rust
pub struct LoadCargoConfig {
    pub cargo_config: &CargoConfig,
    pub load_out_dirs_from_check: bool,
    pub with_proc_macro: bool,
}

pub fn load_cargo(
    root: &Path,
    config: &LoadCargoConfig
) -> Result<(AnalysisHost, vfs::Vfs)> {
    // ...
}
```

After:

```rust
pub fn load_workspace(
    root: &Path,
    config: &CargoConfig,
    progress: &dyn Fn(String),
) -> Result<ProjectWorkspace> {
        // ...
}

pub struct LoadCargoConfig {
    pub load_out_dirs_from_check: bool,
    pub with_proc_macro: bool,
}

pub fn load_cargo(
    ws: ProjectWorkspace,
    config: &LoadCargoConfig,
    progress: &dyn Fn(String),
) -> Result<(AnalysisHost, vfs::Vfs)> {
    // ...
}
```


Co-authored-by: Vincent Esche <regexident@gmail.com>
2021-02-16 18:24:28 +00:00
Jonas Schievink
50d18eb0a6 Use cfg(target_arch) instead of a Cargo feature
Not that WASM works right now anyways...
2021-02-16 18:50:06 +01:00
bors[bot]
c9672a0539
Merge #7657
7657: utf8 r=matklad a=matklad

- Prepare for utf-8 offsets
- reduce code duplication in tests
- Make utf8 default, implement utf16 in terms of it
- Make it easy to add additional context for offset conversion
- Implement utf8 offsets

closes #7453

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2021-02-16 16:34:22 +00:00
Aleksey Kladov
1fcf687657 Fix bitrotted module name 2021-02-16 19:17:32 +03:00
Aleksey Kladov
f3d56b89c5 Enable offset-encoding capability 2021-02-16 19:17:32 +03:00
Aleksey Kladov
c8b9ec8e62 Implement utf8 offsets 2021-02-16 19:17:32 +03:00
Aleksey Kladov
0025836f26 Make it easy to add additional context for offset conversion 2021-02-16 19:17:32 +03:00
Aleksey Kladov
95209aa3f8 Make utf8 default, implement utf16 in terms of it 2021-02-16 19:17:32 +03:00
Aleksey Kladov
00cc778c8c reduce code duplication in tests 2021-02-16 19:17:32 +03:00
Aleksey Kladov
2cb4ac9eb4 Prepare for utf-8 offsets 2021-02-16 19:17:32 +03:00
kjeremy
f9bb398cc5 Fix a few clippy::perf warnings 2021-02-16 10:55:34 -05:00
Vincent Esche
1a44168260 Split pub fn cargo_load into pub fn load_workspace_at and pub fn load_workspace 2021-02-16 16:37:52 +01:00
bors[bot]
cc49502ab4
Merge #7695
7695: Bump lsp-types r=matklad a=kjeremy

Nothing to see here...

Co-authored-by: kjeremy <kjeremy@gmail.com>
2021-02-16 14:32:33 +00:00
kjeremy
88a5e1d036 Bump lsp-types 2021-02-16 09:21:07 -05:00
bors[bot]
b7a6d830be
Merge #7687
7687: Specialization for async traits r=matklad a=arnaudgolfouse

Fixes #7669.

Adapting the parser seemed to be all that was needed, but I am not very experienced with the codebase. Is this enough ?

Co-authored-by: Arnaud <arnaud.golfouse@laposte.net>
2021-02-16 14:16:47 +00:00
bors[bot]
88e8b0a5fa
Merge #7620
7620: Support control flow in `extract_function` assist r=matklad a=cpud36

Support `return`ing from outer function, `break`ing and `continue`ing outer loops when extracting function.

# Example
Transforms
```rust
fn foo() -> i32 {
  let items = [1,2,3];
  let mut sum = 0;
  for &item in items {
    <|>if item == 42 {
      break;
    }<|>
    sum += item;
  }
  sum
}
```
Into 
```rust
fn foo() -> i32 {
  let items = [1,2,3];
  let mut sum = 0;
  for &item in items {
    if fun_name(item) {
      break;
    }
    sum += item;
  }
  sum
}

fn fun_name(item: i32) -> bool {
  if item == 42 {
    return true;
  }
  false
}
```

![add_explicit_type_infer_type](https://user-images.githubusercontent.com/4218373/107544222-0fadf280-6bdb-11eb-9625-ed6194ba92c0.gif)

# Features

Supported variants
- break and function does not return => uses `bool` and plain if
- break and function does return => uses `Option<T>` and matches on it
- break with value and function does not return => uses `Option<T>` and if let
- break with value and function does return => uses `Result<T, U>` and matches on t
- same for `return` and `continue`(but we can't continue with value)

Assist does handle nested loops and nested items(like functions, modules, impls)

Try `expr?` operator is allowed together with `return Err(_)` and `return None`.
`return expr` is not allowed.

# Not supported
## Mixing `return` with `break` or `continue`
If we have e.g. a `return` and a `break` in the selected code, it is unclear what the produced code should look like.
We can try `Result<T, Option<U>>` or something like that, but it isn't idiomatic, nor it is established. Otherwise, implementation
is relatively simple.

## `break` with label
Not sure how to handle different labels for multiple `break`s.

[edit] implemented try `expr?`

Co-authored-by: Vladyslav Katasonov <cpud47@gmail.com>
2021-02-16 14:01:09 +00:00
Arnaud
95d239da99 Specialization for async traits 2021-02-15 18:33:12 +01:00
ivan770
66de90b85a
Actually fix runnable order 2021-02-15 16:09:50 +02:00
bors[bot]
7435b9e98c
Merge #7661
7661: Start LSP 3.17 support r=kjeremy a=kjeremy

Companion to https://github.com/gluon-lang/lsp-types/pull/199 which <strike>has not been merged yet</strike>  has been merged.

This doesn't opt into any 3.17 functionality yet.

Co-authored-by: Jeremy Kolb <kjeremy@gmail.com>
2021-02-14 19:52:38 +00:00
Jeremy Kolb
8105418b25 Start LSP 3.17 support 2021-02-14 14:51:29 -05:00
Michał Muskała
e640fa967c Simplify find_crlf
This is both simpler to read and compiles to better code:
https://rust.godbolt.org/z/MxKodv
2021-02-14 20:20:14 +01:00
bors[bot]
425c56aa52
Merge #7676
7676: Make it clear which client-side commands we use r=matklad a=matklad

bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2021-02-14 16:40:44 +00:00
Aleksey Kladov
9852537809 Make it clear which client-side commands we use 2021-02-14 19:36:44 +03:00
bors[bot]
a0322defc3
Merge #7656
7656: Implement constructor usage search for almost all items r=matklad a=Veykril

This PR moves the filering for enum constructors to the HIR, with this unprefixed variants as well as when the enum has been renamed via use will then still show up properly.
We now walk the ast of the `NameRef` up until we find a `PathExpr`(which also handles `CallExpr` for tuple-type structs and variants already) or a `RecordExpr`. For enum search we then take the `path` out of that expression and do a resolution on it to compare it with the definition enum.
With this PR we now support searching for all constructor literals, Unit-, Tuple- and Record-Structs, Unit-, Tuple- and Record-Variants as well as Unions.

There is one shortcoming due to how the search is triggered. Unit Variants constructors can't be searched as we have no position for it to kick off the search(since a comma doesn't have to exist for the last variant).

Closes #2549 though it doesn't implement it as outlined in the issue since the reference kind was removed recently, though I believe the approach taken here is better personally.

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-02-14 16:17:03 +00:00
bors[bot]
d50a37d3aa
Merge #7643 #7663
7643: Automatically detect the rustc-src directory (fixes #3517) r=matklad a=bnjbvr

If the configured rustcSource was not set, then try to automatically
detect a source for the sysroot rustc directory.

I wasn't sure how to do it in the case of the project.json file, though.

7663: Tolerate spaces in nix binary patching r=matklad a=CertainLach

If path to original file contains space (I.e on code insiders, where
default data directory is ~/Code - Insiders/), then there is syntax
error evaluating src arg.

Instead pass path as str, and coerce to path back in nix expression

Co-authored-by: Benjamin Bouvier <public@benj.me>
Co-authored-by: Yaroslav Bolyukin <iam@lach.pw>
2021-02-14 15:42:07 +00:00
bors[bot]
63c5c92856
Merge #7668
7668: Finalize rename infra rewrite r=matklad a=Veykril

This should be the final PR in regards to rewriting rename stuff, #4290.

It addresses 3 things:
	- Currently renaming import aliases causes some undesired behavior(see #5198) which is why this PR causes us to just return an error if an attempt at renaming an alias is made for the time being. Though this only prevents it from happening when the alias import is renamed, so its not too helpful.
	- Fixes #6898
	- If we are inside a macro file simply rename the input name node as there isn't really a way to do any of the fancy shorthand renames and similar things as for that we would have to exactly know what the macro generates and what not.

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-02-14 15:29:00 +00:00
Lukas Wirth
7b64622780 Don't rename field record patterns directly 2021-02-13 23:47:21 +01:00
Domantas Jadenkus
150ed80c51 strip type parameter defaults when generating impl generics 2021-02-13 23:59:51 +02:00
bors[bot]
84c9970db5
Merge #7664
7664: refactor impl generation in assists r=Veykril a=jDomantas

Follow-up to #7659: all impl generation in assists (at least what I found) is now done through `utils::{generate_impl_text, generate_trait_impl_text}`.

Co-authored-by: Domantas Jadenkus <djadenkus@gmail.com>
2021-02-13 21:37:35 +00:00
bors[bot]
7f751d6413
Merge #7665
7665: Don't classify attribute macros as their path unless it's a function with the proc_macro_attribute attribute r=Veykril a=Veykril

bors r+
Closes #6389

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-02-13 21:12:49 +00:00
Lukas Wirth
403a63d2b4 Don't classify attribute macros as their path unless it's a function with the proc_macro_attribute attribute 2021-02-13 22:11:31 +01:00
Domantas Jadenkus
7f100fff92 cargo fmt 2021-02-13 22:51:48 +02:00
Domantas Jadenkus
36e8a55bee use generate_impl_text in replace_derive_with_manual_impl 2021-02-13 22:51:07 +02:00
Domantas Jadenkus
3364ac8b11 use generate_impl_text in generate_impl 2021-02-13 22:45:22 +02:00
Lukas Wirth
9b04506924 Fallback to renaming input NameRef node for macros when inside macro 2021-02-13 21:41:04 +01:00
Domantas Jadenkus
ff7ea7c308 use generate_impl_text in generate_from_impl 2021-02-13 22:27:57 +02:00
Lukas Wirth
1901172841 Prevent aliases from being renamed for now 2021-02-13 20:49:04 +01:00
Vladyslav Katasonov
37a8cec638 expose hir::Type::type_paramters
Used to get E parameter from `Result<T, E>`
2021-02-13 22:04:52 +03:00
Vladyslav Katasonov
4be260d693 allow try expr? with return None in extracted function 2021-02-13 22:04:52 +03:00
Vladyslav Katasonov
9eb19d92dd allow try expr? when extacting function 2021-02-13 22:04:52 +03:00
Vladyslav Katasonov
f345d1772a handle return, break and continue when extracting function 2021-02-13 22:04:52 +03:00
Vladyslav Katasonov
0ad3d7938f migrate body span to {parent,text_range}
This simplifies api as we are not duplicating code from syntax crate
2021-02-13 22:04:52 +03:00
Lukas Wirth
ed1f2b58f7 Group generate getter/setter assist 2021-02-13 19:58:58 +01:00
bors[bot]
205e72f34d
Merge #7596
7596: Move CodeLens to ide crate r=ivan770 a=ivan770

Closes #7579

Co-authored-by: ivan770 <leshenko.ivan770@gmail.com>
2021-02-13 17:50:55 +00:00
Benjamin Bouvier
4a6e602c94 Allow automatically detect the rustc-src directory (fixes #3517).
If the configured rustcSource is set to "discover", try to automatically
detect a source from the sysroot rustc directory.
2021-02-13 18:20:46 +01:00
ivan770
4c2b201b7d
Make annotations tests similar to those in runnables 2021-02-13 19:18:13 +02:00
Lukas Wirth
8ac6041bcf Only use HIR when searching for enum constructors, otherwise fall back to AST 2021-02-13 17:57:14 +01:00
Luciano Bestia
790bda1f85 corrected no newline at end of file 2021-02-13 17:57:05 +01:00
Luciano Bestia
a28f9545e1 removed logging stuff 2021-02-13 17:50:52 +01:00
Luciano
75015b6eaa
Update crates/ide/src/folding_ranges.rs
Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-02-13 17:46:26 +01:00
ivan770
ee049b256a
Improve runnable annotations order, fix incorrect ignore detection 2021-02-13 15:47:53 +02:00
Domantas Jadenkus
b07f530e3a cargo fmt 2021-02-13 15:34:40 +02:00
ivan770
c46b32c449
Added annotation tests 2021-02-13 15:27:04 +02:00
Domantas Jadenkus
375c13cd44 make it work for record-style variants 2021-02-13 14:57:06 +02:00
Domantas Jadenkus
6799088579 update doc 2021-02-13 14:46:41 +02:00
Domantas Jadenkus
3a4d273ac2 handle generic enums 2021-02-13 14:46:28 +02:00
Domantas Jadenkus
e63116c74f allow any field type 2021-02-13 14:29:26 +02:00
Domantas Jadenkus
fee05b0491 use Self instead of enum name 2021-02-13 14:27:38 +02:00
ivan770
02ad828c6d
Fix incorrect references annotation 2021-02-13 13:22:12 +02:00
ivan770
185da286d2
Moved CodeLens to ide crate 2021-02-13 13:07:47 +02:00
Lukas Wirth
c395dd1032 Implement constructor usage search for almost all items
For all struct kinds, unions and enums, as well as for record- and
tuple-variants but not for unit-variants, as these have no trailing
character we can anchor the search to. Functionality wise it is
implemented though.
2021-02-12 21:30:55 +01:00
Lukas Wirth
fd6cf4d566 Update references test output 2021-02-12 19:00:37 +01:00
Lukas Wirth
c5be0b2589 Use NameLike in FileReference directly as its not exported from ide anymore 2021-02-12 18:58:29 +01:00
Lukas Wirth
d644728d82 Refactor reference searching to work with the ast 2021-02-12 18:58:28 +01:00
Lukas Wirth
43ccbf4360 Remove unused ReferenceSearchResult functions 2021-02-12 18:58:28 +01:00