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 {
227227 // If there was a filename, add it first.
228228 if let fileName = fileName {
229229 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 " )
231237 }
232238
233239 /// 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 {
8080 // Main source file.
8181 let ( mainSourceID, mainSourceMarkers) = group. addTestFile (
8282 """
83+
84+
85+ // test
8386 let pi = 3.14159
8487 1️⃣#myAssert(pi == 3)
8588 print( " hello "
@@ -111,9 +114,11 @@ final class GroupedDiagnosticsFormatterTests: XCTestCase {
111114 AssertStringsEqualWithDiff (
112115 annotated,
113116 """
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)
117122 │ ╰─ note: in expansion of macro 'myAssert' here
118123 ╭─── #myAssert ───────────────────────────────────────────────────────
119124 │1 │ let __a = pi
@@ -123,7 +128,7 @@ final class GroupedDiagnosticsFormatterTests: XCTestCase {
123128 │4 │ fatalError( " assertion failed: pi != 3 " )
124129 │5 │ }
125130 ╰─────────────────────────────────────────────────────────────────────
126- 3 │ print( " hello "
131+ 6 │ print( " hello "
127132 │ ╰─ error: expected ')' to end function call
128133
129134 """
@@ -180,7 +185,7 @@ final class GroupedDiagnosticsFormatterTests: XCTestCase {
180185 AssertStringsEqualWithDiff (
181186 annotated,
182187 """
183- === main.swift ===
188+ === main.swift:2 ===
184189 1 │ let pi = 3.14159
185190 2 │ #myAssert(pi == 3)
186191 │ ╰─ note: in expansion of macro 'myAssert' here
You can’t perform that action at this time.
0 commit comments