Commit graph

59 commits

Author SHA1 Message Date
bors[bot]
3877421373
Merge #5989
5989: Rewrite import merging r=jonas-schievink a=Veykril

Rewrites how import merging is being handled. It is now a recursive function to properly handle merging of intermediate levels in the import trees. With this ordering the imports is also now possible tho it doesn't quite order it the same way as `rustfmt` does yet, namely it orders lowercase identifiers after uppercase identifiers as that is the standard character order that rust uses. This also fixes a few weird behaviors that were visible in some of the `replace_qualified_name_with_use.rs` tests.

This really took longer than I was hoping for, fighting with import trees is quite the exhausting task 😅 

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2020-09-16 20:03:41 +00:00
Lukas Wirth
45298b5d2a Add make::glob_use_tree function to create star-only UseTree 2020-09-16 20:33:08 +02:00
Lukas Wirth
b874721752 Fix merge imports failing if the self module import is in the wrong tree 2020-09-12 23:54:49 +02:00
Lukas Wirth
cd6cd91bf3 Tidy up recursive_merge implementation 2020-09-12 23:27:01 +02:00
Lukas Wirth
a898752881 Reimplement import merging by making it recursive properly nesting all levels 2020-09-12 19:19:19 +02:00
Lukas Wirth
adc4c6b9d7 Make MergeBehaviour configurable 2020-09-12 12:11:16 +02:00
Kirill Bulatov
779ea2ea0a Properly preserve macro braces 2020-09-11 22:16:22 +03:00
bors[bot]
568dc38b7b
Merge #5955
5955: Remove merge import code duplication r=jonas-schievink a=Veykril

This removes the code duplication caused by #5935, this also allows the assist to merge imports that have equal visibility and prevents merges of unequal visibility. This PR also fixes an iteration mistake in the mentioned PR:

Turns out I made a mistake when writing the `segment_iter` function, I was assuming that the `children` of a path will just be the segments, which is obviously not the case. This also brings insertion order of shorter paths in line with how `rustfmt` orders them.

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2020-09-11 14:01:20 +00:00
Kirill Bulatov
b477f99bd9 One more test 2020-09-11 00:20:13 +03:00
Kirill Bulatov
208d4609b0 Use better heuristics for replacement text when removing dbg! 2020-09-10 14:14:24 +03:00
Lukas Wirth
74b755d233 Allow merge_imports assists to merge imports of equal visibility 2020-09-05 16:15:16 +02:00
Lukas Wirth
7ccb198af8 Remove duplicated import merge logic 2020-09-05 15:51:26 +02:00
Lukas Wirth
d201317c67 Fix segment_iter not iterating segments properly 2020-09-05 15:44:54 +02:00
bors[bot]
0275b08d15
Merge #5940
5940: Implement "Replace `impl Trait` function argument with the named generic" assist. r=matklad a=alekseysidorov

Fixes #5085 

Co-authored-by: Aleksei Sidorov <gorthauer87@yandex.ru>
2020-09-04 21:54:42 +00:00
Aleksei Sidorov
e1b8d836a9 Remove unnecessary comma 2020-09-04 22:58:50 +03:00
Aleksei Sidorov
ef0a1b2e58 Fix tests 2020-09-04 17:55:27 +03:00
Aleksei Sidorov
a1c060c8d0 Update codegen 2020-09-04 15:28:08 +03:00
Aleksei Sidorov
477fa75cfb Fix nitpicks 2020-09-04 15:24:36 +03:00
Lukas Wirth
82f61e6629 Add extra insert_use test for pub(crate) re-export handling 2020-09-03 20:26:27 +02:00
Lukas Wirth
d29b69cbe6 Disable insert_import in extract_struct_from_enum_variant until its fixed 2020-09-03 18:36:08 +02:00
Lukas Wirth
7de2a30f40 Fix import insertion breaking nested modules 2020-09-03 18:36:08 +02:00
Lukas Wirth
98e2f674e9 Fix inserting imports in front of inner attributes 2020-09-03 18:36:08 +02:00
Lukas Wirth
c1925df7fc Replace insert_use_statement with the new insert_use 2020-09-03 18:36:08 +02:00
Lukas Wirth
952f385682 Impl make::blank_line 2020-09-03 18:36:07 +02:00
Lukas Wirth
07ff9eeca8 Use mark to check that paths that are too long will not be merged 2020-09-03 18:36:07 +02:00
Lukas Wirth
74186d3ae7 Tidy up tests and apply suggested changes 2020-09-03 18:36:07 +02:00
Lukas Wirth
903c7eb2e5 Add more import insertion tests 2020-09-03 18:36:07 +02:00
Lukas Wirth
ed37335c01 Begin refactor of import insertion 2020-09-03 18:36:07 +02:00
Aleksei Sidorov
7259cc82f3 Resolve most of corner cases 2020-09-03 17:46:04 +03:00
Aleksei Sidorov
fe3170dc34 Initial implementation of the #5085 issue 2020-09-03 14:47:07 +03:00
Aleksey Kladov
75b1f9ee23 Unify naming 2020-09-03 12:18:46 +02:00
Aleksey Kladov
b1f59ff6c1 Reduce path_from_text usage 2020-08-31 15:47:42 +02:00
Aleksey Kladov
0fc8fd2bd5 **Inline Variable** works with field shorthand 2020-08-26 13:03:14 +02:00
Aleksey Kladov
4f6ca0e081 Minor 2020-08-25 18:07:25 +02:00
Aleksey Kladov
7721accebf Cleanup invert-if
* stick to trivial factory functions in make
* compress the logic for inverting Option/Result
2020-08-25 11:00:32 +02:00
bors[bot]
81fa00c5b5
Merge #5733
5733: Fix expand glob import bugs r=matklad a=unexge

fixes https://github.com/rust-analyzer/rust-analyzer/issues/5709

TODOs:
- [x] Incorrect node replacing
<details>
    <summary>Details</summary>

```rust
use crate::{
    body::scope::{ExprScopes, ScopeId},
    body::Body,
    builtin_type::BuiltinType,
    db::DefDatabase,
    expr::{ExprId, PatId},
    generics::GenericParams,
    item_scope::{BuiltinShadowMode, BUILTIN_SCOPE},
    nameres::CrateDefMap,
    path::*<|>,
    per_ns::PerNs,
    visibility::{RawVisibility, Visibility},
    AdtId, AssocContainerId, ConstId, ContainerId, DefWithBodyId, EnumId, EnumVariantId,
    FunctionId, GenericDefId, HasModule, ImplId, LocalModuleId, Lookup, ModuleDefId, ModuleId,
    StaticId, StructId, TraitId, TypeAliasId, TypeParamId, VariantId,
};
```
becames
```rust
use crate::{PathKind, name, name, ModPath};
```
</details>

- [x] Ignoring visibility
<details>
    <summary>Details</summary>

```rust
mod foo {
    mod bar {
        pub struct Bar;
    }
}

use foo::bar::*;

fn baz(bar: Bar) {}
```
becames
```rust
mod foo {
    mod bar {
        pub struct Bar;
    }
}

use foo::bar::Bar;

fn baz(bar: Bar) {}
```
although mod `bar` is private
</details>

- [x] Eating attributes

Co-authored-by: unexge <unexge@gmail.com>
2020-08-24 14:26:33 +00:00
bors[bot]
31cb13dde8
Merge #4776
4776: Do a weekly minor publish to crates.io r=matklad a=pksunkara

This is the same system I set up on Chalk repo.

Every week it creates a new minor version, pushes it to github and then deploys it to crates.io.

Co-authored-by: Pavan Kumar Sunkara <pavan.sss1991@gmail.com>
2020-08-24 11:14:45 +00:00
Pavan Kumar Sunkara
335add49db Add description for crates that will be published 2020-08-24 13:07:22 +02:00
Pavan Kumar Sunkara
a8fa5cd42e Add version to deps in cargo.toml 2020-08-24 11:10:41 +02:00
dragfire
1d129a7172 Invert if should be smart about is_some, is_none, is_ok, is_err 2020-08-23 22:30:34 -06:00
Aleksey Kladov
863b1fb731 ⬆️ ungrammar 2020-08-21 19:14:05 +02:00
unexge
ef54e8451d Use new Definition::usages API in expand glob import 2020-08-20 21:35:47 +03:00
unexge
5cff4b60be Fix importing private modules in expand glob import 2020-08-20 21:34:53 +03:00
unexge
5d28dec7b9 Fix importing unused traits in expand glob import 2020-08-20 21:34:53 +03:00
unexge
585f5d4901 Use fixme instead of todo 2020-08-20 21:34:53 +03:00
unexge
0847bc801e Use Definition::find_usages for finding used items in expand glob import 2020-08-20 21:34:53 +03:00
unexge
11d048af03 Run rustfmt 2020-08-20 21:34:53 +03:00
unexge
bb72150f02 Handle more cases in AST replacing in expand glob import 2020-08-20 21:34:53 +03:00
unexge
128eef779f Improve AST replacing in expand glob import 2020-08-20 21:34:53 +03:00
Aleksey Kladov
4b5b55f6f3 **Remove Unused Parameter** refactoring 2020-08-19 19:40:55 +02:00