@@ -82,43 +82,56 @@ struct GenerateCommand: CommandProtocol {
8282 }
8383 }
8484
85- private func parseSPMModule( moduleName: String ) throws -> [ SwiftDocs ] {
86- guard let docs = Module ( spmName: moduleName) ? . docs else {
85+ private func interfaceForModule( _ module: String , compilerArguments: [ String ] ) throws -> [ String : SourceKitRepresentable ] {
86+ try Request . customRequest ( request: [
87+ " key.request " : UID ( " source.request.editor.open.interface " ) ,
88+ " key.name " : NSUUID ( ) . uuidString,
89+ " key.compilerargs " : compilerArguments,
90+ " key.modulename " : " \( module) " ,
91+ ] ) . send ( )
92+ }
93+
94+ private func parseSPMModule( moduleName: String ) throws -> [ String : SourceKitRepresentable ] {
95+ guard let module = Module ( spmName: moduleName) else {
8796 let message = " Error: Failed to generate documentation for SPM module ' \( moduleName) '. "
8897 throw ModuleInterface . Error. default ( message)
8998 }
90- return docs
99+ return try interfaceForModule ( module . name , compilerArguments : module . compilerArguments )
91100 }
92101
93- private func parseSwiftModule( moduleName: String , args: [ String ] , path: String ) throws -> [ SwiftDocs ] {
94- guard let docs = Module ( xcodeBuildArguments: args, name: moduleName, inPath: path) ? . docs else {
102+ private func parseSwiftModule( moduleName: String , args: [ String ] , path: String ) throws -> [ String : SourceKitRepresentable ] {
103+ guard let module = Module ( xcodeBuildArguments: args, name: moduleName, inPath: path) else {
95104 let message = " Error: Failed to generate documentation for module ' \( moduleName) '. "
96105 throw ModuleInterface . Error. default ( message)
97106 }
98- return docs
107+ return try interfaceForModule ( module . name , compilerArguments : module . compilerArguments )
99108 }
100109
101- private func parseXcodeProject( args: [ String ] , inputPath: String ) throws -> [ SwiftDocs ] {
102- guard let docs = Module ( xcodeBuildArguments: args, name: nil , inPath: inputPath) ? . docs else {
110+ private func parseXcodeProject( args: [ String ] , inputPath: String ) throws -> [ String : SourceKitRepresentable ] {
111+ guard let module = Module ( xcodeBuildArguments: args, name: nil , inPath: inputPath) else {
103112 throw ModuleInterface . Error. default ( " Error: Failed to generate documentation. " )
104113 }
105- return docs
114+ return try interfaceForModule ( module . name , compilerArguments : module . compilerArguments )
106115 }
107116
108- private func generateDocumentation( docs: [ SwiftDocs ] , options: GenerateCommandOptions , module: String ) throws {
117+ private func generateDocumentation( docs: [ String : SourceKitRepresentable ] , options: GenerateCommandOptions , module: String ) throws {
109118 if options. clean {
110119 try CleanCommand . removeModuleInterface ( path: options. outputFolder, module: module)
111120 }
112- let output = process ( docs: docs, options: options)
121+ guard let sourcetext = docs [ " key.sourcetext " ] as? String else {
122+ let message = " Unable to parse module named \( module) "
123+ throw ModuleInterface . Error. default ( message)
124+ }
125+ let output = sourcetext
113126 try createDirectory ( path: options. outputFolder)
114127 try write ( to: options. outputFolder, module: module, documentation: output)
115128 }
116129
117- private func write( to path: String , module: String , documentation: [ String ] ) throws {
130+ private func write( to path: String , module: String , documentation: String ) throws {
118131 fputs ( " Generating Module Interface... \n " . green, stdout)
119132 let fileName = module. isEmpty ? " Unknown " : module
120133 let fileExtension = " .swift "
121- let contents = documentation. joined ( separator : " \n " )
134+ let contents = documentation
122135 try contents. write ( toFile: path + " / " + fileName + fileExtension, atomically: true , encoding: . utf8)
123136 fputs ( " Fomatting... \n " . green, stdout)
124137 let formatted = try format ( contents)
0 commit comments