@@ -32,18 +32,17 @@ package struct RunSourceKitdRequestCommand: AsyncParsableCommand {
3232
3333 @Option (
3434 name: . customLong( " request-file " ) ,
35- help: " Path to a JSON sourcekitd request "
35+ help:
36+ " Path to a JSON sourcekitd request. Multiple may be passed to run them in sequence on the same sourcekitd instance "
3637 )
37- var sourcekitdRequestPath : String
38+ var sourcekitdRequestPaths : [ String ]
3839
3940 @Option ( help: " line:column override for key.offset " )
4041 var position : String ?
4142
4243 package init ( ) { }
4344
4445 package func run( ) async throws {
45- var requestString = try String ( contentsOf: URL ( fileURLWithPath: sourcekitdRequestPath) , encoding: . utf8)
46-
4746 let installPath = try AbsolutePath ( validating: Bundle . main. bundlePath)
4847 let sourcekitdPath =
4948 if let sourcekitdPath {
@@ -58,54 +57,49 @@ package struct RunSourceKitdRequestCommand: AsyncParsableCommand {
5857 dylibPath: try ! AbsolutePath ( validating: sourcekitdPath)
5958 )
6059
61- if let lineColumn = position? . split ( separator: " : " , maxSplits: 2 ) . map ( Int . init) ,
62- lineColumn. count == 2 ,
63- let line = lineColumn [ 0 ] ,
64- let column = lineColumn [ 1 ]
65- {
66- let requestInfo = try RequestInfo ( request: requestString)
60+ var lastResponse : SKDResponse ?
6761
68- let lineTable = LineTable ( requestInfo. fileContents)
69- let offset = lineTable. utf8OffsetOf ( line: line - 1 , utf8Column: column - 1 )
70- print ( " Adjusting request offset to \( offset) " )
71- requestString. replace ( #/key.offset: [0-9]+/# , with: " key.offset: \( offset) " )
72- }
62+ for sourcekitdRequestPath in sourcekitdRequestPaths {
63+ var requestString = try String ( contentsOf: URL ( fileURLWithPath: sourcekitdRequestPath) , encoding: . utf8)
64+ if let lineColumn = position? . split ( separator: " : " , maxSplits: 2 ) . map ( Int . init) ,
65+ lineColumn. count == 2 ,
66+ let line = lineColumn [ 0 ] ,
67+ let column = lineColumn [ 1 ]
68+ {
69+ let requestInfo = try RequestInfo ( request: requestString)
7370
74- let request = try requestString. cString ( using: . utf8) !. withUnsafeBufferPointer { buffer in
75- var error : UnsafeMutablePointer < CChar > ?
76- let req = sourcekitd. api. request_create_from_yaml ( buffer. baseAddress!, & error) !
77- if let error {
78- throw ReductionError ( " Failed to parse sourcekitd request from JSON: \( String ( cString: error) ) " )
71+ let lineTable = LineTable ( requestInfo. fileContents)
72+ let offset = lineTable. utf8OffsetOf ( line: line - 1 , utf8Column: column - 1 )
73+ print ( " Adjusting request offset to \( offset) " )
74+ requestString. replace ( #/key.offset: [0-9]+/# , with: " key.offset: \( offset) " )
7975 }
80- return req
81- }
82- let response : SKDResponse = await withCheckedContinuation { continuation in
83- var handle : sourcekitd_api_request_handle_t ? = nil
84- sourcekitd. api. send_request ( request, & handle) { resp in
85- continuation. resume ( returning: SKDResponse ( resp!, sourcekitd: sourcekitd) )
76+
77+ let request = try requestString. cString ( using: . utf8) !. withUnsafeBufferPointer { buffer in
78+ var error : UnsafeMutablePointer < CChar > ?
79+ let req = sourcekitd. api. request_create_from_yaml ( buffer. baseAddress!, & error) !
80+ if let error {
81+ throw ReductionError ( " Failed to parse sourcekitd request from JSON: \( String ( cString: error) ) " )
82+ }
83+ return req
84+ }
85+ let response = await withCheckedContinuation { continuation in
86+ var handle : sourcekitd_api_request_handle_t ? = nil
87+ sourcekitd. api. send_request ( request, & handle) { resp in
88+ continuation. resume ( returning: SKDResponse ( resp!, sourcekitd: sourcekitd) )
89+ }
8690 }
91+ lastResponse = response
92+
93+ print ( response. description)
8794 }
8895
89- switch response. error {
90- case . requestFailed( let message) :
91- print ( message)
92- throw ExitCode ( 1 )
93- case . requestInvalid( let message) :
94- print ( message)
95- throw ExitCode ( 1 )
96- case . requestCancelled:
97- print ( " request cancelled " )
98- throw ExitCode ( 1 )
99- case . timedOut:
100- print ( " request timed out " )
101- throw ExitCode ( 1 )
102- case . missingRequiredSymbol:
103- print ( " missing required symbol " )
96+ switch lastResponse? . error {
97+ case . requestFailed, . requestInvalid, . requestCancelled, . timedOut, . missingRequiredSymbol:
10498 throw ExitCode ( 1 )
10599 case . connectionInterrupted:
106100 throw ExitCode ( 255 )
107101 case nil :
108- print ( response . description )
102+ break
109103 }
110104 }
111105}
0 commit comments