rust-analyzer/crates
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
..
base_db Fixed remaining references to AnalysisChange (now: Change) 2021-02-28 12:57:41 +01:00
cfg Add runnables::related_tests 2021-02-27 18:00:17 +03:00
flycheck Bump cargo_metadata 2021-03-02 14:27:29 +02:00
hir 7709: Import changes. 2021-03-16 01:58:21 +05:30
hir_def Fix macro expansion for statements w/o semicolon 2021-03-16 13:44:50 +08:00
hir_expand Fix macro expansion for statements w/o semicolon 2021-03-16 13:44:50 +08:00
hir_ty Fix macro expansion for statements w/o semicolon 2021-03-16 13:44:50 +08:00
ide Merge #8028 2021-03-15 17:50:20 +00:00
ide_assists 7709: Added the check for return type of len function. 2021-03-16 01:16:59 +05:30
ide_completion completions: centralize calculation of relevance and ref matches 2021-03-15 19:40:42 -07:00
ide_db Enable thread-local coverage marks 2021-03-15 16:02:50 +02:00
ide_ssr Enable thread-local coverage marks 2021-03-15 16:02:50 +02:00
mbe Fix macro expansion for statements w/o semicolon 2021-03-16 13:44:50 +08:00
parser Fix macro expansion for statements w/o semicolon 2021-03-16 13:44:50 +08:00
paths Document paths items 2021-01-22 15:38:33 +01:00
proc_macro_api Add test for proc-macro meta info retrieval 2021-03-15 23:38:22 +08:00
proc_macro_srv Add test for proc-macro meta info retrieval 2021-03-15 23:38:22 +08:00
proc_macro_test
profile add more counts 2021-01-27 12:39:19 +03:00
project_model some clippy::performance fixes 2021-03-15 10:19:59 +01:00
rust-analyzer Enable proc-macros by default 2021-03-15 18:19:08 +03:00
stdx Cleanup decl_check 2021-02-05 16:09:45 +01:00
syntax Fix macro expansion for statements w/o semicolon 2021-03-16 13:44:50 +08:00
test_utils Use upstream cov-mark 2021-03-08 22:19:44 +02:00
text_edit Avoid turning completion objects into builders 2020-11-16 23:16:41 +02:00
toolchain
tt add expand log 2021-03-13 20:14:21 +08:00
vfs Fix slow tests sometimes failing 2021-02-12 16:31:16 +01:00
vfs-notify Fix slow tests sometimes failing 2021-02-12 16:31:16 +01:00