Skip to content

Commit 3eac98f

Browse files
committed
Switch suffix text over to a dictionary
The dictionary provides more semantic meaning, that we are mapping from absolute positions over to the suffix text for each position.
1 parent aa45c60 commit 3eac98f

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

Sources/SwiftDiagnostics/DiagnosticsFormatter.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ public struct DiagnosticsFormatter {
190190
tree: SyntaxType,
191191
diags: [Diagnostic],
192192
indentString: String,
193-
suffixTexts: [(AbsolutePosition, String)],
193+
suffixTexts: [AbsolutePosition: String],
194194
sourceLocationConverter: SourceLocationConverter? = nil
195195
) -> String {
196196
let slc = sourceLocationConverter ?? SourceLocationConverter(file: fileName ?? "", tree: tree)
@@ -320,7 +320,7 @@ public struct DiagnosticsFormatter {
320320
tree: tree,
321321
diags: diags,
322322
indentString: "",
323-
suffixTexts: []
323+
suffixTexts: [:]
324324
)
325325
}
326326

Sources/SwiftDiagnostics/GroupedDiagnostics.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,14 +149,16 @@ extension GroupedDiagnostics {
149149

150150
let childPadding = String(slc.sourceLines.count + 1).count + 1;
151151

152-
let childSources: [(AbsolutePosition, String)] = sourceFiles[sourceFileID.id].children.map { childBufferID in
152+
// Collect the child sources.
153+
var childSources: [AbsolutePosition : String] = [:]
154+
for childBufferID in sourceFiles[sourceFileID.id].children {
153155
let childSource = annotateSource(
154156
childBufferID,
155157
formatter: formatter,
156158
indentString: indentString + String(repeating: " ", count: childPadding) + ""
157159
)
158160

159-
return (sourceFiles[childBufferID.id].parent!.1, childSource)
161+
childSources[sourceFiles[childBufferID.id].parent!.1, default: ""].append(childSource)
160162
}
161163

162164
// If this is a nested source file, draw a box around it.

Sources/SwiftSyntax/AbsolutePosition.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
/// An absolute position in a source file as text - the absolute utf8Offset from
1414
/// the start of the file.
15-
public struct AbsolutePosition: Comparable {
15+
public struct AbsolutePosition: Comparable, Hashable {
1616
public let utf8Offset: Int
1717

1818
static let startOfFile = AbsolutePosition(utf8Offset: 0)

0 commit comments

Comments
 (0)