rust/crates
bors[bot] 4f9506416c
Merge #2887
2887: Initial auto import action implementation r=matklad a=SomeoneToIgnore

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

Adds an auto import action implementation.

This implementation is not ideal and has a few limitations:

* The import search functionality should be moved into a separate crate accessible from ra_assists.
This requires a lot of changes and a preliminary design. 
Currently the functionality is provided as a trait impl, more on that here: https://github.com/rust-analyzer/rust-analyzer/issues/2180#issuecomment-575690942

* Due to the design desicion from the previous item, no doctests are run for the new aciton (look for a new FIXME in the PR)

* For the same reason, I have to create the mock trait implementaion to test the assist

* Ideally, I think we should have this feature as a diagnostics (that detects an absense of an import) that has a corresponding quickfix action that gets evaluated on demand.
Curretly we perform the import search every time we resolve the import which looks suboptimal.
This requires `classify_name_ref` to be moved from ra_ide, so not done currently.

A few improvements to the imports mechanism to be considered later:

* Constants like `ra_syntax::SyntaxKind::NAME` are not imported, because they are not present in the database

* Method usages are not imported, they are found in the database, but `find_use_path` does not return any import paths for them

* Some import paths returned by the `find_use_path` method end up in `core::` or `alloc::` instead of `std:`, for example: `core::fmt::Debug` instead of `std::fmt::Debug`.
This is not an error techically, but still looks weird.

* No detection of cases where a trait should be imported in order to be able to call a method

* Improve `auto_import_text_edit` functionality: refactor it and move away from the place it is now, add better logic for merging the new import with already existing imports

Co-authored-by: Kirill Bulatov <mail4score@gmail.com>
2020-01-27 13:04:53 +00:00
..
ra_arena Switch to variant-granularity field type inference 2019-11-25 00:12:36 +03:00
ra_assists Code review fixes 2020-01-27 14:42:45 +02:00
ra_batch Support setting cargo features 2019-12-13 18:16:34 +08:00
ra_cargo_watch Move snaps to new naming scheme 2020-01-26 13:29:01 -05:00
ra_cfg Disable doctests 2019-11-17 18:35:05 +03:00
ra_cli Disable env_logger humantime feature 2020-01-25 11:53:40 +01:00
ra_db Remove the Default impl for SourceRoot 2020-01-08 19:42:27 +01:00
ra_fmt fix 2190; add test for "replace if let with match" 2019-11-20 19:01:06 +01:00
ra_hir Code review fixes 2020-01-27 14:42:45 +02:00
ra_hir_def Update crates 2020-01-26 10:46:45 -05:00
ra_hir_expand Use dummy value for line! and column! macro 2020-01-15 01:47:01 +08:00
ra_hir_ty Update crates 2020-01-26 10:46:45 -05:00
ra_ide Merge #2887 2020-01-27 13:04:53 +00:00
ra_lsp_server Bump main thread priority on windows 2020-01-26 14:15:57 +01:00
ra_mbe Add details about test_repeat_bad_var current state 2019-12-30 17:12:20 +01:00
ra_parser ra_syntax: remove code duplication and token reevaluation from ast::Literal::kind() 2020-01-22 13:02:21 +02:00
ra_prof Add print_time helper 2020-01-25 11:59:11 +01:00
ra_project_model Address nit 2020-01-10 22:41:52 +01:00
ra_syntax Fixed a typo 2020-01-22 13:02:21 +02:00
ra_text_edit Disable doctests 2019-11-17 18:35:05 +03:00
ra_tt Refactoring 2019-12-18 13:10:37 +08:00
ra_vfs_glob Disable doctests 2019-11-17 18:35:05 +03:00
test_utils Refactor goto tests to always specify texts 2019-12-18 16:00:35 +01:00