Commit graph

9551 commits

Author SHA1 Message Date
Aleksey Kladov
3dfa2768ac Shorten names 2021-01-09 14:48:15 +03:00
Aleksey Kladov
c6150a3706 Reorder modules 2021-01-09 14:45:47 +03:00
Aleksey Kladov
64a6ee4535 Shorten frequent names 2021-01-09 14:44:01 +03:00
Aleksey Kladov
6fb52af521 Rename dummy -> none 2021-01-09 14:41:31 +03:00
Jacob Pratt
38dd9aa284
Hide argument name hint regardless of case 2021-01-09 04:05:59 -05:00
bors[bot]
5fe8cb1fba
Merge #7213
7213: Simplify r=Veykril a=Veykril

bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-01-08 23:20:54 +00:00
Lukas Wirth
5889bb27d6 Simplify 2021-01-09 00:17:34 +01:00
bors[bot]
056cabf25d
Merge #7212
7212: Simplify highlighting r=matklad a=matklad



Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2021-01-08 20:48:30 +00:00
Aleksey Kladov
e30c1c3fbf Simplify highlighting infra
This also fixes the killer whale bug
2021-01-08 23:47:35 +03:00
Daiki Ihara
65c45083cf Support intra_doc links 2021-01-08 22:23:03 +09:00
ShuiRuTian
c08391ce32 support folder rename for initial request. 2021-01-08 17:49:13 +08:00
Edwin Cheng
ee93037ed9 Use another name instead of dbg for test 2021-01-08 17:38:39 +08:00
Edwin Cheng
bced02c5dc Add test 2021-01-08 14:00:23 +08:00
Edwin Cheng
74a24adc8e Fix bug when $crate in LHS in mbe 2021-01-08 14:00:16 +08:00
bors[bot]
1a29934c37
Merge #7145
7145: Proper handling $crate Take 2 [DO NOT MERGE] r=edwin0cheng a=edwin0cheng

Similar to previous PR (#7133) , but improved the following things :

1. Instead of storing the whole `ExpansionInfo`, we store a similar but stripped version `HygieneInfo`.
2. Instread of storing the `SyntaxNode` (because every token we are interested are IDENT), we store the `TextRange` only.
3. Because of 2, we now can put it in Salsa.
4. And most important improvement: Instead of computing the whole frames every single time, we compute it recursively through salsa: (Such that in the best scenario, we only need to compute the first layer of frame)

```rust
        let def_site = db.hygiene_frame(info.def.file_id);
        let call_site = db.hygiene_frame(info.arg.file_id);

        HygieneFrame { expansion: Some(info), local_inner, krate, call_site, def_site }
```

The overall speed compared to previous PR is much faster (65s vs 45s) :
```
[WITH old PR]
Database loaded 644.86ms, 284mi
Crates in this dir: 36
Total modules found: 576
Total declarations: 11153
Total functions: 8715
Item Collection: 15.78s, 91562mi
Total expressions: 240721
Expressions of unknown type: 2635 (1%)
Expressions of partially unknown type: 2064 (0%)
Type mismatches: 865
Inference: 49.84s, 250747mi
Total: 65.62s, 342310mi
rust-analyzer -q analysis-stats .  66.72s user 0.57s system 99% cpu 1:07.40 total

[WITH this PR]
Database loaded 665.83ms, 284mi
Crates in this dir: 36
Total modules found: 577
Total declarations: 11188
Total functions: 8743
Item Collection: 15.28s, 84919mi
Total expressions: 241229
Expressions of unknown type: 2637 (1%)
Expressions of partially unknown type: 2064 (0%)
Type mismatches: 868
Inference: 30.15s, 135293mi
Total: 45.43s, 220213mi   
rust-analyzer -q analysis-stats .  46.26s user 0.74s system 99% cpu 47.294 total
```

*HOWEVER*,  it is still a perf regression (35s vs 45s):
```
[WITHOUT this PR]
Database loaded 657.42ms, 284mi
Crates in this dir: 36
Total modules found: 577
Total declarations: 11177
Total functions: 8735
Item Collection: 12.87s, 72407mi
Total expressions: 239380
Expressions of unknown type: 2643 (1%)
Expressions of partially unknown type: 2064 (0%)
Type mismatches: 868
Inference: 22.88s, 97889mi
Total: 35.74s, 170297mi
rust-analyzer -q analysis-stats .  36.71s user 0.63s system 99% cpu 37.498 total
```



Co-authored-by: Edwin Cheng <edwin0cheng@gmail.com>
2021-01-08 03:57:11 +00:00
Lukas Wirth
6dca2cbba5 Simplify mod completion 2021-01-07 23:33:52 +01:00
Lukas Wirth
ca6db58762 Tidy up attribute completion match 2021-01-07 22:48:54 +01:00
Phil Ellison
7066bff9c3 Switch test marker 2021-01-07 19:01:33 +00:00
Phil Ellison
554ee6ea02 cargo fmt 2021-01-07 19:01:33 +00:00
Phil Ellison
b2dbe6e43a Add fix to wrap return expression in Some 2021-01-07 19:01:33 +00:00
bors[bot]
4ddf075673
Merge #7193
7193: Show progress for fetching workspace (cargo-metadata and loadOutDirsFromCheck) r=matklad a=edwin0cheng


![Peek 2021-01-07 21-57](https://user-images.githubusercontent.com/11014119/103902132-0db4c780-5135-11eb-94d3-32429445be87.gif)


Fixes #7188 
Fixes #3300

Co-authored-by: Edwin Cheng <edwin0cheng@gmail.com>
2021-01-07 18:07:01 +00:00
bors[bot]
c29d353623
Merge #7191
7191: Adjust vfs crate documentation r=matklad a=arnaudgolfouse

This removes an outdated comment, and uses intra-doc links

Co-authored-by: Arnaud <arnaud.golfouse@free.fr>
2021-01-07 17:57:48 +00:00
Edwin Cheng
2b2d699b35 Report progress for cargo metadata and output-dir 2021-01-08 01:18:58 +08:00
Edwin Cheng
54eb87de03 Refactor out JodChild 2021-01-08 01:08:34 +08:00
Aleksey Kladov
f459375f48 Better fixture highlight 2021-01-07 19:11:27 +03:00
bors[bot]
7967ce85cf
Merge #7184
7184: Changes Cursor Marker To $0 r=matklad a=kevaundray



Co-authored-by: Kevaundray Wedderburn <kevtheappdev@gmail.com>
2021-01-07 12:27:17 +00:00
Kevaundray Wedderburn
72b9a4fbd3 Change <|> to $0 - Rebase 2021-01-07 12:09:23 +00:00
Aleksey Kladov
037caec62c Use american spelling for config
As per

171c3c08fe/docs/dev/style.md (variable-naming)

Also implement config aliasing, for pain-free settings migrations in the future
2021-01-07 15:07:19 +03:00
Arnaud
d216d718bf Use file_set::FileSet and FileSet consistently in doc
The first occurrence of `FileSet` has the full path (`file_set::FileSet`),
while every other is simply `FileSet`.
2021-01-07 12:18:25 +01:00
Arnaud
f80f4ff223 Use intra-doc links in vfs crate documentation 2021-01-07 12:17:38 +01:00
Arnaud
b6669b1c9b Remove the reference to WalkdirLoaderHandle in vfs documentation
This structure was deleted in commit #dad1333
2021-01-07 12:10:02 +01:00
Aleksey Kladov
c8ace3a295 Remove some stale deprecations 2021-01-07 13:54:18 +03:00
Edwin Cheng
76f2b9d2ef Proper handling $crate Take 2 2021-01-07 13:08:32 +08:00
Aleksey Kladov
f8a0561178 Align config's API with usage
The config now is mostly immutable, optimize for that.
2021-01-06 21:22:24 +03:00
bors[bot]
7ae4b8bdb6
Merge #7183
7183: YAGNI active_resolve_capabilities r=matklad a=matklad

bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2021-01-06 17:29:18 +00:00
Aleksey Kladov
6e87828756 YAGNI active_resolve_capabilities
This leaks a lot of LSP details into ide layer, which we want to avoid:

c9cec381bc/docs/dev (lsp-independence)

Additionally, all what this infra does is providing a toggle for
auto-import completion, but we already have one!
2021-01-06 20:23:53 +03:00
Jesse Bakker
974313eb87 Replace last usages of difference with dissimilar 2021-01-06 18:13:29 +01:00
bors[bot]
c9cec381bc
Merge #7181
7181: Document project_model::PackageData and project_model::TargetData r=arnaudgolfouse a=arnaudgolfouse

This PR adds some documentation for the `project_model` crate.

Some of the field descriptions were taken directly from their `cargo_metadata` counterpart :
- `PackageData` -> `cargo_metadata::Package`
- `TargetData` -> `cargo_metadata::Target`

Co-authored-by: Arnaud <arnaud.golfouse@free.fr>
2021-01-06 16:41:22 +00:00
Arnaud
ef636ba346 Document project_model::TargetData
This adds a description for `TargetData` and all its fields.
2021-01-06 17:26:21 +01:00
Arnaud
0abe487f1c Document project_model::PackageData
This adds a description for `PackageData` and all its fields.
2021-01-06 17:26:15 +01:00
Aleksey Kladov
edf03548e3 More readable test 2021-01-06 18:36:13 +03:00
Arnaud
7c3e163e90 Make PackageData, TargetData and PackageDependency public
This makes them discoverable through documentation.
They were already publicly accessible through `Package` and `Target`.
2021-01-06 16:33:29 +01:00
Aleksey Kladov
ec9e2f50f4 Less confusing instr stat 2021-01-06 18:16:04 +03:00
Aleksey Kladov
25edc3c60a Better target for move module 2021-01-06 16:32:45 +03:00
bors[bot]
ed732e86eb
Merge #7177
7177: Speed up snapshoting r=matklad a=matklad

bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2021-01-06 12:49:50 +00:00
Aleksey Kladov
66ed821e18 Speed up snapshoting
Config can be fairly big, no need to deep clone it frequently
2021-01-06 15:46:31 +03:00
bors[bot]
66c575659e
Merge #7172
7172: refactor config to be lossless & precise r=matklad a=matklad



Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2021-01-06 12:40:34 +00:00
Aleksey Kladov
f7a15b5cd1 More maintainable config
Rather than eagerly converting JSON, we losslessly keep it as is, and
change the shape of user-submitted data at the last moment.

This also allows us to remove a bunch of wrong Defaults
2021-01-06 15:39:28 +03:00
bors[bot]
bb56c55c4e
Merge #7176
7176: Attribute completion r=matklad a=FlowerBOII

Solve #7167.

I removed the optional args for the attributes ```deprecated```, ```must_use``` and ```should_panic```.
I also updated their respective tests.

Please let me know if I missed something.

Co-authored-by: FlowerBOII <42295129+FlowerBOII@users.noreply.github.com>
2021-01-06 11:32:53 +00:00
FlowerBOII
e3d39cf2b1 Change the should_panic completion and his related attribute test 2021-01-06 12:23:19 +01:00
FlowerBOII
220c838bc6 Remove the args for the must_use attibute and change the related tests 2021-01-06 12:04:23 +01:00
FlowerBOII
db0a844ad8 Update deprecated test 2021-01-06 11:07:57 +01:00
FlowerBOII
64f8ec4632 Remove a part of the deprecated autocompletion 2021-01-06 11:06:02 +01:00
bors[bot]
c310446659
Merge #7174
7174: Normalize line endings when formatting r=matklad a=Jesse-Bakker

Fixes #7166


Co-authored-by: Jesse Bakker <github@jessebakker.com>
2021-01-06 09:03:38 +00:00
Jesse Bakker
c49d5f757c Normalize line endings when formatting 2021-01-05 23:58:51 +01:00
bors[bot]
861a547270
Merge #7170
7170: More maintainable caps config r=matklad a=matklad

bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2021-01-05 14:52:21 +00:00
Aleksey Kladov
624eb1ee54 More maintainable caps config
The idea here is that we preserve client's config as is, without
changes. This gets rid of state!
2021-01-05 17:46:57 +03:00
Jonas Schievink
3cb7c8b548 Emit diagnostics for unresolved item-level macros 2021-01-05 15:42:43 +01:00
bors[bot]
c8d3d5694b
Merge #7168
7168: Rename expr -> tail_expr r=matklad a=matklad

bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2021-01-05 12:51:38 +00:00
Aleksey Kladov
f9707cde68 Rename expr -> tail_expr 2021-01-05 15:51:13 +03:00
bors[bot]
d7013a5934
Merge #7140
7140: Store trait associated items in fst r=matklad a=SomeoneToIgnore

Store imported traits' associated function/methods and constants into `ImportMap.fst` and pefrorm the imports search on them.

This is a first step towards trait autoimport during completion functionality, the way I see it, after this PR, only a few major things are left to be done:

* store all traits' assoc items into fst, not only the ones in scope, as we do now. Any code pointers on how to do this are welcome 😄 
* adjust a few modules in completions crate (`dot.rs`, `qualified_path.rs` at least) to query the import map, reusing the `import_assets` logic heavily

==
With the current import and autoimport implementations, it looks like for a single query, we're either interested in either associated items lookup or in all other `fst` contents lookup, but never both simultaneously.
I would rather not split `fst` in two but add another `Query` parameter to separate those, but let me know if you have any ideas.

Co-authored-by: Kirill Bulatov <mail4score@gmail.com>
2021-01-05 12:04:35 +00:00
Kirill Bulatov
543e950e30 Move the test mark 2021-01-05 14:03:58 +02:00
bors[bot]
5c10f2f705
Merge #7131
7131: Created an assist for inlining a function's body into its caller r=matklad a=Michael-F-Bryan

This introduces an `inline_function` assist which will convert code like this:

```rust
fn add(a: u32, b: u32) -> u32 { a + b }
fn main() {
    let x = add<|>(1, 2);
}
```

Into something like this:

```rust
fn add(a: u32, b: u32) -> u32 { a + b }
fn main() {
    let x = { 
        let a = 1; 
        let b = 2; 
        a + b 
    };
}
```

Fixes #6863.

Co-authored-by: Michael-F-Bryan <michaelfbryan@gmail.com>
2021-01-05 11:04:58 +00:00
bors[bot]
4bc1ed7d59
Merge #7162
7162: Introduce queries to avoid problems when performing completion for enums with many variants r=matklad a=danielframpton

This change introduces two new queries to compute:
  1) attributes for all variants of an enum, and
  2) attributes for all fields of a variant.

The purpose of this change is to avoid the current n^2 behavior when rendering completion for variants (which prevents completion for enums with large numbers of variants).

Co-authored-by: Daniel Frampton <Daniel.Frampton@microsoft.com>
2021-01-05 10:53:24 +00:00
bors[bot]
18dbb8f5c7
Merge #7164
7164: Allow `#anchor` linking of config options r=matklad a=matklad

bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2021-01-05 10:10:45 +00:00
Aleksey Kladov
d7741d1610 Allow #anchor linking of config options 2021-01-05 13:09:06 +03:00
Daniel Frampton
f08109bd2d Introduce new queries to compute
1) the set of attributes for all variants of an enum, and
  2) the set of attributes for all fields of a variant.

This avoids the current n^2 behavior when rendering completion for variants, which
prevents completion for enums with large numbers of variants.
2021-01-04 20:37:50 -08:00
bors[bot]
b99b14311c
Merge #7160
7160: Get `hir::Function` return type r=flodiebold a=arnaudgolfouse

Hello !

As said in #7158, I noticed that `hir::Function` has no direct way of getting the return type, so this PR adds this functionality.

Co-authored-by: Arnaud <arnaud.golfouse@free.fr>
2021-01-04 21:07:50 +00:00
bors[bot]
550c49657e
Merge #7147
7147: ssr: Allow replacing expressions with statements r=davidlattimore a=MarijnS95

Depends on #6587

Until that is merged, the diff is https://github.com/MarijnS95/rust-analyzer/compare/stmt..replace-expr-with-stmt

---

Now that statements can be matched and replaced (#6587) some usecases require expressions to be replaced with statements as well. This happens when something that can ambiguously be an expression or statement like `if` and loop blocks appear in the last position of a block, as trailing expression. In this case a replacement pattern of the form `if foo(){$a();}==>>$a();` will only substitute `if` blocks in the list of statements but not if they (implicitly) end up in the trailing expression, where they are not wrapped by an EXPR_STMT (but the pattern and template are, as parsing only succeeds for the `stmt ==>> stmt` case).

Instead of adding two rules that match an expression - and emit duplicate matching errors - allow the template for expressions to be a statement if it fails to parse as an expression.

---

Another gross change that does not seem to break any tests currently, but perhaps a safeguard should be added to only allow this kind of replacement in blocks by "pushing" the replacement template to the statement list and clearing the trailing expression?

CC @davidlattimore 

Co-authored-by: Marijn Suijten <marijn@traverseresearch.nl>
2021-01-04 20:36:13 +00:00
Michael-F-Bryan
7b4b4ef026
Created an inline-function assist (fixes #6863) 2021-01-05 04:18:57 +08:00
Kirill Bulatov
27b3b13824 Small helpers 2021-01-04 22:01:35 +02:00
Arnaud
052404565e Remove RetType 2021-01-04 20:34:23 +01:00
Arnaud
2f0969b873 Document hir::Function::ret_type
This adds documentation for the newly added function. It might be a bit too
detailed, but I like it that way :)
2021-01-04 19:14:44 +01:00
Arnaud
a6dc7cf36d Make it possible to retrieve hir::Function's return type
This is done by adding a `ret_type` method to `hir::Function`.
I followed `assoc_fn_params` convention by creating a new `RetType` type,
that contains the actual return type accessible via a `ty` method.
2021-01-04 19:14:44 +01:00
bors[bot]
0708bfeb72
Merge #7159
7159: Refactor mbe to reduce clone and copying r=edwin0cheng a=edwin0cheng

bors r+

Co-authored-by: Edwin Cheng <edwin0cheng@gmail.com>
2021-01-04 18:02:54 +00:00
Edwin Cheng
d387bfdc4a Simplify SubtreeTokenSource 2021-01-05 02:00:51 +08:00
Edwin Cheng
af3d75ad2e Refactor TokenBuffer for reduc cloning 2021-01-05 02:00:46 +08:00
Kirill Bulatov
ca42a52051 Code review fixes 2021-01-04 18:33:05 +02:00
kjeremy
f2d1144b4a Update crates 2021-01-04 11:12:42 -05:00
Edwin Cheng
f1ffd14922 Reduce string copying 2021-01-05 00:11:56 +08:00
Kirill Bulatov
ed1ef3ae13 Do not collect trait type aliases 2021-01-04 17:44:27 +02:00
Kirill Bulatov
ec316cb211 Ignore associated items during unqialified path fuzzy completions 2021-01-04 17:44:27 +02:00
Kirill Bulatov
8721574a85 Simplify 2021-01-04 17:44:27 +02:00
Kirill Bulatov
d27dea86b7 Properly check assoc items lookup 2021-01-04 17:44:27 +02:00
Kirill Bulatov
63d83fa385 Add associated data into fst 2021-01-04 17:44:27 +02:00
Kirill Bulatov
1bfc3a50c0 Add a basic test for the trait fuzzy import 2021-01-04 17:44:27 +02:00
bors[bot]
6f8af890ed
Merge #7154
7154: Show goto type actions for Const and TypeParams r=matklad a=Veykril

Shows goto type actions for type parameters:
![Code_6hn3rowu9M](https://user-images.githubusercontent.com/3757771/103547890-42aaeb00-4ea5-11eb-8ac7-f166869af5f8.png)

Shows goto type actions for const parameters:
![Code_8UFCcbZL3z](https://user-images.githubusercontent.com/3757771/103547891-43438180-4ea5-11eb-91e8-50681e4d831e.png)

Also shows implementations for `Self`:
![Code_eQj1pWfser](https://user-images.githubusercontent.com/3757771/103547892-43438180-4ea5-11eb-9122-461f2e0fdd01.png)


Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-01-04 15:23:53 +00:00
Lukas Wirth
54b9b03ca2 Show GotoTypeAction for TypeParam 2021-01-04 15:54:45 +01:00
bors[bot]
484df745cc
Merge #7153
7153: rename exrtract_assignment -> pull r=matklad a=matklad

bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2021-01-04 14:47:16 +00:00
Lukas Wirth
bd47e140b6 Show GotoTypeAction for ConstParam 2021-01-04 15:19:09 +01:00
Lukas Wirth
cd6426afe5 Show implementations when hovering over SelfType 2021-01-04 14:57:59 +01:00
Aleksey Kladov
46afdb6e9b rename exrtract_assignment -> pull
Vertical code motions are conventionally called "pull up" / "push
down".

"extract" is used for introducing new names.
2021-01-04 16:41:57 +03:00
Lukas Wirth
5804b3fae8 Fix HoverAction::Implementation typo 2021-01-04 14:38:08 +01:00
Lukas Wirth
0ae0909a16 Implement hover for ConstParam 2021-01-04 14:18:31 +01:00
bors[bot]
5771cad451
Merge #7149
7149: Implement hovering for TypeParams r=matklad a=Veykril



Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-01-04 12:57:28 +00:00
Lukas Wirth
47900dd3bc Impl hovering for TypeParams 2021-01-04 12:24:47 +01:00
bors[bot]
ac123ac9e4
Merge #6587
6587: SSR: Support statement matching and replacing r=davidlattimore a=MarijnS95


For #3186

Hi!

This is a smaller initial patchset that came up while working on support for statement lists (and my first time working on RA 😁). It has me stuck on trailing semicolons for which I hope to receive some feedback. Matching (and replacing) `let` bindings with a trailing semicolon works fine, but trying to omit these (to make patterns more ergonomic) turns out more complex than expected.

The "optional trailing semicolon solution" implemented in this PR is ugly because `Matcher::attempt_match_token` should only consume a trailing `;` when parsing `let` bindings to prevent other code from breaking. That at the same time has a nasty side-effect of `;` ending up in the matched code: any replacements on that should include the trailing semicolon as well even if it was not in the pattern. A better example is in the tests:

3ae1649c24/crates/ssr/src/tests.rs (L178-L184)

The end result to achieve is (I guess) allowing replacement of let bindings without trailing semicolon like `let x = $a ==>> let x = 1` (but including them on both sides is still fine), and should make replacement in a macro call (where `foo!(let a = 2;)` for a `$x:stmt` is invalid syntax) possible as well. That should allow to enable/fix these tests:

3ae1649c24/crates/ssr/src/tests.rs (L201-L214)

A possible MVP of this PR might be to drop this optional `;' handling entirely and only allow an SSR pattern/template with semicolons on either side.

Co-authored-by: Marijn Suijten <marijn@traverseresearch.nl>
2021-01-04 11:14:40 +00:00
Marijn Suijten
d33edb4e9c ssr: Allow replacing expressions with statements
Now that statements can be matched and replaced (#6587) some usecases
require expressions to be replaced with statements as well. This happens
when something that can ambiguously be an expression or statement like
`if` and loop blocks appear in the last position of a block, as trailing
expression. In this case a replacement pattern of the form `if
foo(){$a();}==>>$a();` will only substitute `if` blocks in the list of
statements but not if they (implicitly) end up in the trailing
expression, where they are not wrapped by an EXPR_STMT (but the pattern
and template are, as parsing only succeeds for the `stmt ==>> stmt`
case).

Instead of adding two rules that match an expression - and emit
duplicate matching errors - allow the template for expressions to be a
statement if it fails to parse as an expression.
2021-01-04 10:55:09 +01:00
bors[bot]
5b86ff3e91
Merge #7113
7113: Manual updates r=matklad a=tekul

Add some details on how to build the manual and some clarification on how to deal with "proc macro2 warnings.

For context, this arose from [this question](https://users.rust-lang.org/t/how-to-disable-rust-analyzer-proc-macro-warnings-in-neovim/53150) on users.rust-lang.org.

Co-authored-by: Luke Taylor <tekul.hs@gmail.com>
2021-01-03 18:22:07 +00:00
bors[bot]
96ab76ca04
Merge #7138
7138: Support assignment to FieldExpr for extract_assignment assist r=matklad a=Jesse-Bakker



Co-authored-by: Jesse Bakker <github@jessebakker.com>
2021-01-03 18:14:12 +00:00
Jesse Bakker
ba4c42af02 Support assignment to FieldExpr for extract_assignment assist 2021-01-03 15:46:57 +01:00
Jesse Bakker
c7e0c7f43a Upgrade expect-test to 1.1 2021-01-03 14:43:29 +01:00
Marijn Suijten
b87699d97a ssr: Add tests for raw LetStmt matching 2021-01-03 12:05:53 +01:00
Marijn Suijten
42da26e959 parser,syntax: Add separate parser for stmt with optional semicolon
Adjusting `grammar::fragments::stmt` to Optional or Yes will break
original functionality and tests.
2021-01-03 12:05:52 +01:00
Jonas Schievink
85cc3cfec9
Revert "Proper handling $crate and local_inner_macros" 2021-01-03 11:47:57 +01:00
Marijn Suijten
cc081b7e1c syntax,ssr: Implement statement parsing 2021-01-03 11:29:33 +01:00
bors[bot]
354c1daedc
Merge #7136
7136: Fixed nested eager macro bug r=edwin0cheng a=edwin0cheng

fixes #7126 

bors r+

Co-authored-by: Edwin Cheng <edwin0cheng@gmail.com>
2021-01-03 09:58:32 +00:00
Edwin Cheng
26b9c793f1 Fixed nested eager macro bug 2021-01-03 17:56:59 +08:00
bors[bot]
1cc73d60bb
Merge #7068
7068: Add VSCode command to view the hir of a function body r=theotherphil a=theotherphil

Will fix https://github.com/rust-analyzer/rust-analyzer/issues/7061. Very rough initial version just to work out where I needed to wire everything up.

@matklad would you be happy merging a hir visualiser of some kind? If so, do you have any thoughts on what you'd like it show, and how?

I've spent very little time on this thus far, so I'm fine with throwing away the contents of this PR, but I want to avoid taking the time to make this more polished/interactive/useful only to discover that no-one else has any interest in this functionality.

![image](https://user-images.githubusercontent.com/1974256/103236081-bb58f700-493b-11eb-9d12-55ae1b870f8f.png)


Co-authored-by: Phil Ellison <phil.j.ellison@gmail.com>
2021-01-03 09:03:15 +00:00
bors[bot]
520b8a5a4d
Merge #7115
7115: Migrate HasSource::source to return Option r=matklad a=nick96

I've made a start on fixing #6913 based on the provided work plan, migrating `HasSource::source` to return an `Option`. The simple cases are migrated but there are a few that I'm unsure exactly how they should be handled:

- Logging the processing of functions in `AnalysisStatsCmd::run`: In verbose mode it includes the path to the module containing the function and the syntax range. I've handled this with an if-let but would it be better to blow up here with `expect`? I'm not 100% on the code paths but if we're processing a function definition then the source should exist.

I've handled `source()` in all code paths as `None` being a valid return value but are there some cases where we should just blow up? Also, all I've done is bubble up the returned `None`s, there may be some places where we can recover and still provide something.

Co-authored-by: Nick Spain <nicholas.spain@stileeducation.com>
Co-authored-by: Nick Spain <nicholas.spain96@gmail.com>
2021-01-03 08:56:17 +00:00
Phil Ellison
ee7c3f79e2 Use stdx::format_to instead of writeln 2021-01-03 08:54:33 +00:00
bors[bot]
3bf4cec799
Merge #7128
7128: Implement HasAttrs for GenericParam r=matklad a=Veykril



Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-01-03 08:49:59 +00:00
cynecx
3e9847f747 Use fully qualified Itertools::intersperse call to silence nightly warnings about a potential name collision due to recent libstd api additions 2021-01-02 20:58:53 +01:00
cynecx
59fe884ef5 Fix warnings on rust-nightly 2021-01-02 20:48:39 +01:00
bors[bot]
a88d4f8c72
Merge #7133
7133: Proper handling $crate and local_inner_macros r=jonas-schievink a=edwin0cheng

This PR introduces `HygineFrames` to store the macro definition/call site hierarchy in hyginee and when resolving `local_inner_macros` and `$crate`, we use the token to look up the corresponding frame and return the correct value.

See also: https://rustc-dev-guide.rust-lang.org/macro-expansion.html#hygiene-and-hierarchies

fixe #6890 and  #6788

r? @jonas-schievink 

Co-authored-by: Edwin Cheng <edwin0cheng@gmail.com>
2021-01-02 17:42:45 +00:00
bors[bot]
510abef5da
Merge #7130
7130: Add extract_assignment assist r=Jesse-Bakker a=Jesse-Bakker

Add extract-assignment assist (#7006).

Assist is for now only implemented on if/match-statements where the assigment is the last statement in every block,
as for other cases, one would have to check whether the assignment has effects on the rest of the block and
extract a temporary variable for it in the block.



Co-authored-by: Jesse Bakker <github@jessebakker.com>
2021-01-02 16:23:06 +00:00
Jesse Bakker
bfe6a8e71a Add support for MatchExpr to extract_assigment assist 2021-01-02 17:10:46 +01:00
Jesse Bakker
31204e3590 Add extract-assignment assist 2021-01-02 16:59:01 +01:00
Edwin Cheng
3545289603 Use arena instead of vec 2021-01-02 22:48:22 +08:00
bors[bot]
3b347eaa4e
Merge #7134
7134: Fix infer error of macro invocation in array expr r=edwin0cheng a=edwin0cheng

Fixed following infer error:

```rust
macro_rules! bar { () => {0u32} }
fn test() {
    let a = [bar!()];   // a : [unknown]
}
```

bors r+

Co-authored-by: Edwin Cheng <edwin0cheng@gmail.com>
2021-01-02 14:16:26 +00:00
Edwin Cheng
63e330f402 Fix infer error of macro invocation in array expr 2021-01-02 22:06:59 +08:00
Edwin Cheng
fe5340d970 Introduce HygieneFrames for proper token hyginee 2021-01-02 20:39:57 +08:00
Lukas Wirth
68336fdb61 Implement HasAttrs for Type-, Const- and LifetimeParam 2021-01-02 12:11:46 +01:00
Nick Spain
40cd6cdf67 Fix ConstParam HasSource impl and implement TryToNav not Nav 2021-01-02 22:11:25 +11:00
Nick Spain
887028fcf5 Remove old_source now we've fully migrated
Fixes #6913
2021-01-02 21:53:52 +11:00
Nick Spain
5c659c21dd Handle case where detail doesn't exist without giving up on completion
Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2021-01-02 21:53:52 +11:00
Nick Spain
3a1f8e897b Remove source_old from adding const and function impls 2021-01-02 21:53:52 +11:00
Nick Spain
7bfec89cf9 Make the result of Const, FunctionRender and TypeAliasRender constructors optional
They use source() which now returns an Option so they need to too.
2021-01-02 21:53:52 +11:00
Nick Spain
3f1b3df65b Move impls of ToNav that use source() to TryToNav 2021-01-02 21:53:52 +11:00
Nick Spain
6800c606ec Handle missing source in target_data_for_def 2021-01-02 21:53:52 +11:00
Nick Spain
0a9b735240 Handle missing source in filter_assoc_items 2021-01-02 21:53:52 +11:00
Nick Spain
1c009c9f12 Go back to use of source_old() in offset_target_and_file_id as it's not as simple as I thought 2021-01-02 21:53:52 +11:00
Nick Spain
71c9a884d1 Fix type error with .and_then 2021-01-02 21:53:52 +11:00
Nick Spain
68b4efd536 Handle not finding range in Definition::search_scope
The `LifetimeParam` and `Local` variants use `source()` to find their
range. Now that `source()` returns an `Option` we need to handle the
`None` case.
2021-01-02 21:53:52 +11:00
Nick Spain
c936e4b86f source_old -> source for cases that can be handled by simple bubbling 2021-01-02 21:53:52 +11:00
Nick Spain
562e2ee28a Only log path and syntax range when processing function if source exists 2021-01-02 21:53:52 +11:00
Nick Spain
14d0db0759 HasSource::source_old -> HasSource::source for places where proc-macros were special cased
In #6901 some special case handling for proc-macros was introduced to
prevent panicing as they have no AST. Now the new HasSource::source
method is used that returns an option.

Generally this was a pretty trivial change, the only thing of much
interest is that `hir::MacroDef` now implements `TryToNav` not `ToNav`
as this allows us to handle `HasSource::source` now returning an option.
2021-01-02 21:53:52 +11:00
Nick Spain
ea4708c444 Mark HasSource::source_old as deprecated but allow at all call sites 2021-01-02 21:53:51 +11:00
Nick Spain
2de2b1eca3 Implement new HasSource::source for all implementors of HasSource 2021-01-02 21:53:51 +11:00
Nick Spain
27cadcd531 HasSource::source -> HasSource::source_old
To start migrating HasSource::source to return an Option.
2021-01-02 21:53:51 +11:00
Lukas Wirth
ec448ca4b3 Impl HasAttrs for GenericParam 2021-01-02 00:44:59 +01:00
Florian Diebold
29acd39800 Don't emit arg count diagnostics for method calls with unknown receiver
Fixes #7098.
2021-01-01 20:49:18 +01:00
Phil Ellison
db53db8046 Address review suggestion, fix tidy tests 2021-01-01 19:25:18 +00:00
Luke Taylor
10c9efc24b Expand doc on dealing with "proc macro not expanded"
Added the error message to the doc for the UnresolvedProcMacro
diagnostic, explaining that either enabling the procMacro setting
or disabling this diagnostic should make the warnings go away.
2021-01-01 18:47:54 +00:00
Mara Bos
273d2f9123 Formatting. 2021-01-01 17:31:32 +01:00
Mara Bos
4833972067 Add support for Rust 2021. 2021-01-01 17:22:23 +01:00
Lukas Wirth
bbc0b41c37 Show lifetimes and labels on hover 2021-01-01 15:19:47 +01:00
bors[bot]
0e5fe47153
Merge #7080
7080: Implement ConstParams for HIR r=Veykril a=Veykril

r? @flodiebold 

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-01-01 13:45:10 +00:00
Lukas Wirth
18bf2e5af5 Add ConstParams to the ide layer 2021-01-01 14:43:16 +01:00
bors[bot]
51d29fe554
Merge #7116
7116: Fix deep syntax tree bug generated by proc-macro r=jonas-schievink a=edwin0cheng

This PR fixed a bug from `semver-parser` and `pest_derive` crates which generate a very deep syntax tree such that serde reject to de-serialize. To fix this bug, we disabled recursion limit in `serde` (by calling [`Deserializer::disable_recursion_limit`](https://docs.rs/serde_json/1.0.61/serde_json/struct.Deserializer.html#method.disable_recursion_limit))

I have a feeling that we still need some way to protect against bad proc-macro generating huge syntax node, but I have no  idea right now.

r? @jonas-schievink 

Fixes #7103 

Co-authored-by: Edwin Cheng <edwin0cheng@gmail.com>
2021-01-01 11:06:27 +00:00