diff options
Diffstat (limited to 'crates/ide_assists')
-rw-r--r-- | crates/ide_assists/src/handlers/auto_import.rs | 17 | ||||
-rw-r--r-- | crates/ide_assists/src/handlers/merge_imports.rs | 14 | ||||
-rw-r--r-- | crates/ide_assists/src/tests.rs | 8 |
3 files changed, 28 insertions, 11 deletions
diff --git a/crates/ide_assists/src/handlers/auto_import.rs b/crates/ide_assists/src/handlers/auto_import.rs index dda5a6631..d4748ef3a 100644 --- a/crates/ide_assists/src/handlers/auto_import.rs +++ b/crates/ide_assists/src/handlers/auto_import.rs | |||
@@ -33,20 +33,19 @@ use crate::{AssistContext, AssistId, AssistKind, Assists, GroupLabel}; | |||
33 | // use super::AssistContext; | 33 | // use super::AssistContext; |
34 | // ``` | 34 | // ``` |
35 | // | 35 | // |
36 | // .Merge Behavior | 36 | // .Import Granularity |
37 | // | 37 | // |
38 | // It is possible to configure how use-trees are merged with the `importMergeBehavior` setting. | 38 | // It is possible to configure how use-trees are merged with the `importGranularity` setting. |
39 | // It has the following configurations: | 39 | // It has the following configurations: |
40 | // | 40 | // |
41 | // - `full`: This setting will cause auto-import to always completely merge use-trees that share the | 41 | // - `crate`: Merge imports from the same crate into a single use statement. This kind of |
42 | // same path prefix while also merging inner trees that share the same path-prefix. This kind of | ||
43 | // nesting is only supported in Rust versions later than 1.24. | 42 | // nesting is only supported in Rust versions later than 1.24. |
44 | // - `last`: This setting will cause auto-import to merge use-trees as long as the resulting tree | 43 | // - `module`: Merge imports from the same module into a single use statement. |
45 | // will only contain a nesting of single segment paths at the very end. | 44 | // - `item`: Don't merge imports at all, creating one import per item. |
46 | // - `none`: This setting will cause auto-import to never merge use-trees keeping them as simple | 45 | // - `preserve`: Do not change the granularity of any imports. For auto-import this has the same |
47 | // paths. | 46 | // effect as `item`. |
48 | // | 47 | // |
49 | // In `VS Code` the configuration for this is `rust-analyzer.assist.importMergeBehavior`. | 48 | // In `VS Code` the configuration for this is `rust-analyzer.assist.importGranularity`. |
50 | // | 49 | // |
51 | // .Import Prefix | 50 | // .Import Prefix |
52 | // | 51 | // |
diff --git a/crates/ide_assists/src/handlers/merge_imports.rs b/crates/ide_assists/src/handlers/merge_imports.rs index 31854840c..fc117bd9a 100644 --- a/crates/ide_assists/src/handlers/merge_imports.rs +++ b/crates/ide_assists/src/handlers/merge_imports.rs | |||
@@ -213,6 +213,20 @@ pub(crate) use std::fmt::{Debug, Display}; | |||
213 | } | 213 | } |
214 | 214 | ||
215 | #[test] | 215 | #[test] |
216 | fn merge_pub_in_path_crate() { | ||
217 | check_assist( | ||
218 | merge_imports, | ||
219 | r" | ||
220 | pub(in this::path) use std::fmt$0::Debug; | ||
221 | pub(in this::path) use std::fmt::Display; | ||
222 | ", | ||
223 | r" | ||
224 | pub(in this::path) use std::fmt::{Debug, Display}; | ||
225 | ", | ||
226 | ) | ||
227 | } | ||
228 | |||
229 | #[test] | ||
216 | fn test_merge_nested() { | 230 | fn test_merge_nested() { |
217 | check_assist( | 231 | check_assist( |
218 | merge_imports, | 232 | merge_imports, |
diff --git a/crates/ide_assists/src/tests.rs b/crates/ide_assists/src/tests.rs index b091ab91a..6a9231e07 100644 --- a/crates/ide_assists/src/tests.rs +++ b/crates/ide_assists/src/tests.rs | |||
@@ -4,7 +4,10 @@ use expect_test::expect; | |||
4 | use hir::Semantics; | 4 | use hir::Semantics; |
5 | use ide_db::{ | 5 | use ide_db::{ |
6 | base_db::{fixture::WithFixture, FileId, FileRange, SourceDatabaseExt}, | 6 | base_db::{fixture::WithFixture, FileId, FileRange, SourceDatabaseExt}, |
7 | helpers::{insert_use::InsertUseConfig, merge_imports::MergeBehavior, SnippetCap}, | 7 | helpers::{ |
8 | insert_use::{ImportGranularity, InsertUseConfig}, | ||
9 | SnippetCap, | ||
10 | }, | ||
8 | source_change::FileSystemEdit, | 11 | source_change::FileSystemEdit, |
9 | RootDatabase, | 12 | RootDatabase, |
10 | }; | 13 | }; |
@@ -21,8 +24,9 @@ pub(crate) const TEST_CONFIG: AssistConfig = AssistConfig { | |||
21 | snippet_cap: SnippetCap::new(true), | 24 | snippet_cap: SnippetCap::new(true), |
22 | allowed: None, | 25 | allowed: None, |
23 | insert_use: InsertUseConfig { | 26 | insert_use: InsertUseConfig { |
24 | merge: Some(MergeBehavior::Crate), | 27 | granularity: ImportGranularity::Crate, |
25 | prefix_kind: hir::PrefixKind::Plain, | 28 | prefix_kind: hir::PrefixKind::Plain, |
29 | enforce_granularity: true, | ||
26 | group: true, | 30 | group: true, |
27 | }, | 31 | }, |
28 | }; | 32 | }; |