Commit Graph

15572 Commits

Author SHA1 Message Date
bors[bot] ceffcf8a11 Merge #7984
7984: Improve version display r=matklad a=lnicola

Maybe closes #7854

The version string for unreleased builds looks like this now:

```
$ rust-analyzer --version
rust-analyzer 2021-03-08-159-gc0459c535
```

Release builds should only have the tag name (`2021-03-15`).

Co-authored-by: Laurențiu Nicola <lnicola@dend.ro>
2021-03-13 13:22:25 +00:00
bors[bot] fe4a94fff3 Merge #7994
7994: Speed up mbe matching in heavy recursive cases r=edwin0cheng a=edwin0cheng

In some cases (e.g.  #4186), mbe matching is very slow due to a lot of copy and allocation for bindings, this PR try to solve this problem by introduce a semi "link-list" approach for bindings building.

I used this [test case](https://github.com/weiznich/minimal_example_for_rust_81262) (for `features(32-column-tables)`) to run following command to benchmark:
```
time rust-analyzer analysis-stats  --load-output-dirs ./ 
```

Before this PR : 2 mins
After this PR: 3 seconds.

However, for 64-column-tables cases, we still need 4 mins to complete. 

I will try to investigate in the following weeks.

bors r+




Co-authored-by: Edwin Cheng <edwin0cheng@gmail.com>
2021-03-13 13:04:45 +00:00
Edwin Cheng 9117148f42 Add bindings builder for speed up matching 2021-03-13 20:52:36 +08:00
Edwin Cheng f1350dd93c add expand log 2021-03-13 20:14:21 +08:00
bors[bot] 88f78bdb9b Merge #7991
7991: Simplify hir_def TestDB r=jonas-schievink a=jonas-schievink

bors r+

Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
2021-03-13 01:25:33 +00:00
Jonas Schievink 2b5ea5c730 Simplify hir_def TestDB 2021-03-13 02:24:53 +01:00
bors[bot] 5368e2c103 Merge #7989
7989: Remove `ItemTree::source` r=jonas-schievink a=jonas-schievink

`HasSource` should be used instead

bors r+

Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
2021-03-12 22:55:02 +00:00
Jonas Schievink 8447f101ac Remove ItemTree::source
`HasSource` should be used instead
2021-03-12 23:54:29 +01:00
bors[bot] 437527b226 Merge #7986
7986: Simplify a bit r=flodiebold a=flodiebold



Co-authored-by: Florian Diebold <flodiebold@gmail.com>
2021-03-12 19:52:07 +00:00
Florian Diebold 784636f1c1 Simplify a bit 2021-03-12 20:51:29 +01:00
bors[bot] 05814e542f Merge #7985
7985: Use Chalk Environment more directly r=flodiebold a=flodiebold



Co-authored-by: Florian Diebold <florian.diebold@freiheit.com>
2021-03-12 19:41:23 +00:00
Florian Diebold ec70387a4c Use Chalk Environment more directly 2021-03-12 19:12:17 +01:00
Laurențiu Nicola 88ef0541a5 Improve version display 2021-03-12 19:49:00 +02:00
bors[bot] c0459c5357 Merge #7956
7956: Add assist to convert for_each into for loops r=Veykril a=SaiintBrisson

This PR resolves #7821.
Adds an assist to that converts an `Iterator::for_each` into a for loop: 

```rust
fn main() {
    let vec = vec![(1, 2), (2, 3), (3, 4)];
    x.iter().for_each(|(x, y)| {
        println!("x: {}, y: {}", x, y);
    })
}
```
becomes
```rust
fn main() {
    let vec = vec![(1, 2), (2, 3), (3, 4)];
    for (x, y) in x.iter() {
        println!("x: {}, y: {}", x, y);
    });
}
```

Co-authored-by: Luiz Carlos Mourão Paes de Carvalho <luizcarlosmpc@gmail.com>
Co-authored-by: Luiz Carlos <luizcarlosmpc@gmail.com>
Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-03-12 14:45:04 +00:00
Lukas Wirth 6d35c67b6e Fix convert_iter_for_each_to_for doctest 2021-03-12 15:42:53 +01:00
bors[bot] 19dd1fd4d4 Merge #7904
7904: Improved completion sorting r=JoshMcguigan a=JoshMcguigan

I was working on extending #3954 to apply completion scores in more places (I'll have another PR open for that soon) when I discovered that actually completion sorting was not working for me at all in `coc.nvim`. This led me down a bit of a rabbit hole of how coc and vs code each sort completion items.

Before this PR, rust-analyzer was setting the `sortText` field on completion items to `None` if we hadn't applied any completion score for that item, or to the label of the item with a leading whitespace character if we had applied any completion score. Completion score is defined in rust-analyzer as an enum with two variants, `TypeMatch` and `TypeAndNameMatch`. 

In vs code the above strategy works, because if `sortText` isn't set [they default it to the label](https://github.com/microsoft/vscode/commit/b4ead4ed665e1ce2e58d8329c682f78da2d4e89d). However, coc [does not do this](https://github.com/neoclide/coc.nvim/blob/e211e361475a38b146a903b9b02343551c6cd372/src/completion/complete.ts#L245).

I was going to file a bug report against coc, but I read the [LSP spec for the `sortText` field](https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_completion) and I feel like it is ambiguous and coc could claim what they do is a valid interpretation of the spec.

Further, the existing rust-analyzer behavior of prepending a leading whitespace character for completion items with any completion score does not handle sorting `TypeAndNameMatch` completions above `TypeMatch` completions. They were both being treated the same.

The first change this PR makes is to set the `sortText` field to either "1" for `TypeAndNameMatch` completions, "2" for `TypeMatch` completions, or "3" for completions which are neither of those. This change works around the potential ambiguity in the LSP spec and fixes completion sorting for users of coc. It also allows `TypeAndNameMatch` items to be sorted above just `TypeMatch` items (of course both of these will be sorted above completion items without a score). 

The second change this PR makes is to use the actual completion scores for ref matches. The existing code ignored the actual score and always assumed these would be a high priority completion item.

#### Before

Here coc just sorts based on how close the items are in the file.

![image](https://user-images.githubusercontent.com/22216761/110249880-46063580-7f2d-11eb-9233-91a2bbd48238.png)

#### After

Here we correctly get `zzz` first, since that is both a type and name match. Then we get `ccc` which is just a type match.

![image](https://user-images.githubusercontent.com/22216761/110249883-4e5e7080-7f2d-11eb-9269-a3bc133fdee7.png)


Co-authored-by: Josh Mcguigan <joshmcg88@gmail.com>
2021-03-12 14:23:32 +00:00
Josh Mcguigan acbe297fbd update relevance score u8 -> u32 2021-03-12 06:16:04 -08:00
Josh Mcguigan 10fb065b14 add relevance score test 2021-03-12 06:16:04 -08:00
Josh Mcguigan 9ee3914c61 remove unused CompletionScore enum 2021-03-12 06:16:04 -08:00
Josh Mcguigan 3679821eea add completion relevance score 2021-03-12 06:16:01 -08:00
bors[bot] 393e235659 Merge #7980
7980: Fix remaining references to `cargo xtask codegen` r=matklad a=Veykril



Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-03-12 14:11:42 +00:00
Lukas Wirth ebf4448f78 Fix remaining references to cargo xtask codegen 2021-03-12 15:10:33 +01:00
Luiz Carlos Mourão Paes de Carvalho e505752442 fix: generated test fixture 2021-03-12 08:53:57 -03:00
Luiz Carlos 7a9230acdf fix: replace doc-comments with normal comments
Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-03-12 08:44:03 -03:00
Luiz Carlos Mourão Paes de Carvalho f67861310c refactor: refactored and reduced assist code 2021-03-12 08:06:50 -03:00
bors[bot] c0e9530fd0 Merge #7978
7978: Unify naming r=matklad a=matklad

bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2021-03-12 09:23:04 +00:00
Aleksey Kladov 7e217a42e1 Unify naming 2021-03-12 12:22:45 +03:00
bors[bot] c01ef6eaba Merge #7974
7974: use references in CompletionItem's builder r=matklad a=yonip23

@matklad 
This is a follow up to [this pr](https://github.com/rust-analyzer/rust-analyzer/pull/7973)

Co-authored-by: yonip23 <yoni@codota.com>
2021-03-12 08:41:16 +00:00
yonip23 99c4a41cd1 use references in CompletionItem's builder 2021-03-11 17:46:41 +02:00
bors[bot] db6364fecc Merge #7972
7972: fix: add semicolon after type ascription r=matklad a=conradludgate

Fixes #7971

Co-authored-by: Conrad Ludgate <conradludgate@gmail.com>
2021-03-11 10:41:00 +00:00
Conrad Ludgate 233820d780 fix: add semicolon after type ascription 2021-03-11 10:36:45 +00:00
bors[bot] 610eba3320 Merge #7969
7969: Return original text range in PrepareRename responses when inside macro r=Veykril a=Veykril

bors r+
Issue found in #7968

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-03-10 21:29:05 +00:00
Lukas Wirth 98d2dbb90e Return original text range in PrepareRename responses when inside macro 2021-03-10 22:26:41 +01:00
bors[bot] 052fe49179 Merge #7967
7967: Use expect-test for builtin macro/derive tests r=jonas-schievink a=jonas-schievink

bors r+

Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
2021-03-10 20:07:53 +00:00
Jonas Schievink bc4ecb199b Use expect-test for builtin macro/derive tests 2021-03-10 21:05:02 +01:00
bors[bot] 6c32e2d8a0 Merge #7965
7965: cargo update and lexer r=kjeremy a=kjeremy



Co-authored-by: kjeremy <kjeremy@gmail.com>
2021-03-10 18:59:19 +00:00
kjeremy 08e0e9976d cargo update and lexer 2021-03-10 13:47:12 -05:00
bors[bot] 0b96f1a047 Merge #7964
7964: Implement builtin `cfg!` macro r=jonas-schievink a=jonas-schievink

bors r+

Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
2021-03-10 18:46:58 +00:00
Luiz Carlos Mourão Paes de Carvalho 6236b1eaf8 fix: remove semicolon 2021-03-10 15:43:57 -03:00
Jonas Schievink 2b8674b37e Implement builtin cfg! macro 2021-03-10 19:43:03 +01:00
bors[bot] f0e78f2ed6 Merge #7961
7961: add user docs for ssr assist r=JoshMcguigan a=JoshMcguigan

@matklad 

This is a small follow up on #7874, adding user docs for the SSR assist functionality. Since most other assists aren't handled this way I wasn't sure exactly how we wanted to document this, so feel free to suggest alternatives.

Co-authored-by: Josh Mcguigan <joshmcg88@gmail.com>
2021-03-10 17:06:11 +00:00
Josh Mcguigan 40587b08a0 add user docs for ssr assist 2021-03-10 09:04:47 -08:00
bors[bot] b35559a246 Merge #7959
7959: Prefer names from outer DefMap over extern prelude r=jonas-schievink a=jonas-schievink

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

Just one more special case, how bad could it be.

bors r+

Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
2021-03-10 15:35:10 +00:00
Jonas Schievink c2622c9228 Prefer names from outer DefMap over extern prelude 2021-03-10 16:33:18 +01:00
bors[bot] 83280ea574 Merge #7958
7958: Avoid double text edits when renaming mod declaration r=matklad a=Veykril

Closes https://github.com/rust-analyzer/rust-analyzer/issues/7916

See https://github.com/microsoft/vscode-languageserver-node/issues/752 for context

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-03-10 15:07:46 +00:00
Lukas Wirth 3af69b5359 Avoid double text edits when renaming mod declaration 2021-03-10 15:49:01 +01:00
bors[bot] 9dc13408f9 Merge #7874
7874: add apply ssr assist r=JoshMcguigan a=JoshMcguigan

This PR adds an `Apply SSR` assist which was briefly mentioned in #3186. It allows writing an ssr rule as a comment, and then applying that SSR via an assist. This workflow is much nicer than the default available via `coc-rust-analyzer` when iterating to find the proper replacement.

As currently implemented, this requires the ssr rule is written as a single line in the comment, and it doesn't require any kind of prefix. Anything which properly parses as a ssr rule will enable the assist. The benefit of requiring the ssr rule be on a single line is it allows for a workflow where the user has several rules written one after the other, possibly to be triggered in order, without having to try to parse multiple lines of text and determine where one rule ends and the next begins. The benefit of not requiring a prefix is less typing 😆  - plus, I think the chance of something accidentally parsing as an ssr rule is minimal.

I think a reasonable extension of this would be to allow either any ssr rule that fits on a single line, or any comment block which in its entirety makes up a single ssr rule (parsing a comment block containing multiple ssr rules and running them all would break the use case that currently works where a user writes multiple ssr rules then runs them each one by one in arbitrary order).

I've marked this as a draft because for some reason I am strugging to make the unit tests pass. It does work when I compile rust-analyzer and test it in my editor though, so I'm not sure what is going on.

Co-authored-by: Josh Mcguigan <joshmcg88@gmail.com>
2021-03-10 14:34:59 +00:00
Josh Mcguigan 09307be75b add apply ssr assist 2021-03-10 06:02:15 -08:00
bors[bot] a9b1e5cde1 Merge #7957
7957: Fix labels for single import assists r=SomeoneToIgnore a=SomeoneToIgnore

Before: 
![image](https://user-images.githubusercontent.com/2690773/110609185-a26b8e00-8195-11eb-87be-d21b75817c22.png)

After:
![image](https://user-images.githubusercontent.com/2690773/110609198-a5667e80-8195-11eb-8c58-9ae19ba71905.png)


Co-authored-by: Kirill Bulatov <mail4score@gmail.com>
2021-03-10 09:42:36 +00:00
Kirill Bulatov 94bb9cb9ee Fix labels for single import assists 2021-03-10 11:30:25 +02:00