Commit Graph

15934 Commits

Author SHA1 Message Date
Edwin Cheng
9117148f42 Add bindings builder for speed up matching 2021-03-13 20:52:36 +08:00
ivan770
d064ed5f63
Count derefs as matched types if possible 2021-03-13 14:34:11 +02: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
Josh Mcguigan
d5f0f58e63 add params_display and ty_display 2021-03-12 13:46:40 -08:00
Josh Mcguigan
53bb46fa85 show function params in completion detail 2021-03-12 13:36:13 -08: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
Jake Goulding
63155d66f5 Allow applying De Morgan's law to multiple terms at once 2021-03-12 10:19:54 -05: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](b4ead4ed66). However, coc [does not do this](e211e36147/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
vsrs
49cdb2452a Fix LSP extensions documentation 2021-03-11 17:59:27 +03:00
vsrs
00e52e1f42 Add Feature: Related Tests comment 2021-03-11 17:58:45 +03:00
vsrs
daa2637486 Apply review suggestions 2021-03-11 17:39:41 +03: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
Jonas Schievink
7b1a0d5fb7 Diagnose files that aren't in the module tree 2021-03-10 20:30:20 +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