Skip to content

Commit d722cfc

Browse files
authored
Merge pull request #2587 from rintaro/6.0-diagnostics-ascii
[6.0][Diagnostics] Stop using unicode line characters
2 parents 7a8c1ef + b5693d6 commit d722cfc

File tree

5 files changed

+94
-94
lines changed

5 files changed

+94
-94
lines changed

Sources/SwiftDiagnostics/DiagnosticsFormatter.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -268,13 +268,13 @@ public struct DiagnosticsFormatter {
268268
// line numbers should be right aligned
269269
let lineNumberString = String(lineNumber)
270270
let leadingSpaces = String(repeating: " ", count: maxNumberOfDigits - lineNumberString.count)
271-
let linePrefix = "\(leadingSpaces)\(diagnosticDecorator.decorateBufferOutline("\(lineNumberString) ")) "
271+
let linePrefix = "\(leadingSpaces)\(diagnosticDecorator.decorateBufferOutline("\(lineNumberString) |")) "
272272

273273
// If necessary, print a line that indicates that there was lines skipped in the source code
274274
if hasLineBeenSkipped && !annotatedSource.isEmpty {
275275
let lineMissingInfoLine =
276276
indentString + String(repeating: " ", count: maxNumberOfDigits)
277-
+ " \(diagnosticDecorator.decorateBufferOutline(""))"
277+
+ " \(diagnosticDecorator.decorateBufferOutline(":"))"
278278
annotatedSource.append("\(lineMissingInfoLine)\n")
279279
}
280280
hasLineBeenSkipped = false
@@ -313,20 +313,20 @@ public struct DiagnosticsFormatter {
313313
// compute the string that is shown before each message
314314
var preMessage =
315315
indentString + String(repeating: " ", count: maxNumberOfDigits) + " "
316-
+ diagnosticDecorator.decorateBufferOutline("")
316+
+ diagnosticDecorator.decorateBufferOutline("|")
317317
for c in 0..<column {
318318
if columnsWithDiagnostics.contains(c) {
319-
preMessage.append("")
319+
preMessage.append("|")
320320
} else {
321321
preMessage.append(" ")
322322
}
323323
}
324324

325325
for diag in diags.dropLast(1) {
326-
annotatedSource.append("\(preMessage)├─ \(diagnosticDecorator.decorateDiagnosticMessage(diag.diagMessage))\n")
326+
annotatedSource.append("\(preMessage)|- \(diagnosticDecorator.decorateDiagnosticMessage(diag.diagMessage))\n")
327327
}
328328
annotatedSource.append(
329-
"\(preMessage)╰─ \(diagnosticDecorator.decorateDiagnosticMessage(diags.last!.diagMessage))\n"
329+
"\(preMessage)`- \(diagnosticDecorator.decorateDiagnosticMessage(diags.last!.diagMessage))\n"
330330
)
331331
}
332332

Sources/SwiftDiagnostics/GroupedDiagnostics.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ extension GroupedDiagnostics {
193193
let childSource = annotateSource(
194194
childBufferID,
195195
formatter: formatter,
196-
indentString: indentString + String(repeating: " ", count: childPadding) + ""
196+
indentString: indentString + String(repeating: " ", count: childPadding) + "|"
197197
)
198198

199199
childSources[sourceFiles[childBufferID.id].parent!.1, default: ""].append(childSource)
@@ -232,7 +232,7 @@ extension GroupedDiagnostics {
232232
"expanded code originates here",
233233
basedOnSeverity: .note
234234
)
235-
prefixString += "╰─ \(bufferLoc.file):\(bufferLoc.line):\(bufferLoc.column): \(decoratedMessage)\n"
235+
prefixString += "`- \(bufferLoc.file):\(bufferLoc.line):\(bufferLoc.column): \(decoratedMessage)\n"
236236
}
237237
}
238238
} else {
@@ -249,16 +249,16 @@ extension GroupedDiagnostics {
249249
let extraLengthNeeded = targetLineLength - padding.count - sourceFile.displayName.count - 6
250250
let boxSuffix: String
251251
if extraLengthNeeded > 0 {
252-
boxSuffix = diagnosticDecorator.decorateBufferOutline(String(repeating: "", count: extraLengthNeeded))
252+
boxSuffix = diagnosticDecorator.decorateBufferOutline(String(repeating: "-", count: extraLengthNeeded))
253253
} else {
254254
boxSuffix = ""
255255
}
256256

257257
prefixString =
258-
diagnosticDecorator.decorateBufferOutline(padding + "╭─── ") + sourceFile.displayName + " " + boxSuffix + "\n"
258+
diagnosticDecorator.decorateBufferOutline(padding + "+--- ") + sourceFile.displayName + " " + boxSuffix + "\n"
259259
suffixString =
260260
diagnosticDecorator.decorateBufferOutline(
261-
padding + "╰───" + String(repeating: "", count: sourceFile.displayName.count + 2)
261+
padding + "+---" + String(repeating: "-", count: sourceFile.displayName.count + 2)
262262
) + boxSuffix + "\n"
263263
}
264264

Tests/SwiftDiagnosticsTest/GroupDiagnosticsFormatterTests.swift

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,9 @@ final class GroupedDiagnosticsFormatterTests: XCTestCase {
7777
annotated,
7878
"""
7979
other.swift:123:17: error: consecutive statements on a line must be separated by newline or ';'
80-
1 #sourceLocation(file: "other.swift", line: 123)
81-
2 let pi = 3.14159 x
82-
╰─ error: consecutive statements on a line must be separated by newline or ';'
80+
1 | #sourceLocation(file: "other.swift", line: 123)
81+
2 | let pi = 3.14159 x
82+
| `- error: consecutive statements on a line must be separated by newline or ';'
8383
8484
"""
8585
)
@@ -134,20 +134,20 @@ final class GroupedDiagnosticsFormatterTests: XCTestCase {
134134
annotated,
135135
"""
136136
main.swift:6:14: error: expected ')' to end function call
137-
3 // test
138-
4 let pi = 3.14159
139-
5 #myAssert(pi == 3)
140-
│ ╰─ note: in expansion of macro 'myAssert' here
141-
╭─── #myAssert ───────────────────────────────────────────────────────
142-
│1 │ let __a = pi
143-
│2 │ let __b = 3
144-
│3 │ if !(__a == __b) {
145-
│ │ ╰─ error: no matching operator '==' for types 'Double' and 'Int'
146-
│4 │ fatalError("assertion failed: pi != 3")
147-
│5 │ }
148-
╰─────────────────────────────────────────────────────────────────────
149-
6 print("hello"
150-
╰─ error: expected ')' to end function call
137+
3 | // test
138+
4 | let pi = 3.14159
139+
5 | #myAssert(pi == 3)
140+
| `- note: in expansion of macro 'myAssert' here
141+
+--- #myAssert -------------------------------------------------------
142+
|1 | let __a = pi
143+
|2 | let __b = 3
144+
|3 | if !(__a == __b) {
145+
| | `- error: no matching operator '==' for types 'Double' and 'Int'
146+
|4 | fatalError("assertion failed: pi != 3")
147+
|5 | }
148+
+---------------------------------------------------------------------
149+
6 | print("hello"
150+
| `- error: expected ')' to end function call
151151
152152
"""
153153
)
@@ -212,23 +212,23 @@ final class GroupedDiagnosticsFormatterTests: XCTestCase {
212212
annotated,
213213
"""
214214
#invertedEqualityCheck:1:7: error: no matching operator '==' for types 'Double' and 'Int'
215-
╰─ main.swift:2:1: note: expanded code originates here
216-
1 let pi = 3.14159
217-
2 #myAssert(pi == 3)
218-
│ ╰─ note: in expansion of macro 'myAssert' here
219-
╭─── #myAssert ───────────────────────────────────────────────────────
220-
│1 │ let __a = pi
221-
│2 │ let __b = 3
222-
│3 │ if #invertedEqualityCheck(__a, __b) {
223-
│ │ ╰─ note: in expansion of macro 'invertedEqualityCheck' here
224-
│ ╭─── #invertedEqualityCheck ───────────────────────────────────────
225-
│ │1 │ !(__a == __b)
226-
│ │ │ ╰─ error: no matching operator '==' for types 'Double' and 'Int'
227-
│ ╰──────────────────────────────────────────────────────────────────
228-
│4 │ fatalError("assertion failed: pi != 3")
229-
│5 │ }
230-
╰─────────────────────────────────────────────────────────────────────
231-
3 print("hello")
215+
`- main.swift:2:1: note: expanded code originates here
216+
1 | let pi = 3.14159
217+
2 | #myAssert(pi == 3)
218+
| `- note: in expansion of macro 'myAssert' here
219+
+--- #myAssert -------------------------------------------------------
220+
|1 | let __a = pi
221+
|2 | let __b = 3
222+
|3 | if #invertedEqualityCheck(__a, __b) {
223+
| | `- note: in expansion of macro 'invertedEqualityCheck' here
224+
| +--- #invertedEqualityCheck ---------------------------------------
225+
| |1 | !(__a == __b)
226+
| | | `- error: no matching operator '==' for types 'Double' and 'Int'
227+
| +------------------------------------------------------------------
228+
|4 | fatalError("assertion failed: pi != 3")
229+
|5 | }
230+
+---------------------------------------------------------------------
231+
3 | print("hello")
232232
233233
"""
234234
)

Tests/SwiftDiagnosticsTest/ParserDiagnosticsFormatterIntegrationTests.swift

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ final class ParserDiagnosticsFormatterIntegrationTests: XCTestCase {
2929
var foo = bar +
3030
"""
3131
let expectedOutput = """
32-
1 var foo = bar +
33-
╰─ error: expected expression after operator
32+
1 | var foo = bar +
33+
| `- error: expected expression after operator
3434
3535
"""
3636
assertStringsEqualWithDiff(annotate(source: source), expectedOutput)
@@ -41,10 +41,10 @@ final class ParserDiagnosticsFormatterIntegrationTests: XCTestCase {
4141
foo.[].[].[]
4242
"""
4343
let expectedOutput = """
44-
1 foo.[].[].[]
45-
│ │ ╰─ error: expected name in member access
46-
│ ╰─ error: expected name in member access
47-
╰─ error: expected name in member access
44+
1 | foo.[].[].[]
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)
@@ -65,17 +65,17 @@ final class ParserDiagnosticsFormatterIntegrationTests: XCTestCase {
6565
i = bar(
6666
"""
6767
let expectedOutput = """
68-
2 i = 2
69-
3 i = foo(
70-
4 i = 4
71-
╰─ error: expected ')' to end function call
72-
5 i = 5
73-
6 i = 6
74-
75-
9 i = 9
76-
10 i = 10
77-
11 i = bar(
78-
╰─ error: expected value and ')' to end function call
68+
2 | i = 2
69+
3 | i = foo(
70+
4 | i = 4
71+
| `- error: expected ')' to end function call
72+
5 | i = 5
73+
6 | i = 6
74+
:
75+
9 | i = 9
76+
10 | i = 10
77+
11 | i = bar(
78+
| `- error: expected value and ')' to end function call
7979
8080
"""
8181
assertStringsEqualWithDiff(annotate(source: source), expectedOutput)
@@ -85,9 +85,9 @@ final class ParserDiagnosticsFormatterIntegrationTests: XCTestCase {
8585
let source = "t as (..)"
8686

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

@@ -100,8 +100,8 @@ final class ParserDiagnosticsFormatterIntegrationTests: XCTestCase {
100100
"""
101101

102102
let expectedOutput = """
103-
\u{001B}[0;36m1 \u{001B}[0;0m var foo = bar +
104-
\u{001B}[0;36m\u{001B}[0;0m ╰─ \u{001B}[1;31merror: \u{001B}[1;39mexpected expression after operator\u{001B}[0;0m
103+
\u{001B}[0;36m1 |\u{001B}[0;0m var foo = bar +
104+
\u{001B}[0;36m|\u{001B}[0;0m `- \u{001B}[1;31merror: \u{001B}[1;39mexpected expression after operator\u{001B}[0;0m
105105
106106
"""
107107
assertStringsEqualWithDiff(annotate(source: source, colorize: true), expectedOutput)
@@ -112,10 +112,10 @@ final class ParserDiagnosticsFormatterIntegrationTests: XCTestCase {
112112
foo.[].[].[]
113113
"""
114114
let expectedOutput = """
115-
\u{001B}[0;36m1 \u{001B}[0;0m foo.[].[].[]
116-
\u{001B}[0;36m\u{001B}[0;0m │ │ ╰─ \u{001B}[1;31merror: \u{001B}[1;39mexpected name in member access\u{001B}[0;0m
117-
\u{001B}[0;36m\u{001B}[0;0m │ ╰─ \u{001B}[1;31merror: \u{001B}[1;39mexpected name in member access\u{001B}[0;0m
118-
\u{001B}[0;36m\u{001B}[0;0m ╰─ \u{001B}[1;31merror: \u{001B}[1;39mexpected name in member access\u{001B}[0;0m
115+
\u{001B}[0;36m1 |\u{001B}[0;0m foo.[].[].[]
116+
\u{001B}[0;36m|\u{001B}[0;0m | | `- \u{001B}[1;31merror: \u{001B}[1;39mexpected name in member access\u{001B}[0;0m
117+
\u{001B}[0;36m|\u{001B}[0;0m | `- \u{001B}[1;31merror: \u{001B}[1;39mexpected name in member access\u{001B}[0;0m
118+
\u{001B}[0;36m|\u{001B}[0;0m `- \u{001B}[1;31merror: \u{001B}[1;39mexpected name in member access\u{001B}[0;0m
119119
120120
"""
121121
assertStringsEqualWithDiff(annotate(source: source, colorize: true), expectedOutput)
@@ -127,9 +127,9 @@ final class ParserDiagnosticsFormatterIntegrationTests: XCTestCase {
127127
"""
128128

129129
let expectedOutput = """
130-
\u{001B}[0;36m1 \u{001B}[0;0m for \u{001B}[4;39m(i\u{001B}[0;0m \u{001B}[4;39m= 🐮; i != 👩‍👩‍👦‍👦; i += 1)\u{001B}[0;0m { }
131-
\u{001B}[0;36m\u{001B}[0;0m ╰─ \u{001B}[1;31merror: \u{001B}[1;39mexpected ')' to end tuple pattern\u{001B}[0;0m
132-
\u{001B}[0;36m\u{001B}[0;0m ╰─ \u{001B}[1;31merror: \u{001B}[1;39mC-style for statement has been removed in Swift 3\u{001B}[0;0m
130+
\u{001B}[0;36m1 |\u{001B}[0;0m for \u{001B}[4;39m(i\u{001B}[0;0m \u{001B}[4;39m= 🐮; i != 👩‍👩‍👦‍👦; i += 1)\u{001B}[0;0m { }
131+
\u{001B}[0;36m|\u{001B}[0;0m | `- \u{001B}[1;31merror: \u{001B}[1;39mexpected ')' to end tuple pattern\u{001B}[0;0m
132+
\u{001B}[0;36m|\u{001B}[0;0m `- \u{001B}[1;31merror: \u{001B}[1;39mC-style for statement has been removed in Swift 3\u{001B}[0;0m
133133
134134
"""
135135

@@ -142,9 +142,9 @@ final class ParserDiagnosticsFormatterIntegrationTests: XCTestCase {
142142
"""
143143

144144
let expectedOutput = """
145-
1 let _ : Float -> Int
146-
╰─ error: expected ')' in function type
147-
╰─ error: expected '(' to start function type
145+
1 | let _ : Float -> Int
146+
| | `- error: expected ')' in function type
147+
| `- error: expected '(' to start function type
148148
149149
"""
150150

@@ -159,11 +159,11 @@ final class ParserDiagnosticsFormatterIntegrationTests: XCTestCase {
159159
"""
160160

161161
let expectedOutput = """
162-
1 func o() {
163-
2 }👨‍👩‍👧‍👦}
164-
│ │╰─ error: extraneous braces at top level
165-
│ ╰─ error: consecutive statements on a line must be separated by newline or ';'
166-
3 }
162+
1 | func o() {
163+
2 | }👨‍👩‍👧‍👦}
164+
| |`- error: extraneous braces at top level
165+
| `- error: consecutive statements on a line must be separated by newline or ';'
166+
3 | }
167167
168168
"""
169169

@@ -176,8 +176,8 @@ final class ParserDiagnosticsFormatterIntegrationTests: XCTestCase {
176176
"""
177177

178178
let expectedOutput = """
179-
1 let 👨‍👩‍👧‍👦 = ;
180-
╰─ error: expected expression in variable
179+
1 | let 👨‍👩‍👧‍👦 = ;
180+
| `- error: expected expression in variable
181181
182182
"""
183183

Tests/SwiftSyntaxBuilderTest/StringInterpolationTests.swift

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -452,8 +452,8 @@ final class StringInterpolationTests: XCTestCase {
452452
String(describing: error),
453453
"""
454454
455-
1 /*comment*/ invalid /*comm*/
456-
╰─ error: unexpected trivia 'invalid'
455+
1 | /*comment*/ invalid /*comm*/
456+
| `- error: unexpected trivia 'invalid'
457457
458458
"""
459459
)
@@ -470,9 +470,9 @@ final class StringInterpolationTests: XCTestCase {
470470
String(describing: error),
471471
"""
472472
473-
1 return 1
474-
│ │ ╰─ error: expected declaration
475-
│ ╰─ error: unexpected code 'return 1' before declaration
473+
1 | return 1
474+
| | `- error: expected declaration
475+
| `- error: unexpected code 'return 1' before declaration
476476
477477
"""
478478
)
@@ -489,9 +489,9 @@ final class StringInterpolationTests: XCTestCase {
489489
String(describing: error),
490490
"""
491491
492-
1 struct Foo {}
493-
│ │ ╰─ error: expected statement
494-
│ ╰─ error: unexpected code 'struct Foo {}' before statement
492+
1 | struct Foo {}
493+
| | `- error: expected statement
494+
| `- error: unexpected code 'struct Foo {}' before statement
495495
496496
"""
497497
)
@@ -508,8 +508,8 @@ final class StringInterpolationTests: XCTestCase {
508508
String(describing: error),
509509
"""
510510
511-
1
512-
│ ╰─ error: expected declaration
511+
1 |
512+
| `- error: expected declaration
513513
514514
"""
515515
)

0 commit comments

Comments
 (0)