Skip to content

Commit 1847dc7

Browse files
Rename OptionTypeSchama.Object to Struct
1 parent aa7be46 commit 1847dc7

File tree

3 files changed

+23
-19
lines changed

3 files changed

+23
-19
lines changed

SourceKitLSPDevUtils/Sources/ConfigSchemaGen/JSONSchema.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,11 @@ struct JSONSchemaBuilder {
107107
case .dictionary(value: let value):
108108
schema.type = "object"
109109
schema.additionalProperties = try buildJSONSchema(from: value)
110-
case .object(let object):
110+
case .struct(let structInfo):
111111
schema.type = "object"
112112
var properties: [String: JSONSchema] = [:]
113113
var required: [String] = []
114-
for property in object.properties {
114+
for property in structInfo.properties {
115115
let propertyType = property.type
116116
var propertySchema = try buildJSONSchema(from: propertyType)
117117
propertySchema.description = property.description

SourceKitLSPDevUtils/Sources/ConfigSchemaGen/OptionDocument.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ struct OptionDocumentBuilder {
4545
let type = property.type
4646
let typeDescription: String?
4747
switch type.kind {
48-
case .object:
49-
// Skip object type as we describe its properties in the next level
48+
case .struct:
49+
// Skip struct type as we describe its properties in the next level
5050
typeDescription = nil
5151
default:
5252
typeDescription = Self.typeToDisplay(type)
@@ -61,7 +61,7 @@ struct OptionDocumentBuilder {
6161
}
6262
doc += "\n"
6363
switch type.kind {
64-
case .object(let schema):
64+
case .struct(let schema):
6565
for property in schema.properties {
6666
try appendProperty(property, indentLevel: indentLevel + 1)
6767
}
@@ -78,7 +78,7 @@ struct OptionDocumentBuilder {
7878
default: break
7979
}
8080
}
81-
guard case .object(let schema) = schema.kind else {
81+
guard case .struct(let schema) = schema.kind else {
8282
fatalError("Root schema must be a struct")
8383
}
8484
for property in schema.properties {
@@ -97,8 +97,8 @@ struct OptionDocumentBuilder {
9797
return "\(typeToDisplay(value, shouldWrap: true))[]"
9898
case .dictionary(let value):
9999
return "[string: \(typeToDisplay(value))]"
100-
case .object(let objectInfo):
101-
return objectInfo.name
100+
case .struct(let structInfo):
101+
return structInfo.name
102102
case .enum(let enumInfo):
103103
let cases = enumInfo.cases.map { "\"\($0.name)\"" }.joined(separator: "|")
104104
return shouldWrap ? "(\(cases))" : cases

SourceKitLSPDevUtils/Sources/ConfigSchemaGen/OptionSchema.swift

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ struct OptionTypeSchama {
2222
var defaultValue: String?
2323
}
2424

25-
struct Object {
25+
struct Struct {
2626
var name: String
2727
/// Properties of the object, preserving the order of declaration
2828
var properties: [Property]
@@ -45,7 +45,7 @@ struct OptionTypeSchama {
4545
case string
4646
indirect case array(value: OptionTypeSchama)
4747
indirect case dictionary(value: OptionTypeSchama)
48-
case object(Object)
48+
case `struct`(Struct)
4949
case `enum`(Enum)
5050
}
5151

@@ -60,37 +60,41 @@ struct OptionTypeSchama {
6060
/// Accesses the property schema by name
6161
subscript(_ key: String) -> OptionTypeSchama? {
6262
get {
63-
guard case .object(let object) = kind else {
63+
guard case .struct(let structInfo) = kind else {
6464
return nil
6565
}
66-
return object.properties.first { $0.name == key }?.type
66+
return structInfo.properties.first { $0.name == key }?.type
6767
}
6868
set {
69-
guard case .object(var object) = kind else {
69+
guard case .struct(var structInfo) = kind else {
7070
fatalError("Cannot set property on non-object type")
7171
}
72-
guard let index = object.properties.firstIndex(where: { $0.name == key }) else {
72+
guard let index = structInfo.properties.firstIndex(where: { $0.name == key }) else {
7373
fatalError("Property not found: \(key)")
7474
}
7575
guard let newValue = newValue else {
7676
fatalError("Cannot set property to nil")
7777
}
78-
object.properties[index].type = newValue
79-
kind = .object(object)
78+
structInfo.properties[index].type = newValue
79+
kind = .struct(structInfo)
8080
}
8181
}
8282
}
8383

8484
/// Context for resolving option schema from Swift syntax nodes
8585
struct OptionSchemaContext {
86-
let typeNameResolver: TypeDeclResolver
86+
private let typeNameResolver: TypeDeclResolver
87+
88+
init(typeNameResolver: TypeDeclResolver) {
89+
self.typeNameResolver = typeNameResolver
90+
}
8791

8892
/// Builds a schema from a type declaration
8993
func buildSchema(from typeDecl: TypeDeclResolver.TypeDecl) throws -> OptionTypeSchama {
9094
switch DeclSyntax(typeDecl).as(DeclSyntaxEnum.self) {
9195
case .structDecl(let decl):
9296
let structInfo = try buildStructProperties(decl)
93-
return OptionTypeSchama(kind: .object(structInfo))
97+
return OptionTypeSchama(kind: .struct(structInfo))
9498
case .enumDecl(let decl):
9599
let enumInfo = buildEnumCases(decl)
96100
return OptionTypeSchama(kind: .enum(enumInfo))
@@ -165,7 +169,7 @@ struct OptionSchemaContext {
165169
return .init(name: typeName, cases: cases)
166170
}
167171

168-
private func buildStructProperties(_ node: StructDeclSyntax) throws -> OptionTypeSchama.Object {
172+
private func buildStructProperties(_ node: StructDeclSyntax) throws -> OptionTypeSchama.Struct {
169173
var properties: [OptionTypeSchama.Property] = []
170174
for member in node.memberBlock.members {
171175
// Skip computed properties

0 commit comments

Comments
 (0)