aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/ide_db/src/helpers/insert_use.rs16
-rw-r--r--crates/rust-analyzer/src/config.rs6
-rw-r--r--editors/code/package.json4
3 files changed, 11 insertions, 15 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)]
20pub enum ImportGranularity { 20pub 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
31impl 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)]
42pub struct InsertUseConfig { 34pub struct InsertUseConfig {
43 pub granularity: ImportGranularity, 35 pub granularity: ImportGranularity,
@@ -118,10 +110,10 @@ impl ImportScope {
118pub fn insert_use<'a>(scope: &ImportScope, path: ast::Path, cfg: InsertUseConfig) { 110pub 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")]
721enum ImportGranularityDef { 722enum 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")]
diff --git a/editors/code/package.json b/editors/code/package.json
index 81179ff9b..06ce86987 100644
--- a/editors/code/package.json
+++ b/editors/code/package.json
@@ -387,15 +387,17 @@
387 "$generated-start": false, 387 "$generated-start": false,
388 "rust-analyzer.assist.importGranularity": { 388 "rust-analyzer.assist.importGranularity": {
389 "markdownDescription": "How imports should be grouped into use statements.", 389 "markdownDescription": "How imports should be grouped into use statements.",
390 "default": "preserve", 390 "default": "guess",
391 "type": "string", 391 "type": "string",
392 "enum": [ 392 "enum": [
393 "guess",
393 "preserve", 394 "preserve",
394 "crate", 395 "crate",
395 "module", 396 "module",
396 "item" 397 "item"
397 ], 398 ],
398 "enumDescriptions": [ 399 "enumDescriptions": [
400 "Try to guess the granularity of imports on a per module basis by observing the existing imports.",
399 "Do not change the granularity of any imports and preserve the original structure written by the developer.", 401 "Do not change the granularity of any imports and preserve the original structure written by the developer.",
400 "Merge imports from the same crate into a single use statement. Conversely, imports from different crates are split into separate statements.", 402 "Merge imports from the same crate into a single use statement. Conversely, imports from different crates are split into separate statements.",
401 "Merge imports from the same module into a single use statement. Conversely, imports from different modules are split into separate statements.", 403 "Merge imports from the same module into a single use statement. Conversely, imports from different modules are split into separate statements.",