mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-03 15:15:24 +00:00
Auto merge of #16372 - davidsemakula:import-granularity-one, r=Veykril
feat: Add "One" import granularity Adds a new import granularity option "One" that merges all imports into a single use statement as long as they have the same visibility and attributes. This is similar to [rustfmt's `imports_granularity = "One"`](https://rust-lang.github.io/rustfmt/?version=v1.6.0&search=import#imports_granularity). Fixes: #11361
This commit is contained in:
commit
3f4c6dac3d
10 changed files with 473 additions and 85 deletions
|
@ -1497,6 +1497,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 {
|
||||
|
@ -1941,6 +1942,7 @@ enum ImportGranularityDef {
|
|||
Item,
|
||||
Crate,
|
||||
Module,
|
||||
One,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Debug, Copy, Clone)]
|
||||
|
@ -2282,12 +2284,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! {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue