Skip to content

Never return nil for position conversions #1168

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions Sources/Diagnose/SourcekitdRequestCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,9 @@ public struct SourceKitdRequestCommand: AsyncParsableCommand {
let requestInfo = try RequestInfo(request: requestString)

let lineTable = LineTable(requestInfo.fileContents)
if let offset = lineTable.utf8OffsetOf(line: line - 1, utf8Column: column - 1) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure it's worth it, but maybe we should keep a nil returning variant? In this case in particular, it would make sense to display an error about invalid line/col (though... we're currently just ignoring it anyway).

print("Adjusting request offset to \(offset)")
requestString.replace(#/key.offset: [0-9]+/#, with: "key.offset: \(offset)")
}
let offset = lineTable.utf8OffsetOf(line: line - 1, utf8Column: column - 1)
print("Adjusting request offset to \(offset)")
requestString.replace(#/key.offset: [0-9]+/#, with: "key.offset: \(offset)")
}

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