Unnamed repository; edit this file 'description' to name the repository.
update import granularity config and docs
davidsemakula 2024-01-18
parent 57d4b5b · commit 4f176b3
-rw-r--r--crates/ide-assists/src/handlers/auto_import.rs2
-rw-r--r--crates/rust-analyzer/src/config.rs7
-rw-r--r--editors/code/package.json6
3 files changed, 11 insertions, 4 deletions
diff --git a/crates/ide-assists/src/handlers/auto_import.rs b/crates/ide-assists/src/handlers/auto_import.rs
index a64591c9ca..45ac03fbf3 100644
--- a/crates/ide-assists/src/handlers/auto_import.rs
+++ b/crates/ide-assists/src/handlers/auto_import.rs
@@ -49,6 +49,8 @@ use crate::{AssistContext, AssistId, AssistKind, Assists, GroupLabel};
// - `item`: Don't merge imports at all, creating one import per item.
// - `preserve`: Do not change the granularity of any imports. For auto-import this has the same
// effect as `item`.
+// - `one`: Merge all imports into a single use statement as long as they have the same visibility
+// and attributes.
//
// In `VS Code` the configuration for this is `rust-analyzer.imports.granularity.group`.
//
diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs
index 3ec5d86966..29f9df2fba 100644
--- a/crates/rust-analyzer/src/config.rs
+++ b/crates/rust-analyzer/src/config.rs
@@ -1493,6 +1493,7 @@ impl Config {
ImportGranularityDef::Item => ImportGranularity::Item,
ImportGranularityDef::Crate => ImportGranularity::Crate,
ImportGranularityDef::Module => ImportGranularity::Module,
+ ImportGranularityDef::One => ImportGranularity::One,
},
enforce_granularity: self.data.imports_granularity_enforce,
prefix_kind: match self.data.imports_prefix {
@@ -1933,6 +1934,7 @@ enum ImportGranularityDef {
Item,
Crate,
Module,
+ One,
}
#[derive(Deserialize, Debug, Copy, Clone)]
@@ -2274,12 +2276,13 @@ fn field_props(field: &str, ty: &str, doc: &[&str], default: &str) -> serde_json
},
"ImportGranularityDef" => set! {
"type": "string",
- "enum": ["preserve", "crate", "module", "item"],
+ "enum": ["preserve", "crate", "module", "item", "one"],
"enumDescriptions": [
"Do not change the granularity of any imports and preserve the original structure written by the developer.",
"Merge imports from the same crate into a single use statement. Conversely, imports from different crates are split into separate statements.",
"Merge imports from the same module into a single use statement. Conversely, imports from different modules are split into separate statements.",
- "Flatten imports so that each has its own use statement."
+ "Flatten imports so that each has its own use statement.",
+ "Merge all imports into a single use statement as long as they have the same visibility and attributes."
],
},
"ImportPrefixDef" => set! {
diff --git a/editors/code/package.json b/editors/code/package.json
index e7ceee165c..bca789fab7 100644
--- a/editors/code/package.json
+++ b/editors/code/package.json
@@ -1120,13 +1120,15 @@
"preserve",
"crate",
"module",
- "item"
+ "item",
+ "one"
],
"enumDescriptions": [
"Do not change the granularity of any imports and preserve the original structure written by the developer.",
"Merge imports from the same crate into a single use statement. Conversely, imports from different crates are split into separate statements.",
"Merge imports from the same module into a single use statement. Conversely, imports from different modules are split into separate statements.",
- "Flatten imports so that each has its own use statement."
+ "Flatten imports so that each has its own use statement.",
+ "Merge all imports into a single use statement as long as they have the same visibility and attributes."
]
},
"rust-analyzer.imports.group.enable": {