File tree Expand file tree Collapse file tree 2 files changed +17
-6
lines changed
Tests/SwiftDiagnosticsTest Expand file tree Collapse file tree 2 files changed +17
-6
lines changed Original file line number Diff line number Diff line change @@ -227,7 +227,13 @@ public struct DiagnosticsFormatter {
227
227
// If there was a filename, add it first.
228
228
if let fileName = fileName {
229
229
let header = colorizeBufferOutline ( " === " )
230
- annotatedSource. append ( " \( indentString) \( header) \( fileName) \( header) \n " )
230
+ let firstLine =
231
+ 1
232
+ + ( annotatedSourceLines. enumerated ( ) . first { ( lineIndex, sourceLine) in
233
+ !sourceLine. isFreeOfAnnotations
234
+ } ? . offset ?? 0 )
235
+
236
+ annotatedSource. append ( " \( indentString) \( header) \( fileName) : \( firstLine) \( header) \n " )
231
237
}
232
238
233
239
/// Keep track if a line missing char should be printed
Original file line number Diff line number Diff line change @@ -80,6 +80,9 @@ final class GroupedDiagnosticsFormatterTests: XCTestCase {
80
80
// Main source file.
81
81
let ( mainSourceID, mainSourceMarkers) = group. addTestFile (
82
82
"""
83
+
84
+
85
+ // test
83
86
let pi = 3.14159
84
87
1️⃣#myAssert(pi == 3)
85
88
print( " hello "
@@ -111,9 +114,11 @@ final class GroupedDiagnosticsFormatterTests: XCTestCase {
111
114
AssertStringsEqualWithDiff (
112
115
annotated,
113
116
"""
114
- === main.swift ===
115
- 1 │ let pi = 3.14159
116
- 2 │ #myAssert(pi == 3)
117
+ === main.swift:5 ===
118
+ ┆
119
+ 3 │ // test
120
+ 4 │ let pi = 3.14159
121
+ 5 │ #myAssert(pi == 3)
117
122
│ ╰─ note: in expansion of macro 'myAssert' here
118
123
╭─── #myAssert ───────────────────────────────────────────────────────
119
124
│1 │ let __a = pi
@@ -123,7 +128,7 @@ final class GroupedDiagnosticsFormatterTests: XCTestCase {
123
128
│4 │ fatalError( " assertion failed: pi != 3 " )
124
129
│5 │ }
125
130
╰─────────────────────────────────────────────────────────────────────
126
- 3 │ print( " hello "
131
+ 6 │ print( " hello "
127
132
│ ╰─ error: expected ')' to end function call
128
133
129
134
"""
@@ -180,7 +185,7 @@ final class GroupedDiagnosticsFormatterTests: XCTestCase {
180
185
AssertStringsEqualWithDiff (
181
186
annotated,
182
187
"""
183
- === main.swift ===
188
+ === main.swift:2 ===
184
189
1 │ let pi = 3.14159
185
190
2 │ #myAssert(pi == 3)
186
191
│ ╰─ note: in expansion of macro 'myAssert' here
You can’t perform that action at this time.
0 commit comments