Repository: apple/swift-syntax (swift)

Issue:
Swift error reporting style removed complete `path:line:col` information
### Description

The new error formatting does the following:

```
=== /Users/ktoso/code/swift-project/swift/stdlib/public/core/SIMDVector.swift ===
     ┆
  61 │
  62 │ /// A type that can be used as an element in a SIMD vector.
  63 │ public protocol SIMDScalar {
     ∣                 ├─ warning: protocol 'SIMDScalar' should be declared to refine 'Decodable' due to a same-type constraint on 'Self'
     ∣                 ├─ warning: protocol 'SIMDScalar' should be declared to refine 'Encodable' due to a same-type constraint on 'Self'
     ∣                 ╰─ warning: protocol 'SIMDScalar' should be declared to refine 'Hashable' due to a same-type constraint on 'Self'
```

which is missing a crucial feature of the previous format, including the:

```
/Users/ktoso/code/swift-project/swift/stdlib/public/core/SIMDVector.swift:61:16
```

information as one string where the error was located.

This is important because terminals and IDEs are able to understand this format and e.g. in iterm2 you can click such "path:line:col" to open up your editor at the exact line where the error was simplifying editing by a lot when working from the terminal (which always do for example).

Including this in the "header" where the fullpath is would be good enough I think 👍 

Thanks in advance for bringing back this info the new formatter is quite pleasant, looking forward to it!

Pull request description:
When printing the filename header for diagnostics, also include the line at which the displqy starts using the standard `:<line number>` format, which is recognized by various tools to quickly go to that source file and line.

Fixes https://github.com/apple/swift-syntax/issues/1385.

Patch:
diff --git a/Sources/SwiftDiagnostics/DiagnosticsFormatter.swift b/Sources/SwiftDiagnostics/DiagnosticsFormatter.swift
index ea1c9fd2943..758455853df 100644
--- a/Sources/SwiftDiagnostics/DiagnosticsFormatter.swift
+++ b/Sources/SwiftDiagnostics/DiagnosticsFormatter.swift
@@ -227,7 +227,13 @@ public struct DiagnosticsFormatter {
     // If there was a filename, add it first.
     if let fileName = fileName {
       let header = colorizeBufferOutline("===")
-      annotatedSource.append("\(indentString)\(header) \(fileName) \(header)\n")
+      let firstLine =
+        1
+        + (annotatedSourceLines.enumerated().first { (lineIndex, sourceLine) in
+          !sourceLine.isFreeOfAnnotations
+        }?.offset ?? 0)
+
+      annotatedSource.append("\(indentString)\(header) \(fileName):\(firstLine) \(header)\n")
     }
 
     /// Keep track if a line missing char should be printed


Test patch:
diff --git a/Tests/SwiftDiagnosticsTest/GroupDiagnosticsFormatterTests.swift b/Tests/SwiftDiagnosticsTest/GroupDiagnosticsFormatterTests.swift
index f7ff4ff81f4..1ef3f403292 100644
--- a/Tests/SwiftDiagnosticsTest/GroupDiagnosticsFormatterTests.swift
+++ b/Tests/SwiftDiagnosticsTest/GroupDiagnosticsFormatterTests.swift
@@ -80,6 +80,9 @@ final class GroupedDiagnosticsFormatterTests: XCTestCase {
     // Main source file.
     let (mainSourceID, mainSourceMarkers) = group.addTestFile(
       """
+
+
+      // test
       let pi = 3.14159
       1️⃣#myAssert(pi == 3)
       print("hello"
@@ -111,9 +114,11 @@ final class GroupedDiagnosticsFormatterTests: XCTestCase {
     AssertStringsEqualWithDiff(
       annotated,
       """
-      === main.swift ===
-      1 │ let pi = 3.14159
-      2 │ #myAssert(pi == 3)
+      === main.swift:5 ===
+        ┆
+      3 │ // test
+      4 │ let pi = 3.14159
+      5 │ #myAssert(pi == 3)
         │ ╰─ note: in expansion of macro 'myAssert' here
         ╭─── #myAssert ───────────────────────────────────────────────────────
         │1 │ let __a = pi
@@ -123,7 +128,7 @@ final class GroupedDiagnosticsFormatterTests: XCTestCase {
         │4 │   fatalError("assertion failed: pi != 3")
         │5 │ }
         ╰─────────────────────────────────────────────────────────────────────
-      3 │ print("hello"
+      6 │ print("hello"
         │              ╰─ error: expected ')' to end function call
 
       """
@@ -180,7 +185,7 @@ final class GroupedDiagnosticsFormatterTests: XCTestCase {
     AssertStringsEqualWithDiff(
       annotated,
       """
-      === main.swift ===
+      === main.swift:2 ===
       1 │ let pi = 3.14159
       2 │ #myAssert(pi == 3)
         │ ╰─ note: in expansion of macro 'myAssert' here