rust/crates/hir_def/src
bors[bot] c518fe7f6c
Merge #6130 #6135
6130: Items case quick fix (snake_case / UPPER_SNAKE_CASE / CamelCase) r=matklad a=popzxc

Resolves #4598.

After a third try, it finally works. Boy, it appeared tougher than it seemed.

Initially I thought like "Ha, `rustc` already tells us where idents are named incorrectly. It shouldn't be that hard, should it?".

Well, the problems with the information provided by `rustc` appeared shortly:

- `rustc` warnings are `flycheck` warnings, which are slightly aside from our diagnostics with fixes.
  When we map flycheck diagnostic to LSP, we can convert it into a fix, but only if it's marked as `Applicability::MachineApplicable`.
  Name case fix is marked `Applicability::MaybeIncorrect`, and for a reason: it only suggest to rename symbol under cursor, without tracking any references.
- Warning spawned by `rustc` are identified by string labels rather than enum. It means that if one day the diagnostic will be renamed in `rustc`, `rust-analyzer` code will still compile, but won't find the required diagnostic by name anymore. If by chance this will happen when some unlucky guy will decide to create their first pull request, they'll be confused by suddenly failing tests  (likely) not related to their changes.
- Even if we'll try to build fixes atop of `rustc` warnings, we'll have to do it in the `rust_analyzer::diagnostics::to_proto` module, which is far less
  convenient for that matter than `ide` crate.

That's why I decided that it's worth a separate `rust-analyzer` diagnostic, which will implement `DiagnosticWithFix` trait.

After that, I discovered that currently `hir_ty::diagnostics` only check `DefWithBody` types, like function bodies. I had to add support for diagnostics
which look at any `ModuleDef`.

And of course, since I'd added a lot of new functionality, it required extensive testing.

That explains why the diff is so big for a (looking) relatively small feature.

I hope that this PR doesn't only add a small feature, but also creates a base for building another features.

## Example:

![case_quick_fix](https://user-images.githubusercontent.com/12111581/95008475-e07ee780-0622-11eb-9978-62a9ea0e7782.gif)

P.S. My eyes were bleeding when I had to write the code for the example...


6135: when generating new function, focus on return type instead of body r=matklad a=bnjjj

I made a little change when we use the assist to generate a new function, instead of focusing on the function body, it will focus on return type

Co-authored-by: Igor Aleksanov <popzxc@yandex.ru>
Co-authored-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
2020-10-12 16:00:13 +00:00
..
body Fix mut self not emitting mutable binding on self use 2020-10-11 18:39:03 +02:00
item_tree Remove previously added parameter names from the function data 2020-10-12 11:05:00 +03:00
nameres Account for proc macro helpers when parsing attr 2020-10-05 23:41:16 +02:00
path Rename ra_hir_def -> hir_def 2020-08-13 16:29:33 +02:00
adt.rs adt: correctly inherit field visibility from enum 2020-10-09 20:46:45 +02:00
attr.rs Remove incorrect docs 2020-09-18 18:09:47 +02:00
body.rs Rename ra_hir_def -> hir_def 2020-08-13 16:29:33 +02:00
builtin_type.rs Rename ra_hir_def -> hir_def 2020-08-13 16:29:33 +02:00
child_by_source.rs Rename ra_hir_def -> hir_def 2020-08-13 16:29:33 +02:00
data.rs Remove previously added parameter names from the function data 2020-10-12 11:05:00 +03:00
db.rs Rename ra_hir_def -> hir_def 2020-08-13 16:29:33 +02:00
diagnostics.rs Mark unresolved imports diagnostic as experimental 2020-09-28 12:45:20 +02:00
docs.rs Rename ra_hir_def -> hir_def 2020-08-13 16:29:33 +02:00
dyn_map.rs Rename ra_hir_def -> hir_def 2020-08-13 16:29:33 +02:00
expr.rs Merge #5971 2020-09-13 17:28:22 +00:00
find_path.rs Add test makr 2020-10-06 19:20:56 +02:00
generics.rs Rename ra_hir_def -> hir_def 2020-08-13 16:29:33 +02:00
import_map.rs Constrain ImportMap to only store simple paths 2020-10-06 17:04:29 +02:00
item_scope.rs Make incorrect case diagnostic work inside of functions 2020-10-12 11:05:00 +03:00
item_tree.rs Remove previously added parameter names from the function data 2020-10-12 11:05:00 +03:00
keys.rs Rename ra_hir_def -> hir_def 2020-08-13 16:29:33 +02:00
lang_item.rs Rename ra_hir_def -> hir_def 2020-08-13 16:29:33 +02:00
lib.rs Rename ra_hir_def -> hir_def 2020-08-13 16:29:33 +02:00
nameres.rs Properly name the field 2020-10-02 21:38:22 +03:00
path.rs Move ModPath->ast::Path function to IDE layer 2020-10-06 16:19:18 +02:00
per_ns.rs Rename ra_hir_def -> hir_def 2020-08-13 16:29:33 +02:00
resolver.rs Rename ra_hir_def -> hir_def 2020-08-13 16:29:33 +02:00
src.rs Rename ra_hir_def -> hir_def 2020-08-13 16:29:33 +02:00
test_db.rs Add annotation-based nameres diagnostic tests 2020-09-16 17:26:51 +02:00
trace.rs Rename ra_hir_def -> hir_def 2020-08-13 16:29:33 +02:00
type_ref.rs Rename ra_hir_def -> hir_def 2020-08-13 16:29:33 +02:00
visibility.rs Rename ra_hir_def -> hir_def 2020-08-13 16:29:33 +02:00