Commit graph

15713 commits

Author SHA1 Message Date
bors[bot]
1a82af3527
Merge #7900 #8000
7900: show function params in completion detail r=matklad a=JoshMcguigan

This resolves #7842 by updating the detail for function completions from `-> T` to `fn(T, U) -> V`. I added an expicit unit test for this, `ide_completion::render::fn_detail_includes_args_and_return_type`, which passes.

Lots of other unit tests fail (~60 of them) due to this change, although I believe the failures are purely cosmetic (they were testing the exact format of this output). I'm happy to go update those tests, but before I do that I'd like to make sure this is in fact the format we want for the detail?

edit - I realized `UPDATE_EXPECT=1 cargo test` automatically updates `expect!` tests. Big 👍 to whoever worked on that! So I'll go ahead and update all these tests soon. But I still would like to confirm `fn(T, U) -> V` is the desired content in the `detail` field. 

8000: Use hir formatter for hover text r=matklad a=oxalica

Fix #2765 , (should) fix #4665

Co-authored-by: Josh Mcguigan <joshmcg88@gmail.com>
Co-authored-by: oxalica <oxalicc@pm.me>
2021-03-16 08:05:24 +00:00
bors[bot]
62ec04bbd5
Merge #8036 #8046
8036: completions: provide relevance bonus for enum types, and suggest ref matches for fn and enum r=matklad a=JoshMcguigan

This PR makes several improvements to completions and completion sorting:

1. Provide exact match type relevance score bonus for enum variants
2. Suggest `&Foo` (ref_match) for enums if that is an exact type match
3. Suggest `&foo()` (ref_match) if `foo` returns a type which would be an exact match either with the reference or due to a `Deref` impl

### Before

![pre-ref-relevance-centralized](https://user-images.githubusercontent.com/22216761/111189377-3f05a580-8573-11eb-89be-58a45cb7f829.png)

### After

![post-ref-relevance-centralized](https://user-images.githubusercontent.com/22216761/111189395-45941d00-8573-11eb-871b-09186b35cbb9.png)

### Caveats

I think generic types will require some kind of fancier logic when testing for `exact_type_match`, so for now `Option`/`Result`/etc unfortunately still don't have great completions.

### Implementation

I implemented this in a way that I think makes it most likely for each completion type to be handled consistently. Just replace `CompletionItem::new` with `CompletionItem::new_with_type_info` and `exact_type_match`/`exact_name_match`/`ref_match` are all handled for you, in a way which is sure to be consistent across completion types. 

This approach does introduce some coupling/plumbing that didn't exist before. Notice for example `set_is_local` on the builder, because `set_relevance` was removed from the builder to enforce that the relevance was built "properly" with `CompletionItem::new_with_type_info`. But I think there are benefits to this approach, like `CompletionRelevance` should probably consider deprecation status, and we already tell the builder about that, so in the (likely near term) future we can just pass that information along to `CompletionRelevance` when the user calls `set_deprecated` rather than the user having to manually set it in two places. This basically just hides `CompletionRelevance` from the individual completions, so they only worry about the `CompletionItem` interface. At the moment this seems like a cleaner approach to me, but I'm open to feedback here. 

edit - I've reimplemented this in a simpler way, per feedback below.

8046: Prefer match to if let else r=matklad a=matklad

bors r+
🤖

Co-authored-by: Josh Mcguigan <joshmcg88@gmail.com>
Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2021-03-16 07:57:33 +00:00
Aleksey Kladov
30dea3a727 Prefer match to if let else 2021-03-16 10:51:05 +03:00
bors[bot]
5fa26d05fb
Merge #8045
8045: Increase fetch-depth to make `git describe` work r=lnicola a=lnicola

bors r+

Co-authored-by: Laurențiu Nicola <lnicola@dend.ro>
2021-03-16 07:50:04 +00:00
Laurențiu Nicola
b51dfe3e82 Increase fetch-depth to make git describe work 2021-03-16 09:49:32 +02:00
bors[bot]
8b4075ff1c
Merge #8040
8040: 7709: Added the check for return type of len function. r=Veykril a=chetankhilosiya



Co-authored-by: Chetan Khilosiya <chetan.khilosiya@gmail.com>
2021-03-16 07:41:58 +00:00
bors[bot]
152f385055
Merge #8044
8044: Fix macro expansion for statements w/o semicolon r=edwin0cheng a=edwin0cheng

Fixes  #7845

And up `ungrammer` to  1.12.

cc @jonas-schievink 

bors r+

Co-authored-by: Edwin Cheng <edwin0cheng@gmail.com>
2021-03-16 05:48:05 +00:00
Edwin Cheng
8e07b23b84 Fix macro expansion for statements w/o semicolon 2021-03-16 13:44:50 +08:00
Josh Mcguigan
405bbb3aa4 completions: centralize calculation of relevance and ref matches 2021-03-15 19:40:42 -07:00
Chetan Khilosiya
847ec9e840 7709: Import changes. 2021-03-16 01:58:21 +05:30
Chetan Khilosiya
714836959b 7709: Added the check for return type of len function. 2021-03-16 01:16:59 +05:30
bors[bot]
c0a2b4e826
Merge #8039
8039: Use SmallVec for Substs r=flodiebold a=flodiebold

Doesn't help as much as I hoped, but it helps a bit and I also did some
refactorings that were necessary anyway.

Co-authored-by: Florian Diebold <flodiebold@gmail.com>
2021-03-15 18:49:07 +00:00
Florian Diebold
455e755bb0 Use SmallVec for Substs
Doesn't help as much as I hoped, but it helps a bit and I also did some
refactorings that were necessary anyway.
2021-03-15 19:48:03 +01:00
bors[bot]
47b74cadf9
Merge #7970
7970: Fix incorrect diagnostics for failing built in macros r=jonas-schievink a=brandondong

**Reproduction:**
1. Use a built in macro in such a way that rust-analyzer fails to expand it. For example:

**lib.rs**
```
include!("<valid file but without a .rs extension so it is not indexed by rust-analyzer>");
```
2. rust-analyzer highlights the macro call and says the macro itself cannot be resolved even though include! is in the standard library (unresolved-macro-call diagnostic).
3. No macro-error diagnostic is raised.

**Root cause for incorrect unresolved-macro-call diagnostic:**
1. collector:collect_macro_call is able to resolve include! in legacy scope but the expansion fails. Therefore, it's pushed into unexpanded_macros to be retried with module scope.
2. include! fails at the resolution step in collector:resolve_macros now that it's using module scope. Therefore, it's retained in unexpanded_macros.
3. Finally, collector:finish tries resolving the remaining unexpanded macros but only with module scope. include! again fails at the resolution step so a diagnostic is created.

**Root cause for missing macro-error diagnostic:**
1. In collector:resolve_macros, directive.legacy is None since eager expansion failed in collector:collect_macro_call. The macro_call_as_call_id fails to resolve since we're retrying in module scope. Therefore, collect_macro_expansion is not called for the macro and no macro-error diagnostic is generated.

**Fix:**
- In collector:collect_macro_call, do not add failing built-in macros to the unexpanded_macros list and immediately raise the macro-error diagnostic. This is in contrast to lazy macros which are resolved in collector::resolve_macros and later expanded in collect_macro_expansion where a macro-error diagnostic may be raised.

Co-authored-by: Brandon <brandondong604@hotmail.com>
Co-authored-by: brandondong <brandondong604@hotmail.com>
2021-03-15 18:24:22 +00:00
brandondong
ebb10da563
Update crates/hir_def/src/nameres/collector.rs
Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
2021-03-15 11:16:58 -07:00
bors[bot]
e24453c5ee
Merge #8038
8038: Fix unification logic r=flodiebold a=flodiebold



Co-authored-by: Florian Diebold <flodiebold@gmail.com>
2021-03-15 18:14:49 +00:00
Florian Diebold
287e9a870c Fix unification logic 2021-03-15 19:14:10 +01:00
bors[bot]
d38fd77845
Merge #8028
8028: Return multiple modules in `parent_module` feature r=matklad a=Veykril



Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-03-15 17:50:20 +00:00
bors[bot]
1f28345b37
Merge #8037
8037: Assist is empty 7709 r=Veykril a=chetankhilosiya

Updated the implementation to get the function from implementation

Co-authored-by: Chetan Khilosiya <chetan.khilosiya@gmail.com>
2021-03-15 17:40:14 +00:00
oxalica
455b418263
Update tests 2021-03-16 01:24:26 +08:00
oxalica
73fc05fdca
Pretty print root module of extern crates 2021-03-16 01:24:21 +08:00
Chetan Khilosiya
0c2d4a8a77 7709: Updated the implementation.
The get function from impl method is updated.
and now same method used to get len and is_empty function.
2021-03-15 22:48:50 +05:30
oxalica
7c855c940a
Clean usage of ShortLabel 2021-03-16 01:05:56 +08:00
oxalica
7101bada0f
Fix trait type parameter 2021-03-16 01:04:33 +08:00
oxalica
87171238c6
Use hir formatter more 2021-03-16 01:04:33 +08:00
oxalica
ef416e0154
Impl HirDisplay for function hover message 2021-03-16 01:04:20 +08:00
oxalica
2bb8956a10
Introduce FunctionQualifier for hir::FunctionData 2021-03-16 01:03:07 +08:00
oxalica
b9c172a977
Collect HirDisplay impls to a single file 2021-03-16 01:02:33 +08:00
oxalica
ef48d1ca3b
Add test for hover of macro expanded function 2021-03-16 01:01:24 +08:00
bors[bot]
ce3125165a
Merge #8035
8035: unqualfied_path completions aren't responsible for variant pattern completions r=Veykril a=Veykril

bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-03-15 16:51:53 +00:00
Lukas Wirth
4a0ab832f3 unqualfied_path completions aren't responsible for pattern completions 2021-03-15 17:23:08 +01:00
Chetan Khilosiya
2bf3802f21 7709: Added the assist to generate is_empty function
the assist will be shown when the len function is implemented.
is_empty internally uses len function.
2021-03-15 21:31:52 +05:30
bors[bot]
eec64ec01b
Merge #7992
7992: improved completion sorting for functions and methods r=JoshMcguigan a=JoshMcguigan

This PR improves completion sorting for functions and methods. Related to #7935.

### Before

The methods are being sorted by `coc` by closeness in file. 

![pre-fn-relevance](https://user-images.githubusercontent.com/22216761/111018669-fe3d3f00-836e-11eb-9607-cc05af080a6a.png)

### After

Notice `bbb()` on top (type + name match), followed by `ddd()` (type match).

![image](https://user-images.githubusercontent.com/22216761/111018680-0e551e80-836f-11eb-94b1-c88336ecbc6e.png)


Co-authored-by: Josh Mcguigan <joshmcg88@gmail.com>
2021-03-15 15:53:15 +00:00
bors[bot]
b8a85e9603
Merge #8033
8033: Add test for proc-macro meta info retrieval r=edwin0cheng a=edwin0cheng

bors r+

Co-authored-by: Edwin Cheng <edwin0cheng@gmail.com>
2021-03-15 15:39:34 +00:00
Edwin Cheng
a8c9c88292 Add test for proc-macro meta info retrieval 2021-03-15 23:38:22 +08:00
Josh Mcguigan
db8bcf132c implement function completion scoring 2021-03-15 08:35:28 -07:00
bors[bot]
106a5abbef
Merge #8032
8032: Enable proc-macros by default r=matklad a=matklad

bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2021-03-15 15:21:42 +00:00
Aleksey Kladov
469b739c28 Enable proc-macros by default 2021-03-15 18:19:08 +03:00
Lukas Wirth
f05fef7063 Support multiple parents in parentModule in vscode-client 2021-03-15 15:50:55 +01:00
bors[bot]
5f6d71cf0c
Merge #8029
8029: Enable thread-local coverage marks r=JoshMcguigan a=lnicola



Co-authored-by: Laurențiu Nicola <lnicola@dend.ro>
2021-03-15 14:42:26 +00:00
bors[bot]
633637b8ba
Merge #8030
8030: Add diesel to the benchmark suite r=lnicola a=weiznich

This commit adds diesel to the continuosly run benchmark suite. Diesel
heavily relies internally on macro generated code. Additionally there
are lots of complicated trait releations used as part of their API.
Therefore this benchmark will be quite sensitive to:
* Performance related changes in the macro expanding code
* Performance related changes while resolving trait bounds

CC #7950


cc @lnicola 

Co-authored-by: Georg Semmler <github@weiznich.de>
2021-03-15 14:34:23 +00:00
Georg Semmler
aa6db3f36a
Add diesel to the benchmark suite
This commit adds diesel to the continuosly run benchmark suite. Diesel
heavily relies internally on macro generated code. Additionally there
are lots of complicated trait releations used as part of their API.
Therefore this benchmark will be quite sensitive to:
* Performance related changes in the macro expanding code
* Performance related changes while resolving trait bounds

CC #7950
2021-03-15 15:19:16 +01:00
Lukas Wirth
2e3c156b0e Return multiple modules in parent_module 2021-03-15 15:15:40 +01:00
bors[bot]
f2c39d0cdf
Merge #8020
8020: Power up goto_implementation r=matklad a=Veykril

by allowing it to be invoked on references of names, now showing all (trait)
implementations of the given type in all crates instead of just the defining
crate as well as including support for builtin types

![image](https://user-images.githubusercontent.com/3757771/111144403-52bb0700-8587-11eb-9205-7a2a5b8b75a3.png)
Example screenshot of `impl`s of Box in `log`, `alloc`, `std` and the current crate. Before you had to invoke it on the definition where it would only show the `impls` in `alloc`.

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-03-15 14:08:26 +00:00
Laurențiu Nicola
e941cb0238 Drop non-working mark 2021-03-15 16:05:16 +02:00
Laurențiu Nicola
88cee24c6c Enable thread-local coverage marks 2021-03-15 16:02:50 +02:00
bors[bot]
3962b0d53c
Merge #8027
8027: Completion context remove exact match method in favor of fields r=JoshMcguigan a=JoshMcguigan

This is a minor cleanup PR following #8008. It removes the `expected_name_and_type` method on completion context in favor of using the fields. 

I thought this method was used in more places, or else it may have just made sense to make this change directly in #8008 🤷 

Co-authored-by: Josh Mcguigan <joshmcg88@gmail.com>
2021-03-15 13:42:12 +00:00
Lukas Wirth
79561b9d2e goto_implementation: Look at the entire crate graph for trait impls 2021-03-15 14:31:55 +01:00
Josh Mcguigan
67d59aeb7c remove expected_name_and_type method on completion context in favor of using fields added in #8008 2021-03-15 06:25:39 -07:00
bors[bot]
b245e8d115
Merge #8015
8015:  Introduce Semantics::visit_file_defs r=matklad a=Veykril

See https://github.com/rust-analyzer/rust-analyzer/issues/3538#issuecomment-798920601

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-03-15 13:18:26 +00:00