Skip to content

Commit 4f176b3

Browse files
committed
update import granularity config and docs
1 parent 57d4b5b commit 4f176b3

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

crates/ide-assists/src/handlers/auto_import.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ use crate::{AssistContext, AssistId, AssistKind, Assists, GroupLabel};
4949
// - `item`: Don't merge imports at all, creating one import per item.
5050
// - `preserve`: Do not change the granularity of any imports. For auto-import this has the same
5151
// effect as `item`.
52+
// - `one`: Merge all imports into a single use statement as long as they have the same visibility
53+
// and attributes.
5254
//
5355
// In `VS Code` the configuration for this is `rust-analyzer.imports.granularity.group`.
5456
//

crates/rust-analyzer/src/config.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1493,6 +1493,7 @@ impl Config {
14931493
ImportGranularityDef::Item => ImportGranularity::Item,
14941494
ImportGranularityDef::Crate => ImportGranularity::Crate,
14951495
ImportGranularityDef::Module => ImportGranularity::Module,
1496+
ImportGranularityDef::One => ImportGranularity::One,
14961497
},
14971498
enforce_granularity: self.data.imports_granularity_enforce,
14981499
prefix_kind: match self.data.imports_prefix {
@@ -1933,6 +1934,7 @@ enum ImportGranularityDef {
19331934
Item,
19341935
Crate,
19351936
Module,
1937+
One,
19361938
}
19371939

19381940
#[derive(Deserialize, Debug, Copy, Clone)]
@@ -2274,12 +2276,13 @@ fn field_props(field: &str, ty: &str, doc: &[&str], default: &str) -> serde_json
22742276
},
22752277
"ImportGranularityDef" => set! {
22762278
"type": "string",
2277-
"enum": ["preserve", "crate", "module", "item"],
2279+
"enum": ["preserve", "crate", "module", "item", "one"],
22782280
"enumDescriptions": [
22792281
"Do not change the granularity of any imports and preserve the original structure written by the developer.",
22802282
"Merge imports from the same crate into a single use statement. Conversely, imports from different crates are split into separate statements.",
22812283
"Merge imports from the same module into a single use statement. Conversely, imports from different modules are split into separate statements.",
2282-
"Flatten imports so that each has its own use statement."
2284+
"Flatten imports so that each has its own use statement.",
2285+
"Merge all imports into a single use statement as long as they have the same visibility and attributes."
22832286
],
22842287
},
22852288
"ImportPrefixDef" => set! {

editors/code/package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1120,13 +1120,15 @@
11201120
"preserve",
11211121
"crate",
11221122
"module",
1123-
"item"
1123+
"item",
1124+
"one"
11241125
],
11251126
"enumDescriptions": [
11261127
"Do not change the granularity of any imports and preserve the original structure written by the developer.",
11271128
"Merge imports from the same crate into a single use statement. Conversely, imports from different crates are split into separate statements.",
11281129
"Merge imports from the same module into a single use statement. Conversely, imports from different modules are split into separate statements.",
1129-
"Flatten imports so that each has its own use statement."
1130+
"Flatten imports so that each has its own use statement.",
1131+
"Merge all imports into a single use statement as long as they have the same visibility and attributes."
11301132
]
11311133
},
11321134
"rust-analyzer.imports.group.enable": {

0 commit comments

Comments
 (0)