rust/crates
bors[bot] 9dfa69a44a
Merge #5935
5935: Rewrite import insertion r=matklad a=Veykril

This is my attempt at refactoring the import insertion #3947. I hope what I created here is somewhat in line with what was requested, it wouldn't surprise me .

`common_prefix` is a copy from `merge_imports.rs` so those should be unified somewhere, `try_merge_trees` is also copied from there but slighly modified to take the `MergeBehaviour` enum into account.
`MergeBehaviour` should in the end become a configuration option, and the order if `ImportGroup` probably as well?

I'm not too familiar with the assist stuff and the like which is why I dont know what i have to do with `insert_use_statement` and `find_insert_use_container` for now.

I will most likely add more test cases in the end as well as I currently only tried to hit every path in `find_insert_position`. 
Some of the merge tests also fail atm due to them not sorting what they insert. There is also this test case I'm not sure if we want to support it. I would assume we want to? https://github.com/rust-analyzer/rust-analyzer/pull/5935/files#diff-6923916dd8bdd2f1ab4b984adacd265fR540-R547

The entire module was rewritten so looking at the the file itself is probably better than looking at the diff.

Regarding the sub issues of #3947:
- #3301: This is fixed with the rewrite, what this implementation does is that it scans through the first occurence of groupings and picks the appropriate one out. This means the user can actually rearrange the groupings on a per file basis to their liking. If a group isnt being found it is inserted according to the `ImportGroup` variant order(Would be nice if this was configurable I imagine).
- #3831: This should be fixed with the introduced `MergeBehaviour` enum and it's `Last` variant.
- #3946: This should also be [fixed](https://github.com/rust-analyzer/rust-analyzer/pull/5935/files#diff-6923916dd8bdd2f1ab4b984adacd265fR87)
- #5795: This is fixed in the sense that the grouping search picks the first group that is of the same kind as the import that is being added. So if  there is a random import in the middle of the program it should only be considered if there is no group of the same kind in the file already present.
- the last point in the list I havent checked yet, tho I got the feeling that it's not gonna be too simple as that will require knowledge of whether in this example `ast` is a crate or the module that is already imported.

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2020-09-04 13:28:05 +00:00
..
arena Add TBD description to arena 2020-08-24 13:29:10 +02:00
assists Add extra insert_use test for pub(crate) re-export handling 2020-09-03 20:26:27 +02:00
base_db Add description for crates that will be published 2020-08-24 13:07:22 +02:00
cfg Add description for crates that will be published 2020-08-24 13:07:22 +02:00
flycheck Add description for crates that will be published 2020-08-24 13:07:22 +02:00
hir Tease apart orthogonal concerns in markdown link rewriting 2020-08-26 20:24:00 +02:00
hir_def ⬆️ expect-test 2020-08-28 14:47:14 +02:00
hir_expand Bump token expansion limit 2020-09-01 14:55:41 +02:00
hir_ty Chalk 0.25 2020-09-02 14:07:06 -04:00
ide Document VS Code setting needed for on-typing assists 2020-09-01 23:40:53 +10:00
ide_db Add description for crates that will be published 2020-08-24 13:07:22 +02:00
mbe Add description for crates that will be published 2020-08-24 13:07:22 +02:00
parser Up proc-macro2 to 1.20 2020-09-03 17:40:12 -04:00
paths Add description for crates that will be published 2020-08-24 13:07:22 +02:00
proc_macro_api Add description for crates that will be published 2020-08-24 13:07:22 +02:00
proc_macro_srv Add description for crates that will be published 2020-08-24 13:07:22 +02:00
proc_macro_test Add description for crates that will be published 2020-08-24 13:07:22 +02:00
profile Add description for crates that will be published 2020-08-24 13:07:22 +02:00
project_model Add sysroot shortcut to rust-project.json 2020-08-25 19:41:56 +02:00
rust-analyzer default checkOnSave.enable to true in server 2020-09-02 17:44:21 -04:00
ssr ⬆️ expect-test 2020-08-28 14:47:14 +02:00
stdx Add description for crates that will be published 2020-08-24 13:07:22 +02:00
syntax Impl make::blank_line 2020-09-03 18:36:07 +02:00
test_utils Add description for crates that will be published 2020-08-24 13:07:22 +02:00
text_edit Actually assert disjointness 2020-09-03 13:37:36 +02:00
toolchain Add description for crates that will be published 2020-08-24 13:07:22 +02:00
tt Add description for crates that will be published 2020-08-24 13:07:22 +02:00
vfs Add description for crates that will be published 2020-08-24 13:07:22 +02:00
vfs-notify Add description for crates that will be published 2020-08-24 13:07:22 +02:00