Skip to content

Commit 9346b78

Browse files
Fix markdownEnumDescriptions encoding for JSON Schema
The `markdownEnumDescriptions` field in JSON Schema is supposed to be an array of descriptions but was incorrectly encoded as a dictionary.
1 parent f2e957b commit 9346b78

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

SourceKitLSPDevUtils/Sources/ConfigSchemaGen/JSONSchema.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ struct JSONSchema: Encodable {
5858
var markdownDescription: String?
5959
/// VSCode extension: Markdown formatted descriptions for rich hover for enum values
6060
/// https://github.com/microsoft/vscode-wiki/blob/main/Setting-Descriptions.md
61-
var markdownEnumDescriptions: [String: String]?
61+
var markdownEnumDescriptions: [String]?
6262

6363
func encode(to encoder: any Encoder) throws {
6464
// Manually implement encoding to use `encodeIfPresent` for HeapBox-ed fields
@@ -79,7 +79,7 @@ struct JSONSchema: Encodable {
7979
try container.encodeIfPresent(items, forKey: .items)
8080
try container.encodeIfPresent(additionalProperties, forKey: .additionalProperties)
8181
try container.encodeIfPresent(markdownDescription, forKey: .markdownDescription)
82-
if let markdownEnumDescriptions, !markdownEnumDescriptions.isEmpty {
82+
if let markdownEnumDescriptions {
8383
try container.encode(markdownEnumDescriptions, forKey: .markdownEnumDescriptions)
8484
}
8585
}
@@ -131,7 +131,9 @@ struct JSONSchemaBuilder {
131131
// Set `markdownEnumDescriptions` for better rendering in VSCode rich hover
132132
// Unlike `description`, `enumDescriptions` field is not a part of JSON Schema spec,
133133
// so we only set `markdownEnumDescriptions` here.
134-
schema.markdownEnumDescriptions = enumInfo.cases.reduce(into: [:]) { $0[$1.name] = $1.description }
134+
if enumInfo.cases.contains(where: { $0.description != nil }) {
135+
schema.markdownEnumDescriptions = enumInfo.cases.map { $0.description ?? "" }
136+
}
135137
}
136138
return schema
137139
}

config.schema.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515
"enabled"
1616
],
1717
"markdownDescription" : "Determines how background indexing should prepare a target.",
18-
"markdownEnumDescriptions" : {
19-
"build" : "Build a target to prepare it.",
20-
"enabled" : "Prepare a target without generating object files.",
21-
"noLazy" : "Prepare a target without generating object files but do not do lazy type checking and function body skipping. This uses SwiftPM's `--experimental-prepare-for-indexing-no-lazy` flag."
22-
},
18+
"markdownEnumDescriptions" : [
19+
"Build a target to prepare it.",
20+
"Prepare a target without generating object files but do not do lazy type checking and function body skipping. This uses SwiftPM's `--experimental-prepare-for-indexing-no-lazy` flag.",
21+
"Prepare a target without generating object files."
22+
],
2323
"type" : "string"
2424
},
2525
"buildSettingsTimeout" : {

0 commit comments

Comments
 (0)