Skip to content

Commit 0b725f3

Browse files
committed
fix: rust-analyzer.imports.granularity.group should get a dropdown UI
VS Code only offers a dropdown if a the toplevel property description is `enum`. For `anyOf` (a JSON schema feature), we don't get that helpful UI. Whilst the previous version marked `preserve` as deprecated, the VS Code UI didn't do anything special when users chose that value. Instead, use an enum so we get the helpful dropdown, and just use the description to highlight the deprecated value. Relevant docs: https://code.visualstudio.com/api/references/contribution-points#:~:text=The%20enumDescriptions%20property%20provides%20a,will%20be%20parsed%20as%20Markdown. https://json-schema.org/draft/2020-12/draft-bhutton-json-schema-01#section-10.2.1.2
1 parent e31e2b1 commit 0b725f3

File tree

2 files changed

+20
-41
lines changed

2 files changed

+20
-41
lines changed

src/tools/rust-analyzer/crates/rust-analyzer/src/config.rs

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3566,23 +3566,13 @@ fn field_props(field: &str, ty: &str, doc: &[&str], default: &str) -> serde_json
35663566
},
35673567
"ImportGranularityDef" => set! {
35683568
"type": "string",
3569-
"anyOf": [
3570-
{
3571-
"enum": ["crate", "module", "item", "one"],
3572-
"enumDescriptions": [
3573-
"Merge imports from the same crate into a single use statement. Conversely, imports from different crates are split into separate statements.",
3574-
"Merge imports from the same module into a single use statement. Conversely, imports from different modules are split into separate statements.",
3575-
"Flatten imports so that each has its own use statement.",
3576-
"Merge all imports into a single use statement as long as they have the same visibility and attributes."
3577-
],
3578-
},
3579-
{
3580-
"enum": ["preserve"],
3581-
"enumDescriptions": [
3582-
"Deprecated - unless `enforceGranularity` is `true`, the style of the current file is preferred over this setting. Behaves like `item`.",
3583-
],
3584-
"deprecated": true,
3585-
}
3569+
"enum": ["crate", "module", "item", "one", "preserve"],
3570+
"enumDescriptions": [
3571+
"Merge imports from the same crate into a single use statement. Conversely, imports from different crates are split into separate statements.",
3572+
"Merge imports from the same module into a single use statement. Conversely, imports from different modules are split into separate statements.",
3573+
"Flatten imports so that each has its own use statement.",
3574+
"Merge all imports into a single use statement as long as they have the same visibility and attributes.",
3575+
"Deprecated - unless `enforceGranularity` is `true`, the style of the current file is preferred over this setting. Behaves like `item`."
35863576
],
35873577
},
35883578
"ImportPrefixDef" => set! {

src/tools/rust-analyzer/editors/code/package.json

Lines changed: 13 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2020,30 +2020,19 @@
20202020
"markdownDescription": "How imports should be grouped into use statements.",
20212021
"default": "crate",
20222022
"type": "string",
2023-
"anyOf": [
2024-
{
2025-
"enum": [
2026-
"crate",
2027-
"module",
2028-
"item",
2029-
"one"
2030-
],
2031-
"enumDescriptions": [
2032-
"Merge imports from the same crate into a single use statement. Conversely, imports from different crates are split into separate statements.",
2033-
"Merge imports from the same module into a single use statement. Conversely, imports from different modules are split into separate statements.",
2034-
"Flatten imports so that each has its own use statement.",
2035-
"Merge all imports into a single use statement as long as they have the same visibility and attributes."
2036-
]
2037-
},
2038-
{
2039-
"enum": [
2040-
"preserve"
2041-
],
2042-
"enumDescriptions": [
2043-
"Deprecated - unless `enforceGranularity` is `true`, the style of the current file is preferred over this setting. Behaves like `item`."
2044-
],
2045-
"deprecated": true
2046-
}
2023+
"enum": [
2024+
"crate",
2025+
"module",
2026+
"item",
2027+
"one",
2028+
"preserve"
2029+
],
2030+
"enumDescriptions": [
2031+
"Merge imports from the same crate into a single use statement. Conversely, imports from different crates are split into separate statements.",
2032+
"Merge imports from the same module into a single use statement. Conversely, imports from different modules are split into separate statements.",
2033+
"Flatten imports so that each has its own use statement.",
2034+
"Merge all imports into a single use statement as long as they have the same visibility and attributes.",
2035+
"Deprecated - unless `enforceGranularity` is `true`, the style of the current file is preferred over this setting. Behaves like `item`."
20472036
]
20482037
}
20492038
}

0 commit comments

Comments
 (0)