# RFC: Diagnostics formatting for diagnostic messages without relation to source syntax

**URL:** <https://forums.swift.org/t/rfc-diagnostics-formatting-for-diagnostic-messages-without-relation-to-source-syntax/79321>\
**Category:** Swift Syntax\
**Created:** [April 17, 2025, 12:59am UTC](https://forums.swift.org/t/rfc-diagnostics-formatting-for-diagnostic-messages-without-relation-to-source-syntax/79321 "2025-04-17T00:59:10Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Douglas\_Gregor](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/douglas_gregor/32/1362_2.png) [@Douglas\_Gregor](https://forums.swift.org/u/Douglas_Gregor)\
**Post date:** [April 17, 2025, 12:59am UTC](https://forums.swift.org/t/rfc-diagnostics-formatting-for-diagnostic-messages-without-relation-to-source-syntax/79321/1 "2025-04-17T00:59:10Z")

</div>

- **Link to PR** : [Add a new API DiagnosticsFormatter.formattedMessage(\_:) for messages without source location info by DougGregor · Pull Request #3059 · swiftlang/swift-syntax · GitHub](https://github.com/swiftlang/swift-syntax/pull/3059)
- **Summary** : Some tools want to use the diagnostics formatter to produce diagnostics that don't relate to source code, or for which the source code isn't available. Add an that API allows them to do so while maintaining consistent presentation.
- **API Changes** : The API is this:

```swift
extension DiagnosticsFormatter {
  /// Produce a string that formats the given diagnostic message with any
  /// source-location information.
  public func formattedMessage(_ message: some DiagnosticMessage) -> String
}

```

- **Migration** : New API, no migration needed.

For reference, the compiler's adoption of this API is at [[Diagnostics] Use the swift-syntax formatting for invalid source locations, too by DougGregor · Pull Request #80874 · swiftlang/swift · GitHub](https://github.com/swiftlang/swift/pull/80874).

Doug

---

<div class="post-metadata">

**Author:** ![ahoppen](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/ahoppen/32/36046_2.png) [@ahoppen](https://forums.swift.org/u/ahoppen)\
**Post date:** [April 17, 2025, 5:04pm UTC](https://forums.swift.org/t/rfc-diagnostics-formatting-for-diagnostic-messages-without-relation-to-source-syntax/79321/2 "2025-04-17T17:04:41Z")

</div>

Looks good to me, thank you, Doug.
