Commit Graph

13721 Commits

Author SHA1 Message Date
zhoufan
f00cd911bf lookup impls in local del maps 2021-11-09 18:14:02 +08:00
bors[bot]
3c786bd7fd
Merge #10726
10726: minor: Add some completion profile spans r=Veykril a=Veykril

bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-11-08 18:42:10 +00:00
Lukas Wirth
ab657af5b7 Add some completion profile spans 2021-11-08 19:41:16 +01:00
Lukas Wirth
26419c0379 Fix proc-macro attributes being shadowed by their functions in IDE layer 2021-11-08 14:49:50 +01:00
bors[bot]
c5c11b87cc
Merge #10720
10720: fix: Don't ascribe types in pattern completion for param patterns twice r=Veykril a=Veykril

Fixes #10323
bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-11-08 13:12:03 +00:00
Lukas Wirth
f7e8136923 Add test for current incorrect behaviour 2021-11-08 14:10:26 +01:00
bors[bot]
2c0f433fd2
Merge #10699
10699: internal: Make CompletionItem `label` and `lookup` fields `SmolStr`s r=Veykril a=Veykril

This replaces a bunch of String clones with SmolStr clones, though also makes a few parts a bit more expensive(mainly things involving `format!`ted strings as labels).


Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-11-07 11:13:15 +00:00
bors[bot]
e4ce6c7468
Merge #10698
10698: implement multi-token mapping for ssr r=Veykril a=spookyvision



Co-authored-by: Anatol Ulrich <anatol.ulrich@ferrous-systems.com>
2021-11-07 11:02:39 +00:00
Laurențiu Nicola
d18a379c7b Bump deps 2021-11-06 17:40:38 +02:00
Lukas Wirth
7369360c15 Don't ascribe types in pattern completion for patterns twice 2021-11-05 18:39:36 +01:00
bors[bot]
726b4dd8bd
Merge #10704
10704: internal: Short-circuit `descend_into_macros_single` r=Veykril a=Veykril

There is no need to descend everything if all we are interested in is the first mapping.
This bring `descend_into_macros` timing in highlighting in `rust-analyzer/src/config.rs` from `154ms - descend_into_macros (2190 calls)` to `24ms - descend_into_macros (2190 calls)` since we use the single variant there(will regress once we want to highlight multiple namespaces again though).
bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-11-05 15:06:37 +00:00
Lukas Wirth
4d768bede0 Short-circuit descend_into_macros_single 2021-11-05 16:03:45 +01:00
Lukas Wirth
addd93ed9a Don't search for root nodes unnecessarily 2021-11-05 15:52:10 +01:00
bors[bot]
274d9f90ae
Merge #10703
10703: internal: Don't check items for macro calls if they have no attributes r=Veykril a=Veykril

Turns out when highlighting we currently populate the Dynmaps of pretty much every item in a file, who would've known that would be so costly...
Shaves off 250 ms for the integrated benchmark on `rust-analyzer/src/config.rs`.

We are still looking at a heft `154ms - descend_into_macros (2190 calls)` but I feel like this is slowly nearing towards just call overhead.
bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-11-05 13:53:59 +00:00
Lukas Wirth
8dad1b9228 Don't check items for macro calls if they have no attributes 2021-11-05 14:50:10 +01:00
bors[bot]
d1e449e313
Merge #10701
10701: internal: Cache ast::MacroCalls to their expansions in Semantics::descend_into_macros_impl r=Veykril a=Veykril

Saves ~45ms when highlighting `rust-analyzer/src/config.rs` for me
bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-11-05 13:26:56 +00:00
Lukas Wirth
af4d244462 Cache ast::MacroCalls to their expansions in Semantics::descend_into_macros_impl 2021-11-05 14:25:47 +01:00
Lukas Wirth
2f5afba9f8 Replace some String usages with SmolStr in completions 2021-11-05 12:30:39 +01:00
bors[bot]
10782bbb39
Merge #10685
10685: fix: Enable markdown tables r=Veykril a=Veykril

Should fix https://github.com/rust-analyzer/rust-analyzer/issues/10655
bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-11-05 11:25:17 +00:00
Anatol Ulrich
69e666fdba maybe? 2021-11-04 22:01:59 +01:00
Lukas Wirth
439a8194b0 Replace more Name::to_string usages with Name::to_smol_str 2021-11-04 18:12:05 +01:00
Lukas Wirth
4d4574f5b6 Enable markdown tables 2021-11-04 17:36:58 +01:00
bors[bot]
962be38004
Merge #10645
10645: fix: make `rename` multi-token mapping aware r=Veykril a=spookyvision



Co-authored-by: Anatol Ulrich <anatol.ulrich@ferrous-systems.com>
Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
Co-authored-by: Anatol Ulrich <45840+spookyvision@users.noreply.github.com>
2021-11-04 16:31:16 +00:00
bors[bot]
c96481e25f
Merge #10691
10691: minor: Use array `into_iter` in more places r=lnicola a=lnicola

bors r+

Co-authored-by: Laurențiu Nicola <lnicola@dend.ro>
2021-11-04 05:52:05 +00:00
Laurențiu Nicola
139bf9b4e1 Use array into_iter in more places 2021-11-04 07:51:20 +02:00
bors[bot]
a8247685cf
Merge #10686
10686: internal: Add `Semantics::original_ast_node` for upmapping nodes out of macro files r=Veykril a=Veykril

Fixes trying to insert imports into macro expanded files which then do text edits on very wrong text ranges.

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-11-03 20:23:14 +00:00
Lukas Wirth
96db0d8bdd Add Semantics::original_ast_node for upmapping nodes out of macro files 2021-11-03 21:12:36 +01:00
bors[bot]
9ee855bcc5
Merge #10680
10680: implement Literal::from_str r=jonas-schievink a=spookyvision

this apparently fixes RTIC 0.6's 
```rust
#[rtic::app]
mod app {}
```

Co-authored-by: Anatol Ulrich <anatol.ulrich@ferrous-systems.com>
2021-11-03 16:19:42 +00:00
Anatol Ulrich
a6df2b16df implement Literal::from_str 2021-11-03 16:50:43 +01:00
bors[bot]
0bd2d234a2
Merge #10667
10667: internal: Expose version string of crates from HIR r=Veykril a=Veykril

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

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-11-03 14:50:39 +00:00
Anatol Ulrich
e8416bb644
Update crates/text_edit/src/lib.rs
Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-11-03 15:44:46 +01:00
Anatol Ulrich
83927e08a8
Update crates/ide/src/rename.rs
Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-11-03 15:44:32 +01:00
Lukas Wirth
52f5af7165 Expose version string of crates fom HIR 2021-11-03 15:40:06 +01:00
bors[bot]
53b5b2fdaa
Merge #10596
10596: internal: Set server status to warning when proc-macro sources change r=Veykril a=Veykril

Fixes https://github.com/rust-analyzer/rust-analyzer/issues/10027
![image](https://user-images.githubusercontent.com/3757771/138102552-208d3edf-a843-49e6-9f48-1e911f54a4ba.png)

It feels wrong using the database in this part of the code, but this was the only way to figure out whether a file belongs to a proc-macro that I could think of.


Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-11-03 14:02:10 +00:00
Lukas Wirth
9025f51118 Add disjoint check back in TextEdit::union 2021-11-03 14:42:15 +01:00
Anatol Ulrich
7581ba3f30 forgot a dbg 2021-11-03 14:21:29 +01:00
Anatol Ulrich
9bce4d6696 accept identical Indels when merging; add rename test case 2021-11-02 21:38:38 +01:00
bors[bot]
7765c1a94f
Merge #10668
10668: fix: Fix for-loop expressions breaking with BlockExpr iterable r=Veykril a=Veykril

Fixes https://github.com/rust-analyzer/rust-analyzer/issues/10665
bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-10-30 14:42:53 +00:00
Lukas Wirth
c93983e76f Fix for-loop expressions breaking with BlockExpr iterable 2021-10-30 16:37:32 +02:00
Lukas Wirth
1d80302b76 Set server status to warning when proc-macro sources change 2021-10-30 14:49:32 +02:00
Laurențiu Nicola
80f9afa1ec Bump object avoid a duplicate dependency 2021-10-30 09:02:45 +03:00
bors[bot]
103bef178c
Merge #10650
10650: minor: Bump deps r=lnicola a=lnicola



Co-authored-by: Laurențiu Nicola <lnicola@dend.ro>
2021-10-29 20:27:51 +00:00
Laurențiu Nicola
d0a99ad54e Bump chalk 2021-10-29 23:26:59 +03:00
bors[bot]
8c078147b5
Merge #10662
10662: Fix Plaintext textDocument/hover r=Veykril a=vsrs

Relates to #10028

Note: the PR corrects only invalid content kind, not formatting.

Co-authored-by: vsrs <vit@conrlab.com>
2021-10-29 16:16:13 +00:00
vsrs
2f862cd6fe Fix Plaintext textDocument/hover 2021-10-29 18:23:47 +03:00
bors[bot]
b9fa37f5b4
Merge #10648
10648: fix: Don't discard attributed items when a proc-macro unexpectedly fails to expand r=Veykril a=Veykril

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

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-10-29 13:13:12 +00:00
Lukas Wirth
98cff6572d Don't discard attributed items when a proc-macro unexpectedly fails to expand 2021-10-29 15:10:44 +02:00
bors[bot]
78108235d5
Merge #10657
10657: feat: Make unqualified derive attributes flyimportable r=Veykril a=Veykril

![UuwpKODbpB](https://user-images.githubusercontent.com/3757771/139436613-1e6eb8fd-f591-4fca-9383-ff7408ee9b18.gif)
Fixes https://github.com/rust-analyzer/rust-analyzer/issues/10052

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-10-29 13:01:49 +00:00
Lukas Wirth
ebd63ec1cf feat: Make unqualified derive attributes flyimportable 2021-10-29 14:51:26 +02:00
bors[bot]
057558b756
Merge #10595
10595: internal: Fix a format error r=Veykril a=dzvon

Fixes #10581

Co-authored-by: Dezhi Wu <wu543065657@163.com>
2021-10-29 10:40:43 +00:00
Dezhi Wu
74396d27c0 Fix: correct markdown link form. 2021-10-29 18:25:32 +08:00
Dezhi Wu
097d527cbd Fix: use a concise way to change link form when generating package.json 2021-10-29 10:00:10 +08:00
Lukas Wirth
7fdbdc4ab2 Enable auto-import and qualify-path in derive attributes 2021-10-28 18:40:38 +02:00
Lukas Wirth
3018ffd85e Refactor ide handling for paths in derive inputs 2021-10-28 16:47:19 +02:00
bors[bot]
f4ba64ee2a
Merge #10623
10623: internal: replace L_DOLLAR/R_DOLLAR with parenthesis hack r=matklad a=matklad

The general problem we are dealing with here is this:

```
macro_rules! thrice {
    ($e:expr) => { $e * 3}
}

fn main() {
    let x = thrice!(1 + 2);
}
```

we really want this to print 9 rather than 7.

The way rustc solves this is rather ad-hoc. In rustc, token trees are
allowed to include whole AST fragments, so 1+2 is passed through macro
expansion as a single unit. This is a significant violation of token
tree model.

In rust-analyzer, we intended to handle this in a more elegant way,
using token trees with "invisible" delimiters. The idea was is that we
introduce a new kind of parenthesis, "left $"/"right $", and let the
parser intelligently handle this.

The idea was inspired by the relevant comment in the proc_macro crate:

https://doc.rust-lang.org/stable/proc_macro/enum.Delimiter.html#variant.None

> An implicit delimiter, that may, for example, appear around tokens
> coming from a “macro variable” $var. It is important to preserve
> operator priorities in cases like $var * 3 where $var is 1 + 2.
> Implicit delimiters might not survive roundtrip of a token stream
> through a string.

Now that we are older and wiser, we conclude that the idea doesn't work.

_First_, the comment in the proc-macro crate is wishful thinking. Rustc
currently completely ignores none delimiters. It solves the (1 + 2) * 3
problem by having magical token trees which can't be duplicated:

* https://rust-lang.zulipchat.com/#narrow/stream/185405-t-compiler.2Frust-analyzer/topic/TIL.20that.20token.20streams.20are.20magic
* https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/Handling.20of.20Delimiter.3A.3ANone.20by.20the.20parser

_Second_, it's not like our implementation in rust-analyzer works. We
special-case expressions (as opposed to treating all kinds of $var
captures the same) and we don't know how parser error recovery should
work with these dollar-parenthesis.

So, in this PR we simplify the whole thing away by not pretending that
we are doing something proper and instead just explicitly special-casing
expressions by wrapping them into real `()`.

In the future, to maintain bug-parity with `rustc` what we are going to
do is probably adding an explicit `CAPTURED_EXPR` *token* which we can
explicitly account for in the parser.

If/when rustc starts handling delimiter=none properly, we'll port that
logic as well, in addition to special handling.

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2021-10-28 10:32:13 +00:00
Dezhi Wu
ffc6cdd871 Fix: transform the asciidoc form link to markdown style when generating the package.json 2021-10-28 10:13:43 +08:00
bors[bot]
210a1d5ece
Merge #10629
10629: Add assist for replacing turbofish with explicit type. r=Veykril a=terrynsun

Converts `::<_>` to an explicit type assignment.

```
let args = args.collect::<Vec<String>>();
```
->
```
let args: Vec<String> = args.collect();
```

Closes #10285

Co-authored-by: Terry Sun <terrynsun@gmail.com>
2021-10-27 21:40:28 +00:00
Terry Sun
d800a1bc93 fixup! rustfmt 2021-10-27 10:58:31 -07:00
Terry Sun
3bbd61d674 fixup! delay to_string() until assist is called 2021-10-27 10:46:25 -07:00
bors[bot]
9d1f15086a
Merge #10649
10649: internal: Remove `CompletionKind` in favor of `CompletionItemKind` r=Veykril a=Veykril

and move some more tests around
bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-10-27 15:38:42 +00:00
Anatol Ulrich
1ac35532c4 remove TODO comment 2021-10-27 17:26:38 +02:00
Anatol Ulrich
df9fb9b159 re-introduce always! 2021-10-27 17:25:42 +02:00
Lukas Wirth
0468b11de7 Remove CompletionKind in favor of CompletionItemKind 2021-10-27 17:23:43 +02:00
Anatol Ulrich
28c73f8374 unwrap-- 2021-10-27 17:23:23 +02:00
Anatol Ulrich
4a1a5ff54e fix logic error: alias detection was too lenient 2021-10-27 17:20:12 +02:00
Lukas Wirth
722489e3ff Remove filtered completion list usage in completion tests 2021-10-27 16:53:39 +02:00
Anatol Ulrich
6cd15c296d wip 2021-10-27 15:40:49 +02:00
Anatol Ulrich
8d3ac328ee remove resolved TODO questions 2021-10-27 15:40:30 +02:00
Anatol Ulrich
f244ed6a1a doxx 2021-10-27 04:46:02 +02:00
Anatol Ulrich
2e0610e64e one down 2021-10-27 04:42:58 +02:00
Anatol Ulrich
95199ac30b make imports less odd 2021-10-27 04:36:32 +02:00
Anatol Ulrich
6decfceae1 WIP: fix: make rename multi-token mapping aware 2021-10-27 04:31:14 +02:00
Terry Sun
6abdbdd0c9 fixup! narrow range; method calls; check for only one type 2021-10-26 17:50:25 -07:00
bors[bot]
dd43f3f2d1
Merge #10642
10642: minor: Add dummy impls for `trace_macros` and `log_syntax` r=Veykril a=Veykril

Both of these are macros for debugging macros and as such don't really need an implementation for us.
Closes https://github.com/rust-analyzer/rust-analyzer/issues/2212
bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-10-26 18:55:42 +00:00
Lukas Wirth
54e6583f53 Add dummy impls for trace_macros and log_syntax 2021-10-26 20:52:38 +02:00
bors[bot]
a3830dfd3b
Merge #10641
10641: fix: make `expand_macro` multi-token mapping aware r=spookyvision a=spookyvision



Co-authored-by: Anatol Ulrich <anatol.ulrich@ferrous-systems.com>
Co-authored-by: Anatol Ulrich <45840+spookyvision@users.noreply.github.com>
2021-10-26 18:18:22 +00:00
Anatol Ulrich
b42093915a
Update crates/ide/src/expand_macro.rs
Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-10-26 20:17:47 +02:00
Anatol Ulrich
e6913be47b fix test 2021-10-26 20:15:25 +02:00
Anatol Ulrich
04f2eb0fba wording 2021-10-26 20:10:09 +02:00
Anatol Ulrich
3f82989153 fix: make expand_macro multi-token mapping aware 2021-10-26 20:09:14 +02:00
bors[bot]
c48730cb72
Merge #10639 #10640
10639: fix: make `goto_declaration` multi-token mapping aware r=Veykril a=spookyvision



10640: assume valid identifier r=Veykril a=spookyvision

improve https://github.com/rust-analyzer/rust-analyzer/pull/10637/ by always returning `Some(potentially_empty_vec)` instead of `None` in the empty case

Co-authored-by: Anatol Ulrich <anatol.ulrich@ferrous-systems.com>
2021-10-26 17:51:33 +00:00
Anatol Ulrich
53be26df50 assume valid identifier 2021-10-26 19:33:50 +02:00
Anatol Ulrich
d8ed15b6a6 fix: make goto_declaration multi-token mapping aware 2021-10-26 19:31:49 +02:00
bors[bot]
ba2b599131
Merge #10592
10592: Fix: only shows one # when we encounter ## r=Veykril a=dzvon

Fixes #10584

Co-authored-by: Dezhi Wu <wu543065657@163.com>
2021-10-26 13:17:13 +00:00
Dezhi Wu
31af94b73a perf: avoid allocating by just slicing.
Signed-off-by: Dezhi Wu <wu543065657@163.com>
2021-10-26 20:59:48 +08:00
bors[bot]
ee1d6cffbf
Merge #10637
10637: fix: make `goto_type_definition` multi-token mapping aware r=Veykril a=spookyvision



Co-authored-by: Anatol Ulrich <anatol.ulrich@ferrous-systems.com>
2021-10-26 10:46:33 +00:00
Anatol Ulrich
c69879423e fix imports 2021-10-26 12:34:40 +02:00
Anatol Ulrich
686f8fbea3 simplify 2021-10-26 12:21:18 +02:00
Anatol Ulrich
2490807ca5 fix: make goto_type_definition multi-token mapping aware 2021-10-25 23:43:58 +02:00
bors[bot]
ed39b45e8d
Merge #10635
10635: fix: fix extract_variable not working on macro_call r=Veykril a=Veykril

Fixes https://github.com/rust-analyzer/rust-analyzer/issues/7410
bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-10-25 19:47:41 +00:00
Lukas Wirth
a2365ea18a fix: fix extract_variable not working on macro_call 2021-10-25 21:46:44 +02:00
bors[bot]
e4ca952be6
Merge #10633
10633: fix: Implement most proc_macro span handling for other ABIs r=Veykril a=Veykril

Follow up to #10378
bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-10-25 15:33:41 +00:00
bors[bot]
aa04d3eb4f
Merge #10634
10634: minor: Drop resolver and `authors` manifest entry in `limit` r=lnicola a=lnicola

The new resolver is on by default in the 2021 edition,

bors r+

Co-authored-by: Laurențiu Nicola <lnicola@dend.ro>
2021-10-25 15:13:34 +00:00
Laurențiu Nicola
0e0ad0377c Drop resolver and authors manifest entries 2021-10-25 18:12:40 +03:00
Lukas Wirth
d2b8ca9b52 fix: Implement most proc_macro span handling for other ABIs 2021-10-25 16:43:49 +02:00
bors[bot]
142b6dc650
Merge #10631
10631: fix: Fix postfix completions panicking r=Veykril a=Veykril

Fixes https://github.com/rust-analyzer/rust-analyzer/issues/10243, I couldn't reproduce the panic with the given snippet, but this change should still guard against it.
bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-10-25 13:24:07 +00:00
Lukas Wirth
a932935d4e Fix postfix completions panicking 2021-10-25 15:22:29 +02:00
Terry Sun
324d7d33e8 Add assist for replacing turbofish with explicit type.
Converts `::<_>` to an explicit type assignment.

```
let args = args.collect::<Vec<String>>();
```
->
```
let args: Vec<String> = args.collect();
```

Closes #10285
2021-10-24 17:38:45 -07:00
Laurențiu Nicola
f0ad6fa68b Revert edition change in test 2021-10-24 14:52:42 +03:00
Aleksey Kladov
485c5e6717 internal: remove unused dollars 2021-10-23 20:44:35 +03:00
Aleksey Kladov
5a83d1be66 internal: replace L_DOLLAR/R_DOLLAR with parenthesis hack
The general problem we are dealing with here is this:

```
macro_rules! thrice {
    ($e:expr) => { $e * 3}
}

fn main() {
    let x = thrice!(1 + 2);
}
```

we really want this to print 9 rather than 7.

The way rustc solves this is rather ad-hoc. In rustc, token trees are
allowed to include whole AST fragments, so 1+2 is passed through macro
expansion as a single unit. This is a significant violation of token
tree model.

In rust-analyzer, we intended to handle this in a more elegant way,
using token trees with "invisible" delimiters. The idea was is that we
introduce a new kind of parenthesis, "left $"/"right $", and let the
parser intelligently handle this.

The idea was inspired by the relevant comment in the proc_macro crate:

https://doc.rust-lang.org/stable/proc_macro/enum.Delimiter.html#variant.None

> An implicit delimiter, that may, for example, appear around tokens
> coming from a “macro variable” $var. It is important to preserve
> operator priorities in cases like $var * 3 where $var is 1 + 2.
> Implicit delimiters might not survive roundtrip of a token stream
> through a string.

Now that we are older and wiser, we conclude that the idea doesn't work.

_First_, the comment in the proc-macro crate is wishful thinking. Rustc
currently completely ignores none delimiters. It solves the (1 + 2) * 3
problem by having magical token trees which can't be duplicated:

* https://rust-lang.zulipchat.com/#narrow/stream/185405-t-compiler.2Frust-analyzer/topic/TIL.20that.20token.20streams.20are.20magic
* https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/Handling.20of.20Delimiter.3A.3ANone.20by.20the.20parser

_Second_, it's not like our implementation in rust-analyzer works. We
special-case expressions (as opposed to treating all kinds of $var
captures the same) and we don't know how parser error recovery should
work with these dollar-parenthesis.

So, in this PR we simplify the whole thing away by not pretending that
we are doing something proper and instead just explicitly special-casing
expressions by wrapping them into real `()`.

In the future, to maintain bug-parity with `rustc` what we are going to
do is probably adding an explicit `CAPTURED_EXPR` *token* which we can
explicitly account for in the parser.

If/when rustc starts handling delimiter=none properly, we'll port that
logic as well, in addition to special handling.
2021-10-23 20:44:31 +03:00
Laurențiu Nicola
8457ae34bd Set MSRV 2021-10-23 15:07:11 +03:00
bors[bot]
fe7c516084
Merge #10602
10602: Add qualify method call assist r=Veykril a=qepasa

This adds `qualify_method_call` assist that allows to replace a method (or trait) call that resolves with its fully qualified path.

For example, for stuct method:
```rust
struct Foo;
impl Foo {
    fn foo(&self) {}
}
```
```
let foo = Foo {};
foo.fo$0o();
```

becomes
```rust
let foo = Foo {};
Foo::foo(&foo);
```

for a trait method:

```rust
struct Foo;
trait FooTrait {
    fn foo(&self) {}
}
impl FooTrait for Foo {
    fn foo(&self) {}
}
```
following call:
```rust
let foo = Foo {};
foo.fo$0o();
```

becomes:
```rust
let foo = Foo {};
FooTrait::foo(&foo);
```

fixes #10453 

Co-authored-by: Paweł Palenica <pawelpalenica11@gmail.com>
2021-10-23 08:34:51 +00:00
bors[bot]
a75353e8ac
Merge #9939
9939: feat: Adding extract_module assist r=Veykril a=feniljain

Should solve https://github.com/rust-analyzer/rust-analyzer/issues/9591

Co-authored-by: vi_mi <fenil.jain2018@vitstudent.ac.in>
Co-authored-by: Laurențiu Nicola <lnicola@dend.ro>
2021-10-22 09:29:16 +00:00
vi_mi
3e73a46660 fix: making tests compatible with new trimmed sel_range 2021-10-22 09:16:56 +00:00
Paweł Palenica
bfc86f64c3 apply code review suggestions 2021-10-21 23:42:14 -07:00
Laurențiu Nicola
ca44b6892e Use array IntoIter 2021-10-22 09:23:29 +03:00
Lukas Wirth
1294bfce86 Migrate to edition 2021 2021-10-21 20:10:40 +02:00
bors[bot]
6aeeb4ef33
Merge #10603
10603: fix: Don't resolve attributes to non attribute macros r=Veykril a=Veykril

Also changes `const`s to `static`s for `Limit`s as we have interior mutability in those(though only used with a certain feature flag enabled).

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-10-21 10:39:26 +00:00
Lukas Wirth
ea2a2c52fc Don't resolve attributes to non attribute macros 2021-10-21 12:22:40 +02:00
Paweł Palenica
91988f46b7 Add generated docs 2021-10-20 23:54:22 -07:00
Paweł Palenica
c2fd0c48a6 cleanup qualify_path 2021-10-20 23:39:25 -07:00
Paweł Palenica
b3d92052ce Remove comment 2021-10-20 23:38:28 -07:00
Paweł Palenica
9f31f59fdf Cleanup - remove unnecessary pub 2021-10-20 23:37:31 -07:00
Paweł Palenica
c8820d342f Run cargo fmt 2021-10-20 23:35:14 -07:00
Paweł Palenica
bb00b09d22 Add qualify method call assist 2021-10-20 23:28:30 -07:00
bors[bot]
6877240fdf
Merge #10563
10563: feat: Make "Generate getter" assist use semantic info r=agluszak a=agluszak

This PR makes "Generate getter" assist use semantic info instead of dealing with types encoded as strings.
Getters for types which are:
- `Copy` no longer return references
- `AsRef<str>` (i.e. `String`) return `&str` (instead of `&String`)
- `AsRef<[T]>` (i.e. `Vec<T>`) return `&[T]` (instead of `&Vec<T>`)
- `AsRef<T>` (i.e. `Box<T>`) return `&T` (instead of `&Box<T>`)
- `Option<T>` return `Option<&T>` (instead of `&Option<T>`)
- `Result<T, E>` return `Result<&T, &E>` (instead of `&Result<T, E>`)

String, Vec, Box and Option were previously handled as special cases.

Closes #10295


Co-authored-by: Andrzej Głuszak <gluszak.andrzej@gmail.com>
2021-10-20 21:02:46 +00:00
bors[bot]
11326a6847
Merge #10387
10387: Move `IdxRange` into la-arena r=Veykril a=arzg

Currently, `IdxRange` (named `IdRange`) is located in `hir_def::item_tree`, when really it isn’t specific to `hir_def` and could become part of la-arena. The rename from `IdRange` to `IdxRange` is to maintain consistency with the naming convention used throughout la-arena (`Idx` instead of `Id`, `RawIdx` instead of `RawId`). This PR also adds a few new APIs to la-arena on top of `IdxRange` for convenience, namely:

- indexing into an `Arena` by an `IdxRange` and getting a slice of values back
- creating an `IdxRange` from an inclusive range

Currently this PR also exposes a new `Arena::next_idx` method to make constructing inclusive`IdxRange`s using `IdxRange::new` easier; however, it would in my opinion be better to remove this as it allows for easy creation of out-of-bounds `Idx`s, when `IdxRange::new_inclusive` mostly covers the same use-case while being less error-prone.

I decided to bump the la-arena version to 0.3.0 from 0.2.0 because adding a new `Index` impl for `Arena` turned out to be a breaking change: I had to add a type hint in `crates/hir_def/src/body/scope.rs` when one wasn’t necessary before, since rustc couldn’t work out the type of a closure parameter now that there are multiple `Index` impls. I’m not sure whether this is the right decision, though. 

Co-authored-by: Aramis Razzaghipour <aramisnoah@gmail.com>
2021-10-20 20:54:36 +00:00
Andrzej Głuszak
88e2f07826 Fixes 2021-10-20 22:35:31 +02:00
Andrzej Głuszak
a2242dcf1b Fixes 2021-10-20 21:35:35 +02:00
bors[bot]
d1cdfa800c
Merge #10600
10600: minor: Make some functions non-generic r=Veykril a=lnicola

This reduces `text` size by 10192 bytes (0.064% 😢), with no apparent change in performance.

Co-authored-by: Laurențiu Nicola <lnicola@dend.ro>
2021-10-20 18:05:31 +00:00
Laurențiu Nicola
24eca25d8a Make some functions non-generic 2021-10-20 20:20:17 +03:00
bors[bot]
c2e36291f3
Merge #10598
10598: minor: Remove obsolete test module r=Veykril a=Veykril

bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-10-20 15:03:36 +00:00
Lukas Wirth
96fbef606a Remove obsolete test module 2021-10-20 17:03:09 +02:00
bors[bot]
25a498bfc7
Merge #10597
10597: fix: Fix standard library doclinks not going to the correct page r=Veykril a=Veykril

Fixes https://github.com/rust-analyzer/rust-analyzer/issues/10082
bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-10-20 14:46:28 +00:00
Lukas Wirth
8ed86fc25d Fix standard library doclinks not going to the correct page 2021-10-20 16:36:01 +02:00
Lukas Wirth
bed6eae304 Fix qualified lint completions ignoring the qualifier value 2021-10-20 14:03:41 +02:00
Lukas Wirth
6c9b8d7ce5 Generate rustdoc lints 2021-10-20 13:48:05 +02:00
Dezhi Wu
b7b9cd5e67 Fix: only shows one # when we encounter ## 2021-10-20 15:05:32 +08:00
rainy-me
1ea2c72386 Fix: remove extra newline 2021-10-19 23:46:43 +09:00
rainy-me
adb3729b91 Fix: expand glob import to empty braces if the glob is unused 2021-10-19 23:31:30 +09:00
bors[bot]
580a6c41eb
Merge #10568
10568: fix(assist): fix #10566 and #10567 r=bnjjj a=bnjjj

close #10566
close #10567

Co-authored-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
2021-10-19 12:57:24 +00:00
Benjamin Coenen
3a5147e9fe fix(assist): delete trailing whitespaces
Signed-off-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
2021-10-19 14:54:29 +02:00
bors[bot]
dfa355b431
Merge #10588
10588: internal: Parse const trait bounds r=Veykril a=Veykril

Fixes https://github.com/rust-analyzer/rust-analyzer/issues/10582
bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-10-19 12:32:30 +00:00
Lukas Wirth
b219a4c465 internal: Parse const trait bounds 2021-10-19 14:20:00 +02:00
bors[bot]
e77fc481ad
Merge #10587
10587: fix: Fix `add_missing_match_arm` panicking on failed upmapping r=Veykril a=Veykril

Closes https://github.com/rust-analyzer/rust-analyzer/issues/10580#issuecomment-946170475

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-10-19 12:16:30 +00:00
Lukas Wirth
7e1d6e5265 fix: Fix add_missing_match_arm panicking 2021-10-19 14:00:24 +02:00
bors[bot]
0e4c3b2c2b
Merge #10586
10586: internal: Derive completions work on hir, not names r=Veykril a=Veykril

bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-10-19 11:51:07 +00:00
Lukas Wirth
3dfe5045c5 Derive completions work on hir, not names 2021-10-19 13:50:08 +02:00
bors[bot]
d85946b735
Merge #10585
10585: fix: Resolve derive attributes even when shadowed r=Veykril a=Veykril

bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-10-19 11:43:08 +00:00
Lukas Wirth
aa9d093488 Resolve derive attributes even when shadowed 2021-10-19 13:42:36 +02:00
Yoshua Wuyts
e346d32e69 fix Ordering::Equal path 2021-10-18 14:45:24 +02:00
Yoshua Wuyts
41fd824415 Revert "Simplify generated PartialOrd code"
This reverts commit 601ed3a10d.
2021-10-18 14:41:38 +02:00
bors[bot]
48c3be922e
Merge #10574
10574: fix: Fix PartialOrd codegen r=lnicola a=yoshuawuyts

Closes https://github.com/rust-analyzer/rust-analyzer/issues/10571#issuecomment-945516462. Thanks!

r? `@lnicola` 

Co-authored-by: Yoshua Wuyts <yoshuawuyts@gmail.com>
2021-10-18 10:47:04 +00:00
Yoshua Wuyts
a9ec345cf7 Fix PartialOrd codegen 2021-10-18 12:44:05 +02:00
Laurențiu Nicola
29d281e523 Fix tests 2021-10-18 12:03:49 +03:00
Laurențiu Nicola
edb03ad6f1 Pull in new lsp-types for VS compat 2021-10-18 12:03:49 +03:00
Lukas Wirth
5704de66c2 Skip non clippy completions when completing a clippy path 2021-10-17 23:04:38 +02:00
Benjamin Coenen
7ee1a77235 fix(assist): fix #10566 and #10567
Signed-off-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
2021-10-17 20:24:40 +02:00
Andrzej Głuszak
98676efdc5 Semantic getter 2021-10-17 16:33:14 +02:00
bors[bot]
401daa5f77
Merge #10417
10417: feat(assist): add new assist to unwrap the result return type r=bnjjj a=bnjjj

do the opposite of assist "wrap the return type in Result"

Co-authored-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
Co-authored-by: Coenen Benjamin <benjamin.coenen@hotmail.com>
2021-10-17 13:32:35 +00:00
Coenen Benjamin
ccf05debfe
Update crates/ide_assists/src/handlers/unwrap_result_return_type.rs
Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-10-17 15:24:20 +02:00
bors[bot]
d9080addf9
Merge #10562
10562: fix: Fix clippy attribute completions always prefixing inserting `clippy::` r=Veykril a=Veykril

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

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-10-17 11:30:49 +00:00
Lukas Wirth
99906baa17 Fix clippy attribute completions always prefixing with clippy:: 2021-10-17 13:07:49 +02:00
Lukas Wirth
ce47d13101 Make attribute completions more ast based 2021-10-17 12:44:44 +02:00
Lukas Wirth
e329b7742b Reorder CompletionContext functions 2021-10-17 11:15:56 +02:00
bors[bot]
c16d04e494
Merge #10561
10561: internal: Don't turn local names into strings in CompletionContext r=Veykril a=Veykril

bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-10-17 09:00:06 +00:00
Lukas Wirth
791a2afbf9 Don't turn local names into strings in CompletionContext 2021-10-17 10:59:06 +02:00
bors[bot]
dd8e831c51
Merge #10558
10558: internal: Refactor lifetime completion context fields r=Veykril a=Veykril

bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-10-16 21:57:36 +00:00
Lukas Wirth
81ccebf1f2 internal: Refactor lifetime completion context fields 2021-10-16 23:56:57 +02:00
bors[bot]
2d7d7f729d
Merge #10557
10557: fix: Fix qualified path completion not completing macros r=Veykril a=Veykril

bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-10-16 21:33:55 +00:00
Lukas Wirth
2fbd52c78f fix: Fix qualified path completion not completing macros 2021-10-16 23:33:09 +02:00
Milo
6f28325830 fix 2021-10-16 15:02:56 +01:00
Milo
30be95a821 add a comment 2021-10-16 14:15:17 +01:00
Milo
5a93457c1b revert 2021-10-16 14:13:43 +01:00
Milo
35e5daacc3 more clippy fixes 2021-10-16 12:32:55 +01:00
Laurențiu Nicola
2bf5f14666 Use trimmed selection range 2021-10-16 13:39:55 +03:00
vi_mi
2efcff7f75 fix: Adding tuple fields in ADT, chore: test action section
unindentation
2021-10-16 13:36:06 +03:00
vi_mi
227490c069 fix: arbitary noop of assist and same file double writes 2021-10-16 13:36:06 +03:00
vi_mi
32b95ea310 feat: Adding extract_module assist 2021-10-16 13:36:06 +03:00
bors[bot]
3c468ab2fc
Merge #10542
10542: Use workspace cargo to fetch rust source's metadata r=lnicola a=Alexendoo

Previously the detected cargo is the global one, as it uses the
directory of the rust source which doesn't pick up the local override

This fixes the case in clippy where the local rust toolchain is a recent
nightly that has a 2021 edition Cargo.toml. The global (stable) cargo
returns an error attempting to parse it

Fixes #10445

Co-authored-by: Alex Macleod <alex@macleod.io>
2021-10-16 10:28:46 +00:00
Laurențiu Nicola
cd0c45fdbc Hide private methods in generate_delegate_methods 2021-10-16 13:16:22 +03:00
bors[bot]
6c7526d308
Merge #10552
10552: fix: Fix missing_fields diagnostic fix replacing wrong text ranges r=Veykril a=Veykril

Fixes #5393 by replacing the problematic behaviour there with a new "problem"

It replaces the correct range now, but it potentially discards the whitespace in the macro input. This is the best we can do currently until we get a formatter.

bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-10-15 17:29:03 +00:00
Lukas Wirth
ac505b21a8 Fix missing_fields diagnostic fix replacing wrong text ranges 2021-10-15 19:27:19 +02:00
bors[bot]
c67db1b952
Merge #10543
10543: Narrow add_missing_match_arms assist range r=Veykril a=antonfirsov

Contributes to #10220 with logic borrowed from #10267.

Note: if anyone has recommendations for further analyzers to check, I'm happy to (hard to do it on my own, I'm completely new to the language).

Co-authored-by: Anton Firszov <antonfir@gmail.com>
2021-10-15 16:05:15 +00:00
Anton Firszov
3d9ce6b6ce cov_mark for add_missing_match_arms special cases 2021-10-15 17:53:01 +02:00
Anton Firszov
1c0eed5f97 undo unnecessary test changes 2021-10-15 14:45:11 +02:00
Anton Firszov
cc6eee1b60 cosmetics 2021-10-15 14:36:37 +02:00
Anton Firszov
e25b20e48d update generated.rs 2021-10-15 14:33:44 +02:00
Anton Firszov
a01a4bae18 fix sample + cosmetics + one more test 2021-10-15 14:30:22 +02:00
Anton Firszov
4e16cfbdf4 simple implementation 2021-10-15 13:19:46 +02:00
Anton Firszov
1e303cc035 cursor_inside_simple_match_arm_list -- tests 2021-10-15 12:15:52 +02:00
Aramis Razzaghipour
dce5c640f8
Move IdxRange into la_arena 2021-10-15 13:03:28 +11:00
bors[bot]
3a79af7e27
Merge #10491
10491: Support nested type on replace if let with match r=k-nasa a=k-nasa

## Why

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

Now, Replacing if-let with match cant't output exhaustive patterns code.
This was because the `else` conversion used specific types (ex. Option, Result) instead of wildcards.

I thought it was more of a problem to generate non-exhaustive patterns than the benefits of using the concrete one.

How about using wildcards in `else`? 
Is this change policy acceptable?

## What

- using wildcards on `make_else_arm`
- Change test cases

Co-authored-by: k-nasa <htilcs1115@gmail.com>
2021-10-14 22:41:06 +00:00
bors[bot]
bfb8f73fb3
Merge #10545
10545: A few clippy fixes r=Veykril a=Milo123459

A few clippy fixes

Co-authored-by: Milo <50248166+Milo123459@users.noreply.github.com>
2021-10-14 20:10:59 +00:00
bors[bot]
0af9d1fc8a
Merge #10546
10546: feat: Implement promote_local_to_const assist r=Veykril a=Veykril

Fixes #7692, that is now one can invoke the `extract_variable` assist on something and then follow that up with this assist to turn it into a const.
bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-10-14 19:51:34 +00:00
Lukas Wirth
06286ee90b Implement promotoe_local_to_const assist 2021-10-14 21:49:46 +02:00
Milo
35de195c41 a few clippy fixes 2021-10-14 19:57:21 +01:00
Anton Firszov
68a50150d6 use ctx.selection_trimmed() instead of ctx.frange.range 2021-10-14 20:45:10 +02:00
Anton Firszov
0a8a56b77a apply formatting recommendations 2021-10-14 20:38:06 +02:00
Anton Firszov
01e3022521 update generated.rs 2021-10-14 20:35:59 +02:00
Anton Firszov
8cca6242f8 make it work from macro 2021-10-14 20:31:33 +02:00
bors[bot]
e52d47a3b8
Merge #10539
10539: Add "generate delegate methods" assist r=Veykril a=yoshuawuyts

_Co-authored with `@rylev_.`

This patch adds a new assist: "generate delegate method" which creates a method that calls to a method defined on an inner field. Delegation is common when authoring newtypes, and having IDE support for this is the best way we can make this easier to author in Rust, bar adding language-level support for it. Thanks!

Closes #5944.

## Example

__before__
```rust
struct Age(u8);
impl Age {
    fn age(&self) -> u8 {
        self.0
    }
}

struct Person {
    ag$0e: Age,
}
```

__after__
```rust
struct Age(u8);
impl Age {
    fn age(&self) -> u8 {
        self.0
    }
}

struct Person {
    age: Age,
}

impl Person {
    $0fn age(&self) -> u8 {
        self.age.age()
    }
}
```

Co-authored-by: Ryan Levick <me@ryanlevick.com>
Co-authored-by: Yoshua Wuyts <yoshuawuyts@gmail.com>
2021-10-14 18:16:17 +00:00
Anton Firszov
fb47a65ab2 apply necessary test changes 2021-10-14 19:31:27 +02:00
Yoshua Wuyts
f84b0b3242 fix ret type in generic 2021-10-14 18:38:52 +02:00
Yoshua Wuyts
987ab1feda implement feedback from review 2021-10-14 18:19:20 +02:00
Anton Firszov
a17a132617 Narrow add_missing_match_arms assist range 2021-10-14 18:15:00 +02:00
Alex Macleod
a6eeb75120 Use workspace cargo to fetch rust source's metadata
Previously the detected cargo is the global one, as it uses the
directory of the rust source which doesn't pick up the local override

This fixes the case in clippy where the local rust toolchain is a recent
nightly that has a 2021 edition Cargo.toml. The global (stable) cargo
returns an error attempting to parse it

Fixes #10445
2021-10-14 16:20:11 +01:00
Yoshua Wuyts
68ffe91526 Add support for tuple structs 2021-10-14 14:18:12 +02:00
bors[bot]
a30941e2a5
Merge #10517
10517: Show cargo check failures to the user r=Veykril a=Veykril

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

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-10-14 11:57:16 +00:00