diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ide_db/src/helpers/insert_use.rs | 16 | ||||
-rw-r--r-- | crates/rust-analyzer/src/config.rs | 6 |
2 files changed, 8 insertions, 14 deletions
diff --git a/crates/ide_db/src/helpers/insert_use.rs b/crates/ide_db/src/helpers/insert_use.rs index 4852121a1..1fdd110cc 100644 --- a/crates/ide_db/src/helpers/insert_use.rs +++ b/crates/ide_db/src/helpers/insert_use.rs | |||
@@ -18,6 +18,8 @@ pub use hir::PrefixKind; | |||
18 | /// How imports should be grouped into use statements. | 18 | /// How imports should be grouped into use statements. |
19 | #[derive(Copy, Clone, Debug, PartialEq, Eq)] | 19 | #[derive(Copy, Clone, Debug, PartialEq, Eq)] |
20 | pub enum ImportGranularity { | 20 | pub enum ImportGranularity { |
21 | /// Try to guess the granularity of imports on a per module basis by observing the existing imports. | ||
22 | Guess, | ||
21 | /// Do not change the granularity of any imports and preserve the original structure written by the developer. | 23 | /// Do not change the granularity of any imports and preserve the original structure written by the developer. |
22 | Preserve, | 24 | Preserve, |
23 | /// Merge imports from the same crate into a single use statement. | 25 | /// Merge imports from the same crate into a single use statement. |
@@ -28,16 +30,6 @@ pub enum ImportGranularity { | |||
28 | Item, | 30 | Item, |
29 | } | 31 | } |
30 | 32 | ||
31 | impl ImportGranularity { | ||
32 | pub fn merge_behavior(self) -> Option<MergeBehavior> { | ||
33 | match self { | ||
34 | ImportGranularity::Crate => Some(MergeBehavior::Crate), | ||
35 | ImportGranularity::Module => Some(MergeBehavior::Module), | ||
36 | ImportGranularity::Preserve | ImportGranularity::Item => None, | ||
37 | } | ||
38 | } | ||
39 | } | ||
40 | |||
41 | #[derive(Clone, Copy, Debug, PartialEq, Eq)] | 33 | #[derive(Clone, Copy, Debug, PartialEq, Eq)] |
42 | pub struct InsertUseConfig { | 34 | pub struct InsertUseConfig { |
43 | pub granularity: ImportGranularity, | 35 | pub granularity: ImportGranularity, |
@@ -118,10 +110,10 @@ impl ImportScope { | |||
118 | pub fn insert_use<'a>(scope: &ImportScope, path: ast::Path, cfg: InsertUseConfig) { | 110 | pub fn insert_use<'a>(scope: &ImportScope, path: ast::Path, cfg: InsertUseConfig) { |
119 | let _p = profile::span("insert_use"); | 111 | let _p = profile::span("insert_use"); |
120 | let mb = match cfg.granularity { | 112 | let mb = match cfg.granularity { |
121 | ImportGranularity::Preserve => scope.guess_merge_behavior_from_scope(), | 113 | ImportGranularity::Guess => scope.guess_merge_behavior_from_scope(), |
122 | ImportGranularity::Crate => Some(MergeBehavior::Crate), | 114 | ImportGranularity::Crate => Some(MergeBehavior::Crate), |
123 | ImportGranularity::Module => Some(MergeBehavior::Module), | 115 | ImportGranularity::Module => Some(MergeBehavior::Module), |
124 | ImportGranularity::Item => None, | 116 | ImportGranularity::Item | ImportGranularity::Preserve => None, |
125 | }; | 117 | }; |
126 | 118 | ||
127 | let use_item = | 119 | let use_item = |
diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs index e72387257..a34ca97ac 100644 --- a/crates/rust-analyzer/src/config.rs +++ b/crates/rust-analyzer/src/config.rs | |||
@@ -36,7 +36,7 @@ config_data! { | |||
36 | /// The strategy to use when inserting new imports or merging imports. | 36 | /// The strategy to use when inserting new imports or merging imports. |
37 | assist_importGranularity | | 37 | assist_importGranularity | |
38 | assist_importMergeBehavior | | 38 | assist_importMergeBehavior | |
39 | assist_importMergeBehaviour: ImportGranularityDef = "\"preserve\"", | 39 | assist_importMergeBehaviour: ImportGranularityDef = "\"guess\"", |
40 | /// The path structure for newly inserted paths to use. | 40 | /// The path structure for newly inserted paths to use. |
41 | assist_importPrefix: ImportPrefixDef = "\"plain\"", | 41 | assist_importPrefix: ImportPrefixDef = "\"plain\"", |
42 | /// Group inserted imports by the [following order](https://rust-analyzer.github.io/manual.html#auto-import). Groups are separated by newlines. | 42 | /// Group inserted imports by the [following order](https://rust-analyzer.github.io/manual.html#auto-import). Groups are separated by newlines. |
@@ -610,6 +610,7 @@ impl Config { | |||
610 | fn insert_use_config(&self) -> InsertUseConfig { | 610 | fn insert_use_config(&self) -> InsertUseConfig { |
611 | InsertUseConfig { | 611 | InsertUseConfig { |
612 | granularity: match self.data.assist_importGranularity { | 612 | granularity: match self.data.assist_importGranularity { |
613 | ImportGranularityDef::Guess => ImportGranularity::Guess, | ||
613 | ImportGranularityDef::Preserve => ImportGranularity::Preserve, | 614 | ImportGranularityDef::Preserve => ImportGranularity::Preserve, |
614 | ImportGranularityDef::Item => ImportGranularity::Item, | 615 | ImportGranularityDef::Item => ImportGranularity::Item, |
615 | ImportGranularityDef::Crate => ImportGranularity::Crate, | 616 | ImportGranularityDef::Crate => ImportGranularity::Crate, |
@@ -719,9 +720,10 @@ enum ManifestOrProjectJson { | |||
719 | #[derive(Deserialize, Debug, Clone)] | 720 | #[derive(Deserialize, Debug, Clone)] |
720 | #[serde(rename_all = "snake_case")] | 721 | #[serde(rename_all = "snake_case")] |
721 | enum ImportGranularityDef { | 722 | enum ImportGranularityDef { |
723 | Preserve, | ||
724 | Guess, | ||
722 | #[serde(alias = "none")] | 725 | #[serde(alias = "none")] |
723 | Item, | 726 | Item, |
724 | Preserve, | ||
725 | #[serde(alias = "full")] | 727 | #[serde(alias = "full")] |
726 | Crate, | 728 | Crate, |
727 | #[serde(alias = "last")] | 729 | #[serde(alias = "last")] |