Hi Aciid!
I checked out SourceKitten
and used it to get the module interface for Foundation
:
"key.kind" : "source.lang.swift.decl.struct",
"key.length" : 658,
"key.name" : "Measurement",
"key.namelength" : 11,
"key.nameoffset" : 265460,
"key.offset" : 265453,
"key.substructure" : [
{
"key.accessibility" : "source.lang.swift.accessibility.public",
"key.kind" : "source.lang.swift.decl.var.instance",
"key.length" : 17,
"key.name" : "value",
"key.namelength" : 5,
"key.nameoffset" : 265750,
"key.offset" : 265746,
"key.setter_accessibility" : "source.lang.swift.accessibility.public",
"key.typename" : "Double"
},
{
"key.accessibility" : "source.lang.swift.accessibility.public",
"key.kind" : "source.lang.swift.decl.function.method.instance",
"key.length" : 35,
"key.name" : "init(value:unit:)",
"key.namelength" : 35,
"key.nameoffset" : 265841,
"key.offset" : 265841,
"key.substructure" : [
{
"key.kind" : "source.lang.swift.decl.var.parameter",
"key.length" : 13,
"key.name" : "value",
"key.namelength" : 5,
"key.nameoffset" : 265846,
"key.offset" : 265846,
"key.typename" : "Double"
},
{
"key.kind" : "source.lang.swift.decl.var.parameter",
"key.length" : 14,
"key.name" : "unit",
"key.namelength" : 4,
"key.nameoffset" : 265861,
"key.offset" : 265861,
"key.typename" : "UnitType"
}
]
}, ...
I feel like there's a lot of useful fields here:
accessibility
name
kind
substructure
typename
Would comparing these be a good starting point?
I think for the initial version, it may be acceptable if SwiftPM takes a serialized version of module interface as an input (instead of a version). This will be annoying for users but will make a good minimum viable feature.
Would this serialized version be in a human format and maintained by package authors? Or would it be more automated, like maybe the JSON response from SourceKit
or something that a command in SwiftPM would output?