Commit graph

11754 commits

Author SHA1 Message Date
Jonas Schievink
ee374ff1ee fix: don't complete derive macros as fn-like macros 2021-06-08 17:31:47 +02:00
Lukas Wirth
1d74ef1d98 Don't complete values in type position 2021-06-08 16:50:10 +02:00
Jonas Schievink
8482329d65 source_to_def: skip items with no def 2021-06-08 16:42:48 +02:00
bors[bot]
590472607c
Merge #9171
9171: internal: simplify r=Veykril a=Veykril

bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-06-07 18:46:18 +00:00
Lukas Wirth
2987e05f15 simplify 2021-06-07 20:45:17 +02:00
bors[bot]
7f16b42188
Merge #9170
9170: internal: Remove unnecessary `completion::macro_in_item_position` module r=Veykril a=Veykril

bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-06-07 17:47:23 +00:00
Lukas Wirth
b29e8ed994 Remove unnecessary completion::macro_in_item_position 2021-06-07 19:46:25 +02:00
bors[bot]
2f376f7475
Merge #9169
9169: internal: steps towards attribute macro token mapping r=jonas-schievink a=jonas-schievink

This doesn't work yet, but we seem to be getting a bit further along (for example, we now stop highlighting `use` items inside item with attribute macros as if they were written verbatim).

bors r+

Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
2021-06-07 17:37:48 +00:00
Jonas Schievink
33be5762e5 Attempt to track attr macros during highlighting 2021-06-07 19:32:28 +02:00
Lukas Wirth
aa29364f83 Reorder CompletionContext fields 2021-06-07 19:06:03 +02:00
bors[bot]
1aff3b4dfc
Merge #9144
9144: Extend convert_tuple_struct_to_named_struct to also apply to enum tuple variants r=matklad a=joshuawarner32

This is largely copied and adapted from the existing `convert_tuple_struct_to_named_struct` code.

Not sure if maybe some of this code can/should be shared between those two assists - but the differences are significant enough to make it at least seem like a non-trivial refactor.

Co-authored-by: Joshua Warner <joshuawarner32@gmail.com>
2021-06-07 16:17:14 +00:00
Jonas Schievink
33e747d786 Make "expand macro" command work with attribute macros 2021-06-07 16:05:36 +02:00
bors[bot]
8b6c3eaaeb
Merge #9164
9164: internal: Reduce the number of direct fields in `CompletionContext` some more r=Veykril a=Veykril

Doesn't make the code much simpler yet.
bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-06-07 12:17:28 +00:00
Lukas Wirth
4eabcb2c01 Move more things into PathCompletionContext 2021-06-07 14:08:05 +02:00
bors[bot]
5f7fc5ae68
Merge #9161
9161: Fix incorrect config usage in hover references r=Veykril a=Veykril

bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-06-07 10:33:13 +00:00
Lukas Wirth
88bc4f17fd Fix incorrect config usage in hover references 2021-06-07 12:32:25 +02:00
Laurențiu Nicola
15dd475988 Make Documentation::new non-generic 2021-06-07 12:58:51 +03:00
Jade
34ce05781f feat: goto def on impl items also goes to the defn in the trait
It was trivial to extend this to associated consts/associated types and
I just didn't think of it.
2021-06-06 21:52:00 -07:00
Jade
8a57c73640 feat: goto definition on an impl fn goes to that fn in the trait
e.g. if you have a trait T and `impl T for S` for some struct, if you
goto definition on some function name inside the impl, it will go to the
definition of that function inside the `trait T` block, rather than the
current behaviour of not going anywhere at all.
2021-06-06 21:51:17 -07:00
Lukas Wirth
e475bcdcc6 Simplify CompletionContext by introducing a path CallKind enum 2021-06-06 20:02:26 +02:00
Jonas Schievink
8d87f9b298 Handle attribute macros in descend_into_macros 2021-06-06 17:03:37 +02:00
Jonas Schievink
1d5c60ff54 Replace attribute with equivalent whitespace
This is needed to that the `TokenMap` we create contains offsets that
match the source.
2021-06-06 16:48:13 +02:00
Joshua Warner
9b74dd0c04 fmt 2021-06-05 17:09:56 -07:00
Joshua Warner
18f796a728 Refactor to be just one assist 2021-06-05 15:29:29 -07:00
bors[bot]
d616a6a456
Merge #9149
9149: feat: Support goto-definition for include macros input path r=Veykril a=Veykril

![0l6l9iWPNE](https://user-images.githubusercontent.com/3757771/120891155-3fa85800-c607-11eb-9b20-7ac330dceb4b.gif)
Fixes #5871


Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-06-05 19:26:33 +00:00
bors[bot]
b68407fab8
Merge #9150
9150: Unescape generated clippy lints r=lnicola a=Veykril



Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-06-05 18:16:57 +00:00
bors[bot]
ad9234fef2
Merge #9140
9140: feat: Render documentation for derive completion r=Veykril a=Veykril

![eEzGiq2wNa](https://user-images.githubusercontent.com/3757771/120847308-9c5a3300-c573-11eb-958d-e0f22f4757ed.gif)

Nothing fancy as all the std derives aren't really documented though maybe some 3rd party crates document them equally to their trait counterparts.

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-06-05 17:23:40 +00:00
Lukas Wirth
fc06058a76 Unescape generated clippy lints 2021-06-05 19:14:53 +02:00
Lukas Wirth
5391f9c63c Support goto-definition for include macro paths 2021-06-05 19:04:50 +02:00
bors[bot]
5092d8c1ae
Merge #9147
9147: internal: enable proc macros and build scripts in cli r=flodiebold a=lnicola



Co-authored-by: Laurențiu Nicola <lnicola@dend.ro>
2021-06-05 12:29:52 +00:00
Laurențiu Nicola
18484365e6 Enable proc macros and build scripts by default in CLI 2021-06-05 15:20:41 +03:00
bors[bot]
4c54ec1c3c
Merge #9148
9148: minor: Prevent renaming of aliases on usages r=Veykril a=Veykril

Otherwise trying to rename a usage that goes through an alias will still rename the aliased item instead, cc https://github.com/rust-analyzer/rust-analyzer/issues/5671
bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-06-05 11:16:46 +00:00
Lukas Wirth
d30f2d43db Prevent renaming of aliases on usages 2021-06-05 13:15:07 +02:00
bors[bot]
fec00f4e13
Merge #9146
9146: minor: Fix incorrect list nesting in format_like feature description r=Veykril a=Veykril

bors r+
Closes #6261

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-06-05 10:44:36 +00:00
Lukas Wirth
abc941d2c8 Fix incorrect list nesting in format_like feature description 2021-06-05 12:43:45 +02:00
Florian Diebold
d174b919dc Enable attribute macro expansion in analysis-stats
Before:
```
> $ rust-analyzer -q analysis-stats --with-proc-macro --load-output-dirs .
Database loaded:     19.08s, 277minstr
  crates: 34, mods: 688, decls: 13202, fns: 10412
Item Collection:     16.21s, 76ginstr
  exprs: 290580, ??ty: 2508 (0%), ?ty: 1814 (0%), !ty: 947
Inference:           27.46s, 108ginstr
Total:               43.67s, 184ginstr
```
After:
```
> $ ./target/release/rust-analyzer -q analysis-stats --with-proc-macro --load-output-dirs .
Database loaded:     1.09s, 277minstr
  crates: 34, mods: 688, decls: 14790, fns: 11006
Item Collection:     18.20s, 78ginstr
  exprs: 297826, ??ty: 493 (0%), ?ty: 558 (0%), !ty: 342
Inference:           28.34s, 111ginstr
Total:               46.54s, 190ginstr
```
2021-06-05 11:29:24 +02:00
Joshua Warner
ca9ffba047 Add assist for converting a tuple enum variant to a named variant 2021-06-04 21:48:32 -07:00
Lukas Wirth
544eca10d6 Complete third-party attributes 2021-06-04 21:07:19 +02:00
Lukas Wirth
7524850831 Render documentation for derive completion 2021-06-04 20:58:12 +02:00
Lukas Wirth
1bd04d9064 Don't inline mutable locals in 'inline_local_variable' 2021-06-04 20:43:48 +02:00
bors[bot]
98395f29a4
Merge #9138
9138: feat: Implement hover for lints r=Veykril a=Veykril

fixes https://github.com/rust-analyzer/rust-analyzer/issues/8857, fixes https://github.com/rust-analyzer/rust-analyzer/issues/3941

![URXBanNxYe](https://user-images.githubusercontent.com/3757771/120830905-4bd8da80-c55f-11eb-9f55-ff5a321726fa.gif)

We also generate the default lints(and lint groups 🎉) instead now by invoking `rustc -W help` and parsing the output from that.


Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-06-04 17:45:37 +00:00
Lukas Wirth
0c89f38378 Replace - with _ in generated lint names 2021-06-04 19:10:52 +02:00
Lukas Wirth
0b9ba4977e Generate default lint groups 2021-06-04 18:55:08 +02:00
Lukas Wirth
343df88ac7 Generate default lint completions 2021-06-04 18:35:19 +02:00
Lukas Wirth
5d17b6a687 Implement hover for lints 2021-06-04 17:03:18 +02:00
bors[bot]
92d91050c4
Merge #9137
9137: fix: fix incorrect "unresolved import" error when using derive helpers r=jonas-schievink a=jonas-schievink

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

cursed bug

bors r+

Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
2021-06-04 14:51:39 +00:00
Jonas Schievink
20de86d014 Return ReachedFixedPoint::No when resolving derive helper 2021-06-04 16:50:35 +02:00
Lukas Wirth
07394316ff Add function references hover action 2021-06-04 15:54:55 +02:00
Lukas Wirth
5f1fac44c5 Cleanup parameter_hint_heuristics inlay hints test 2021-06-04 14:09:20 +02:00
Lukas Wirth
b0f6d8868c Reorganize inlay_hints tests 2021-06-04 13:47:39 +02:00
Jonas Schievink
17565f4dea Set enable_proc_attr_macros in hir_ty TestDB 2021-06-03 18:11:33 +02:00
Jonas Schievink
d1c4d28eed Update list of built-in attributes 2021-06-03 18:09:21 +02:00
Jonas Schievink
9fdb8f9037 Make it opt-in 2021-06-03 18:09:21 +02:00
Jonas Schievink
e5a2c6596d Expand procedural attribute macros 2021-06-03 18:09:21 +02:00
bors[bot]
7f9c4a59d9
Merge #9130
9130: Prefix/suffix parameter inlay hint hiding heuristic is more strict r=Veykril a=Veykril

Instead of just plainly checking prefix/suffix of the argument string to the parameter name we only check for prefixes and suffixes if they are split apart via an underscore meaning, with the argument `foo`, it will be hidden for the parameter name `foo_bar` but not for `foobar`.

bors r+
Closes https://github.com/rust-analyzer/rust-analyzer/issues/8878

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-06-03 14:26:07 +00:00
Lukas Wirth
cc762c30df Prefix/suffix parameter inlay hint hiding heuristic is more strict 2021-06-03 16:22:24 +02:00
Matthias Krüger
9452dfaac7 NFC: remove redundant clones (clippy::perf) 2021-06-03 15:32:46 +02:00
bors[bot]
23b48d377d
Merge #9127
9127: internal: make variant fields inherit the enum's visibility in the ItemTree r=jonas-schievink a=jonas-schievink

No observable changes from what I can tell, but this is "more correct".

bors r+

Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
2021-06-03 12:27:57 +00:00
Jonas Schievink
28e3e683b2 ItemTree: make variant fields inherit the enum's visibility 2021-06-03 14:26:26 +02:00
bors[bot]
48ea50bf04
Merge #9124
9124: Apply a few clippy suggestions r=lnicola a=clemenswasser



Co-authored-by: Clemens Wasser <clemens.wasser@gmail.com>
2021-06-03 12:09:10 +00:00
bors[bot]
c7eb19ebf9
Merge #9104
9104: Implement `#[rustc_skip_array_during_method_dispatch]` r=flodiebold a=jonas-schievink

haxx run the world

Closes https://github.com/rust-analyzer/rust-analyzer/issues/8552
Part of https://github.com/rust-analyzer/rust-analyzer/issues/9056

Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
2021-06-03 11:52:15 +00:00
Jonas Schievink
70e19fd1cb Add comment 2021-06-03 13:51:43 +02:00
Clemens Wasser
629e8d1ed0 Apply more clippy suggestions and update generated 2021-06-03 12:46:56 +02:00
bors[bot]
50936397cc
Merge #9105
9105: internal: calculate pattern adjustments r=flodiebold a=iDawer

This extends `InferenceResult` with `pub pat_adjustments: FxHashMap<PatId, Vec<Ty>>`.

Fixes #9095 


Co-authored-by: Dawer <7803845+iDawer@users.noreply.github.com>
2021-06-03 09:55:37 +00:00
Clemens Wasser
3c6dc0f89d Apply a few clippy suggestions 2021-06-03 11:46:03 +02:00
bors[bot]
092396c65a
Merge #9119
9119: fix: some minor "extract type alias" fixes r=jonas-schievink a=jonas-schievink

It now correctly works inside traits, and no longer messes up the indentation of the original node

bors r+

Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
2021-06-02 20:28:15 +00:00
Jonas Schievink
6c0e58d107 Preserve indentation 2021-06-02 22:27:12 +02:00
Jonas Schievink
e4c019fcaa Account for traits 2021-06-02 22:20:41 +02:00
bors[bot]
c2157f5f96
Merge #9118
9118: Document that `addCallArgumentSnippets` requires `addCallParenthesis r=Veykril a=Veykril

bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-06-02 20:12:10 +00:00
Lukas Wirth
d304352407 Document that addCallArgumentSnippets requires `addCallParenthesis 2021-06-02 22:10:09 +02:00
bors[bot]
e5c86ee3eb
Merge #9117
9117: Allow expand-macro to be invoked anywhere inside a macro call r=Veykril a=Veykril

I don't really see a reason to only limit this to the name-ref of a macro.
bors r+
Closes #4606

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-06-02 19:43:29 +00:00
Lukas Wirth
841feef79e Allow expand-macro to be invoked anywhere inside a macro call 2021-06-02 21:42:49 +02:00
Lukas Wirth
ded4e7cc83 Fix bind patterns always being treated as ref taking patterns 2021-06-02 20:00:39 +02:00
bors[bot]
5be653d426
Merge #9108
9108: Don't show extract into variable assist for unit expressions r=jonas-schievink a=brandondong

**Reproduction:**

```rust
fn main() {
    let mut i = 3;
    $0if i >= 0 {
        i += 1;
    } else {
        i -= 1;
    }$0
}
```

1. Select the snippet of code between the $0's.
2. The extract into variable assist shows up, pushing down the more useful extract into function assist.
3. The resulting output of selecting the extract into variable assist is valid but with the extracted variable having the unit type:
```rust
fn main() {
    let mut i = 3;
    let var_name = if i >= 0 {
        i += 1;
    } else {
        i -= 1;
    };
    var_name
}
```

**Fix:**
- Don't show the extract into variable assist for unit expressions. I could not think of any scenarios where such a variable extraction would be desired.

Co-authored-by: Brandon <brandondong604@hotmail.com>
2021-06-02 17:25:11 +00:00
bors[bot]
a421482e75
Merge #9112
9112: Fix some bugs in `extract_struct_from_enum_variant` assist r=Veykril a=Veykril

bors r+
Fixes #9100
Fixes #9099
Kind of fixes  #9109, it now copies all the generics might be incorrect if the variant doesn't use all of them)

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-06-02 16:18:42 +00:00
Lukas Wirth
6ffe1d99d4 Fix references to patterns in extract_struct_from_enum_variant assist 2021-06-02 18:16:59 +02:00
Lukas Wirth
9ff7ab680c Carry over attributes in extract_struct_from_enum_variant 2021-06-02 17:55:08 +02:00
Lukas Wirth
f3dc4321c8 Account for generics in extract_struct_from_enum_variant 2021-06-02 17:44:00 +02:00
bors[bot]
2022cfce44
Merge #9111
9111: fix: make "extract type alias" place extracted type alias outside of impl r=jonas-schievink a=jonas-schievink

bors r+

Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
2021-06-02 15:21:17 +00:00
Lukas Wirth
76fd1b316f Remove obsolete is_new_item field on CompletionContext 2021-06-02 17:12:36 +02:00
Jonas Schievink
66a5fd375a Place extracted type alias outside of impl 2021-06-02 16:50:44 +02:00
Lukas Wirth
9271941a95 Add MethodCall and FieldAccess variants to ImmediateLocation 2021-06-02 15:21:18 +02:00
Brandon
7d2710218f Don't show extract into variable assist for unit expressions 2021-06-02 00:59:09 -07:00
Dawer
0a8c30a96f internal: implement pattern adjustments. 2021-06-02 01:32:05 +05:00
Dawer
99516bbd67 minor: Avoid eprintln on panic 2021-06-02 01:32:05 +05:00
Jonas Schievink
955064b6aa Implement #[rustc_skip_array_during_method_dispatch] 2021-06-01 21:34:08 +02:00
Jonas Schievink
41321fa71d Fall back to legacy prelude 2021-06-01 19:03:00 +02:00
Jonas Schievink
f96c1a0414 Implement per-edition preludes 2021-06-01 13:39:19 +02:00
bors[bot]
71117e6812
Merge #8717
8717: Update match checking algorithm r=iDawer a=iDawer

I've recently got interest in the match checking to extend the current algo to support reporting witnesses of non-exhaustiveness.
It appears the algo is outdated from rustc's implementation. I decided to rewrite it based on the latest rustc's version. It is a diff-based port to ra codebase. That means you can diff-compare these files to rustc.
I'm striving to keep minimal ra-related changes in the algo to make it easier to backport future changes from the upstream.

Based on upstream algorithm of version rust-lang/rust 1.52.0-nightly (25c15cdbe 2021-04-22)
https://github.com/rust-lang/rust/blob/25c15cdbe/compiler/rustc_mir_build/src/thir/pattern/usefulness.rs

The goal of this PR is to cover the current `missing-match-arm` diagnostic.

What is remaining to do:
- [x] Error handling. The errors that are unrelated to match checking will be handled before the check. Just like how it made in rustc.
  - [x] Lowering `hir_def::expr::Pat` to `hir_ty::diagnostics::match_check::Pat`. rustc's match checking works on top of `rustc_mir_build::thir::Pat`, which is lowered from `hir::Pat` and carries some extra semantics used by the check. All unrelated checks are done there. RA could use this to rule out running the check on unimplemented cases (`Pat::ConstBlock`, etc).
  - [x] ~~Proper~~Loose typecheck of match arm patterns (https://github.com/rust-analyzer/rust-analyzer/pull/8840, https://github.com/rust-analyzer/rust-analyzer/pull/8875).
- [x] Tests from `hir_ty::diagnostics::match_check::tests`.
- [x] Clean up `todo`s
- [x] Test run on real repos https://github.com/rust-analyzer/rust-analyzer/pull/8717#issuecomment-847120265.

Co-authored-by: Dawer <7803845+iDawer@users.noreply.github.com>
2021-05-31 21:01:52 +00:00
Dawer
e7c49666be Expand fixme comments 2021-06-01 01:44:51 +05:00
Dawer
31b6a750f8 fix: panic on extra fields in a pattern 2021-06-01 00:49:44 +05:00
Dawer
4899ac8c05 Correct binding pattern's type; handle invalid records. 2021-06-01 00:49:44 +05:00
Dawer
3088ca0a53 Take substitutions into account. 2021-06-01 00:49:44 +05:00
Dawer
e16f413582 eprint panic context 2021-06-01 00:49:44 +05:00
Dawer
f571b62a13 minor: doc comment pat_util 2021-06-01 00:49:44 +05:00
Dawer
977ba46bb1 Test match guards, reference patterns 2021-06-01 00:49:44 +05:00
Dawer
4cce7a6407 Box field detection; test #[non-exhaustive] attribute 2021-06-01 00:49:44 +05:00
Dawer
f46a42f73a Better tests: check if match checking bails out. 2021-06-01 00:49:27 +05:00
Dawer
e84efc4a46 Replace the old match checking algorithm 2021-06-01 00:23:09 +05:00
Dawer
894b4c64ff Include old tests 2021-06-01 00:08:43 +05:00