Skip to content

Commit 43e9fe4

Browse files
committed
Refactor DiagnosticsFormatter and extend its functionality
This commit refactors the existing code for `DiagnosticsFormatter` and introduces several new features, complete with documentation and unit tests. Key Enhancements: 1. Nested Diagnostic Support: Enhanced to include not only top-level diagnostics but also related notes, improving the debugging experience. 2. Custom Decorators: Incorporate the `DiagnosticDecorator` protocol, allowing for custom formatting and styling of diagnostic output. 3. Context Size Control: Added options to control the `ContextSize`, providing more flexibility in how much source code context is displayed around each diagnostic. Documentation: - Comprehensive documentation added, detailing the purpose, usage examples, and future developments for `DiagnosticsFormatter`. Testing: - Added robust unit tests to validate the new features and ensure reliability. This refactor and feature addition make `DiagnosticsFormatter` a more versatile and developer-friendly tool for debugging and understanding Swift code.
1 parent e77b169 commit 43e9fe4

15 files changed

+1119
-291
lines changed

Sources/SwiftDiagnostics/DiagnosticDecorators/ANSIDiagnosticDecorator.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
extension DiagnosticDecorator where Self == ANSIDiagnosticDecorator {
1414
/// - SeeAlso: ``ANSIDiagnosticDecorator``
15-
static var ANSI: Self {
15+
public static var ANSI: Self {
1616
Self()
1717
}
1818
}
@@ -21,9 +21,9 @@ extension DiagnosticDecorator where Self == ANSIDiagnosticDecorator {
2121
/// buffer outlines, and code highlights—by applying severity-based prefixes and ANSI color codes.
2222
///
2323
/// This decorator uses ANSI codes—control characters specialized for text formatting in terminals—to provide visual cues.
24-
@_spi(Testing) public struct ANSIDiagnosticDecorator: DiagnosticDecorator {
24+
public struct ANSIDiagnosticDecorator: DiagnosticDecorator {
2525

26-
@_spi(Testing) public init() {}
26+
public init() {}
2727

2828
/// Decorates a diagnostic message by appending a severity-based prefix and applying ANSI color codes.
2929
///

Sources/SwiftDiagnostics/DiagnosticDecorators/BasicDiagnosticDecorator.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
extension DiagnosticDecorator where Self == BasicDiagnosticDecorator {
1414
/// - Seealso: ``BasicDiagnosticDecorator``
15-
static var basic: Self {
15+
public static var basic: Self {
1616
Self()
1717
}
1818
}
@@ -21,9 +21,9 @@ extension DiagnosticDecorator where Self == BasicDiagnosticDecorator {
2121
/// buffer outlines, and code highlights—by appending severity-based prefixes.
2222
///
2323
/// Unlike `ANSIDiagnosticDecorator`, this decorator does not use ANSI color codes and solely relies on textual cues.
24-
@_spi(Testing) public struct BasicDiagnosticDecorator: DiagnosticDecorator {
24+
public struct BasicDiagnosticDecorator: DiagnosticDecorator {
2525

26-
@_spi(Testing) public init() {}
26+
public init() {}
2727

2828
/// Decorates a diagnostic message by appending a severity-based prefix.
2929
///

Sources/SwiftDiagnostics/DiagnosticDecorators/DiagnosticDecorator.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
/// The protocol is designed to be easily customizable. Developers can create their own entities that conform
2929
/// to `DiagnosticDecorator` to implement custom decorating logic. This allows for different visual representations,
3030
/// such as using ANSI colors, underscores, emoji-based or other markers, for diagnostics in source code.
31-
protocol DiagnosticDecorator {
31+
public protocol DiagnosticDecorator {
3232
/// Decorates a diagnostic message based on its severity level.
3333
///
3434
/// Implementations are expected to prepend a severity-specific prefix (e.g., "error: ", "warning: ") to the diagnostic message.

0 commit comments

Comments
 (0)