Commit Graph

12524 Commits

Author SHA1 Message Date
mahdi-frms
d38f36e5af generate method assist uses existing impl blocks 2021-08-09 21:06:24 +04:30
mahdi-frms
99570f32d8 refactor: use single next space 2021-08-09 21:06:24 +04:30
mahdi-frms
b777e498fe refactor: use single fn_args 2021-08-09 21:06:24 +04:30
mahdi-frms
9ca73528ee generate method assist 2021-08-09 21:06:24 +04:30
Aleksey Kladov
ce8400bbfd internal: drop latest requests tracking
From the dawn of time, when dinosaurs roamed the and we didn't have
hierarchical profiling, there was the `latest_requests` infra we used to
track the time of ten last requests.

Today, no one is actually using it and, what's more, it itself became
pretty useless -- LSP grew way more chatty, and 10 requests don't really
paint any kind of picture.

Personally, it's been years since I last looked at latest requests in
the status output.

So, let's remove a tiny bit of state from the big ball of complexity
that is `GlobalState` and `main_loop`!
2021-08-09 18:56:19 +03:00
Aleksey Kladov
3e5b155716 fix: avoid pathological macro expansions
Today, rust-analyzer (and rustc, and bat, and IntelliJ) fail badly on
some kinds of maliciously constructed code, like a deep sequence of
nested parenthesis.

"Who writes 100k nested parenthesis" you'd ask?

Well, in a language with macros, a run-away macro expansion might do
that (see the added tests)! Such expansion can be broad, rather than
deep, so it bypasses recursion check at the macro-expansion layer, but
triggers deep recursion in parser.

In the ideal world, the parser would just handle deeply nested structs
gracefully. We'll get there some day, but at the moment, let's try to be
simple, and just avoid expanding macros with unbalanced parenthesis in
the first place.

closes #9358
2021-08-09 16:15:02 +03:00
Aleksey Kladov
9aa6be71a5 internal: remove useless helpers
We generally avoid "syntax only" helper wrappers, which don't do much:
they make code easier to write, but harder to read. They also make
investigations harder, as "find_usages" needs to be invoked both for the
wrapped and unwrapped APIs
2021-08-09 15:58:21 +03:00
Laurențiu Nicola
1b7cdac516 Fix typo in reference modifier description 2021-08-09 14:06:14 +03:00
bors[bot]
caac771439
Merge #9735
9735: Add assist to sort members alphabetically. r=matklad a=vsrs

Supports traits, impls, structs, unions and enums (including inner struct variants). Does not support modules yet.

```rust
en┃um Animal {
  Dog(String, f64),
  Cat { weight: f64, name: String },
}
```
->
```rust
enum Animal {
  Cat { weight: f64, name: String },
  Dog(String, f64),
}
```
---
```rust
enum Animal {
  Dog(String, f64),
  Cat {┃ weight: f64, name: String },
}
```
->
```rust
enum Animal {
  Dog(String, f64),
  Cat { name: String, weight: f64 },
}
```
---
More samples in docs 0b7835619a/crates/ide_assists/src/handlers/sort_items.rs (L12-L83).

Relates #6110


Co-authored-by: vsrs <vit@conrlab.com>
2021-08-09 10:21:14 +00:00
Aleksey Kladov
66960c095c minor: as per code-styple, add invariant comment 2021-08-09 13:13:02 +03:00
bors[bot]
5664a2b0b3
Merge #9814
9814: Generate default impl when converting `#[derive(Debug)]` to manual impl r=yoshuawuyts a=yoshuawuyts

This patch makes it so when you convert `#[derive(Debug)]` to a manual impl, a default body is provided that's equivalent to the original output of `#[derive(Debug)]`. This should make it drastically easier to write custom `Debug` impls, especially when all you want to do is quickly omit a single field which is `!Debug`.

This is implemented for enums, record structs, tuple structs, empty structs - and it sets us up to implement variations on this in the future for other traits (like `PartialEq` and `Hash`).

Thanks!

## Codegen diff
This is the difference in codegen for record structs with this patch:
```diff
struct Foo {
    bar: String,
}

impl fmt::Debug for Foo {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
-        todo!();
+        f.debug_struct("Foo").field("bar", &self.bar).finish()
    }
}
```

Co-authored-by: Irina Shestak <shestak.irina@gmail.com>
Co-authored-by: Yoshua Wuyts <yoshuawuyts@gmail.com>
Co-authored-by: Yoshua Wuyts <yoshuawuyts+github@gmail.com>
2021-08-08 22:30:37 +00:00
Yoshua Wuyts
59cdb51ef3 Remove unwraps 2021-08-09 00:29:38 +02:00
Yoshua Wuyts
f424cd9c7e
Update crates/test_utils/src/minicore.rs
Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-08-09 00:00:09 +02:00
bors[bot]
044d99e162
Merge #9816
9816: feat: Implement if_to_bool_then assist r=Veykril a=Veykril

One half of https://github.com/rust-analyzer/rust-analyzer/issues/8413

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-08-08 18:42:19 +00:00
Yoshua Wuyts
f64aacc0c1 Use minicore 2021-08-08 18:58:42 +02:00
Yoshua Wuyts
5a3c3a029c exclude files from tidy check 2021-08-08 18:44:54 +02:00
Lukas Wirth
3b7c713af3 Implement if_to_bool_then assist 2021-08-08 17:56:34 +02:00
Laurențiu Nicola
ab10ac7d92 Increase chalk overflow depth 2021-08-08 18:40:28 +03:00
Yoshua Wuyts
dcbf385ffc use make::name_ref 2021-08-08 16:31:28 +02:00
Yoshua Wuyts
e26ba72333 Update replace_derive_with_manual_impl.rs 2021-08-08 16:26:25 +02:00
Yoshua Wuyts
a2e5fc659d Improve naming and add comments 2021-08-08 16:26:25 +02:00
Yoshua Wuyts
720508a2df dedup struct debug impl code 2021-08-08 16:26:25 +02:00
Yoshua Wuyts
cc3ff1b486 Fix enum debug indent level 2021-08-08 16:26:25 +02:00
Yoshua Wuyts
4b7ae9fedc generate Debug for enums 2021-08-08 16:26:25 +02:00
Yoshua Wuyts
a1f2c7adcd rename variables
According to https://github.com/rust-analyzer/rust-analyzer/blob/master/docs/dev/style.md#variable-naming
2021-08-08 16:26:25 +02:00
Yoshua Wuyts
aa09141a8a finish debug_struct impls 2021-08-08 16:26:25 +02:00
Yoshua Wuyts
fd7236c791 debug for record field structs 2021-08-08 16:26:25 +02:00
Yoshua Wuyts
e2ab2e12a0 wip 2021-08-08 16:24:54 +02:00
Irina Shestak
f2e547d587 impl Debug def from trait 2021-08-08 16:24:54 +02:00
Aleksey Kladov
0e437c809b fix: add ! to macro completions with existing arg 2021-08-08 15:53:31 +03:00
bors[bot]
546d718a7e
Merge #9808
9808: fix: Look for enum variants and trait assoc functions when looking for lang items r=matklad a=Veykril

Examples for lang enum variants are the `Option` variants.
Assoc trait functions aren't being seen since they aren't declared in the direct module scope.

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-08-08 10:41:45 +00:00
bors[bot]
b07c83f8b0
Merge #9810
9810: Add reference here r=matklad a=ivan770

Superseds #6853 

Co-authored-by: ivan770 <ivan@ivan770.me>
2021-08-08 10:35:00 +00:00
ivan770
be3e70c604
Add reference here diagnostic 2021-08-08 10:12:40 +02:00
Lukas Wirth
50d46863ef Look for enum variants and trait assoc functions when looking for lang items 2021-08-07 22:30:13 +02:00
bors[bot]
6ea07fc26f
Merge #9809
9809: internal: Simplify r=Veykril a=Veykril

bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-08-07 20:16:58 +00:00
Lukas Wirth
c4a119f433 Simplify 2021-08-07 22:16:15 +02:00
Alex Good
b111357b54
Copy the proc_macro crate for the 1.56 ABI 2021-08-07 16:34:59 +01:00
Florian Diebold
16ab75a83a Upgrade Chalk 2021-08-07 13:12:35 +02:00
Jonas Schievink
a310d74536 Don't publish diagnostics in library source roots 2021-08-06 16:14:54 +02:00
Jonas Schievink
5386dc648e Bless tests 2021-08-06 15:59:58 +02:00
Jonas Schievink
30e472a12a Don't include empty suggestions 2021-08-06 15:58:55 +02:00
Jonas Schievink
efe662d474 Include suggested replacement in diagnostics 2021-08-06 15:52:47 +02:00
Florian Diebold
ac4f3e61f8 Fix binders with bare dyn trait
Fixes #9639.
2021-08-05 22:44:38 +02:00
bors[bot]
a16b06afa7
Merge #9793
9793: Remove unused structs in ide_db r=matklad a=michalmuskala



Co-authored-by: Michał Muskała <michal@muskala.eu>
2021-08-05 17:56:19 +00:00
bors[bot]
a7178cabf5
Merge #9785
9785: feature: Add completion for struct literals in which all fields are visible. r=Veykril a=Afourcat

This PR adds a new completion for struct literal.

It Implements the feature discussed in the issue #9610.

![RAExample3](https://user-images.githubusercontent.com/35599359/128211142-116361e9-7a69-425f-83ea-473c6ea47b26.gif)

This PR introduce a repetition in the source files `crates/ide_completion/render/pattern.rs` and `crates/ide_completion/render/struct_literal.rs` that may be fix in another PR.

Co-authored-by: Alexandre Fourcat <afourcat@gmail.com>
2021-08-05 16:17:38 +00:00
Michał Muskała
33c7c23b03 Remove unused structs in ide_db 2021-08-05 12:04:37 +01:00
bors[bot]
80f522091a
Merge #9790
9790: fix: extract_type_alias extracts generics correctly r=Veykril a=Veykril

Fixes #8335
bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-08-05 00:54:49 +00:00
Lukas Wirth
b6d574642d extract_type_alias extracts generics correctly 2021-08-05 02:54:06 +02:00
bors[bot]
950efff5c6
Merge #9780
9780: Support exclusive_range_pattern r=matklad a=lf-

Fix #9779

Co-authored-by: Jade <software@lfcode.ca>
2021-08-04 18:12:37 +00:00
Lukas Wirth
01413dd7d4 extract_function does not move locals defined outside of loops 2021-08-04 20:00:45 +02:00