Skip to content

Commit 08f1595

Browse files
committed
Never return nil for position conversions
Instead of returning `nil` to indicate that the position conversion failed, log a fault and perform a best-effort recovery. I think this allows us to perform better recovery and also makes code calling these position conversions a lot simpler because it doesn’t need to make decisions about what to do if position conversions fail.
1 parent e99892b commit 08f1595

22 files changed

+429
-561
lines changed

Sources/Diagnose/SourcekitdRequestCommand.swift

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,9 @@ public struct SourceKitdRequestCommand: AsyncParsableCommand {
5656
let requestInfo = try RequestInfo(request: requestString)
5757

5858
let lineTable = LineTable(requestInfo.fileContents)
59-
if let offset = lineTable.utf8OffsetOf(line: line - 1, utf8Column: column - 1) {
60-
print("Adjusting request offset to \(offset)")
61-
requestString.replace(#/key.offset: [0-9]+/#, with: "key.offset: \(offset)")
62-
}
59+
let offset = lineTable.utf8OffsetOf(line: line - 1, utf8Column: column - 1)
60+
print("Adjusting request offset to \(offset)")
61+
requestString.replace(#/key.offset: [0-9]+/#, with: "key.offset: \(offset)")
6362
}
6463

6564
let request = try requestString.cString(using: .utf8)!.withUnsafeBufferPointer { buffer in

0 commit comments

Comments
 (0)