@@ -32,18 +32,17 @@ package struct RunSourceKitdRequestCommand: AsyncParsableCommand {
32
32
33
33
@Option (
34
34
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 "
36
37
)
37
- var sourcekitdRequestPath : String
38
+ var sourcekitdRequestPaths : [ String ]
38
39
39
40
@Option ( help: " line:column override for key.offset " )
40
41
var position : String ?
41
42
42
43
package init ( ) { }
43
44
44
45
package func run( ) async throws {
45
- var requestString = try String ( contentsOf: URL ( fileURLWithPath: sourcekitdRequestPath) , encoding: . utf8)
46
-
47
46
let installPath = try AbsolutePath ( validating: Bundle . main. bundlePath)
48
47
let sourcekitdPath =
49
48
if let sourcekitdPath {
@@ -58,54 +57,49 @@ package struct RunSourceKitdRequestCommand: AsyncParsableCommand {
58
57
dylibPath: try ! AbsolutePath ( validating: sourcekitdPath)
59
58
)
60
59
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 ?
67
61
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)
73
70
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) " )
79
75
}
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
+ }
86
90
}
91
+ lastResponse = response
92
+
93
+ print ( response. description)
87
94
}
88
95
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:
104
98
throw ExitCode ( 1 )
105
99
case . connectionInterrupted:
106
100
throw ExitCode ( 255 )
107
101
case nil :
108
- print ( response . description )
102
+ break
109
103
}
110
104
}
111
105
}
0 commit comments