Skip to content

Commit 5594b98

Browse files
authored
Merge pull request #1374 from DougGregor/diagnostics-formatter-diag-kinds
2 parents d1d30e4 + 35f39de commit 5594b98

File tree

4 files changed

+28
-28
lines changed

4 files changed

+28
-28
lines changed

Sources/SwiftDiagnostics/DiagnosticsFormatter.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -327,20 +327,20 @@ public struct DiagnosticsFormatter {
327327
/// Annotates the given ``DiagnosticMessage`` with an appropriate ANSI color code (if the value of the `colorize`
328328
/// property is `true`) and returns the result as a printable string.
329329
private func colorizeIfRequested(_ message: DiagnosticMessage) -> String {
330-
guard colorize else {
331-
return message.message
332-
}
333-
334330
switch message.severity {
335331
case .error:
336332
let annotation = ANSIAnnotation(color: .red, trait: .bold)
337-
return annotation.applied(to: "error: \(message.message)")
333+
return colorizeIfRequested("error: \(message.message)", annotation: annotation)
334+
338335
case .warning:
339336
let color = ANSIAnnotation(color: .yellow)
340-
let prefix = color.withTrait(.bold).applied(to: "warning: ")
341-
return prefix + color.applied(to: message.message)
337+
let prefix = colorizeIfRequested("warning: ", annotation: color.withTrait(.bold))
338+
339+
return prefix + colorizeIfRequested(message.message, annotation: color);
342340
case .note:
343-
return message.message
341+
let color = ANSIAnnotation(color: .default, trait: .bold)
342+
let prefix = colorizeIfRequested("note: ", annotation: color)
343+
return prefix + message.message
344344
}
345345
}
346346

Tests/SwiftDiagnosticsTest/DiagnosticsFormatterTests.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ final class DiagnosticsFormatterTests: XCTestCase {
3030
"""
3131
let expectedOutput = """
3232
1 │ var foo = bar +
33-
∣ ╰─ expected expression after operator
33+
∣ ╰─ error: expected expression after operator
3434
3535
"""
3636
AssertStringsEqualWithDiff(annotate(source: source), expectedOutput)
@@ -42,9 +42,9 @@ final class DiagnosticsFormatterTests: XCTestCase {
4242
"""
4343
let expectedOutput = """
4444
1 │ foo.[].[].[]
45-
∣ │ │ ╰─ expected name in member access
46-
∣ │ ╰─ expected name in member access
47-
∣ ╰─ expected name in member access
45+
∣ │ │ ╰─ error: expected name in member access
46+
∣ │ ╰─ error: expected name in member access
47+
∣ ╰─ error: expected name in member access
4848
4949
"""
5050
AssertStringsEqualWithDiff(annotate(source: source), expectedOutput)
@@ -68,14 +68,14 @@ final class DiagnosticsFormatterTests: XCTestCase {
6868
2 │ i = 2
6969
3 │ i = foo(
7070
4 │ i = 4
71-
∣ ╰─ expected ')' to end function call
71+
∣ ╰─ error: expected ')' to end function call
7272
5 │ i = 5
7373
6 │ i = 6
7474
7575
9 │ i = 9
7676
10 │ i = 10
7777
11 │ i = bar(
78-
∣ ╰─ expected value and ')' to end function call
78+
∣ ╰─ error: expected value and ')' to end function call
7979
8080
"""
8181
AssertStringsEqualWithDiff(annotate(source: source), expectedOutput)
@@ -86,8 +86,8 @@ final class DiagnosticsFormatterTests: XCTestCase {
8686

8787
let expectedOutput = """
8888
1 │ t as (..)
89-
∣ ├─ expected type in tuple type
90-
∣ ╰─ unexpected code '..' in tuple type
89+
∣ ├─ error: expected type in tuple type
90+
∣ ╰─ error: unexpected code '..' in tuple type
9191
9292
"""
9393

Tests/SwiftDiagnosticsTest/GroupDiagnosticsFormatterTests.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -114,17 +114,17 @@ final class GroupedDiagnosticsFormatterTests: XCTestCase {
114114
=== main.swift ===
115115
1 │ let pi = 3.14159
116116
2 │ #myAssert(pi == 3)
117-
∣ ╰─ in expansion of macro 'myAssert' here
117+
∣ ╰─ note: in expansion of macro 'myAssert' here
118118
╭─── #myAssert ───────────────────────────────────────────────────────
119119
│1 │ let __a = pi
120120
│2 │ let __b = 3
121121
│3 │ if !(__a == __b) {
122-
│ ∣ ╰─ no matching operator '==' for types 'Double' and 'Int'
122+
│ ∣ ╰─ error: no matching operator '==' for types 'Double' and 'Int'
123123
│4 │ fatalError("assertion failed: pi != 3")
124124
│5 │ }
125125
╰─────────────────────────────────────────────────────────────────────
126126
3 │ print("hello"
127-
∣ ╰─ expected ')' to end function call
127+
∣ ╰─ error: expected ')' to end function call
128128
129129
"""
130130
)
@@ -183,21 +183,21 @@ final class GroupedDiagnosticsFormatterTests: XCTestCase {
183183
=== main.swift ===
184184
1 │ let pi = 3.14159
185185
2 │ #myAssert(pi == 3)
186-
∣ ╰─ in expansion of macro 'myAssert' here
186+
∣ ╰─ note: in expansion of macro 'myAssert' here
187187
╭─── #myAssert ───────────────────────────────────────────────────────
188188
│1 │ let __a = pi
189189
│2 │ let __b = 3
190190
│3 │ if #invertedEqualityCheck(__a, __b) {
191-
│ ∣ ╰─ in expansion of macro 'invertedEqualityCheck' here
191+
│ ∣ ╰─ note: in expansion of macro 'invertedEqualityCheck' here
192192
│ ╭─── #invertedEqualityCheck ───────────────────────────────────────
193193
│ │1 │ !(__a == __b)
194-
│ │ ∣ ╰─ no matching operator '==' for types 'Double' and 'Int'
194+
│ │ ∣ ╰─ error: no matching operator '==' for types 'Double' and 'Int'
195195
│ ╰──────────────────────────────────────────────────────────────────
196196
│4 │ fatalError("assertion failed: pi != 3")
197197
│5 │ }
198198
╰─────────────────────────────────────────────────────────────────────
199199
3 │ print("hello"
200-
∣ ╰─ expected ')' to end function call
200+
∣ ╰─ error: expected ')' to end function call
201201
202202
"""
203203
)

Tests/SwiftSyntaxBuilderTest/StringInterpolationTests.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ final class StringInterpolationTests: XCTestCase {
418418
"""
419419
420420
1 │ /*comment*/ invalid /*comm*/
421-
∣ ╰─ unexpected trivia 'invalid'
421+
∣ ╰─ error: unexpected trivia 'invalid'
422422
423423
"""
424424
)
@@ -435,8 +435,8 @@ final class StringInterpolationTests: XCTestCase {
435435
"""
436436
437437
1 │ return 1
438-
∣ │ ╰─ expected declaration
439-
∣ ╰─ unexpected code 'return 1' before declaration
438+
∣ │ ╰─ error: expected declaration
439+
∣ ╰─ error: unexpected code 'return 1' before declaration
440440
441441
"""
442442
)
@@ -453,8 +453,8 @@ final class StringInterpolationTests: XCTestCase {
453453
"""
454454
455455
1 │ struct Foo {}
456-
∣ │ ╰─ expected statement
457-
∣ ╰─ unexpected code 'struct Foo {}' before statement
456+
∣ │ ╰─ error: expected statement
457+
∣ ╰─ error: unexpected code 'struct Foo {}' before statement
458458
459459
"""
460460
)

0 commit comments

Comments
 (0)