Skip to content

Commit d87e913

Browse files
committed
[Diag-Experimental-Formatting] Custom formatting for Xcode editor placeholders
1 parent ad3fa79 commit d87e913

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

lib/Frontend/PrintingDiagnosticConsumer.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,22 @@ namespace {
194194
bool maybePrintInsertionAfter(int Byte, raw_ostream &Out) {
195195
for (auto fixIt : FixIts) {
196196
if ((int)fixIt.EndByte - 1 == Byte) {
197-
Out.changeColor(ColoredStream::Colors::GREEN, true);
198-
Out << fixIt.Text;
197+
Out.changeColor(ColoredStream::Colors::GREEN, /*bold*/ true);
198+
for (unsigned i = 0; i < fixIt.Text.size(); ++i) {
199+
// Invert text colors for editor placeholders.
200+
if (i + 1 < fixIt.Text.size() && fixIt.Text.substr(i, 2) == "<#") {
201+
Out.changeColor(ColoredStream::Colors::GREEN, /*bold*/ true,
202+
/*background*/ true);
203+
++i;
204+
} else if (i + 1 < fixIt.Text.size() &&
205+
fixIt.Text.substr(i, 2) == "#>") {
206+
Out.changeColor(ColoredStream::Colors::GREEN, /*bold*/ true,
207+
/*background*/ false);
208+
++i;
209+
} else {
210+
Out << fixIt.Text[i];
211+
}
212+
}
199213
Out.resetColor();
200214
return true;
201215
}

test/diagnostics/pretty-printed-diagnostics.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ extension A {
3434

3535
let abc = "👍
3636
37+
let x = {
38+
let y = 1
39+
return y
40+
}
41+
3742
// Test fallback for non-ASCII characters.
3843
// CHECK: SOURCE_DIR/test/diagnostics/pretty-printed-diagnostics.swift:35:11
3944
// CHECK: 34 |
@@ -114,6 +119,11 @@ let abc = "👍
114119
// CHECK: | ^ note: Remove '=' to make 'x' a computed property [remove '= '] [replace 'let' with 'var']
115120
// CHECK: 33 | }
116121

122+
// CHECK: SOURCE_DIR/test/diagnostics/pretty-printed-diagnostics.swift:37:9
123+
// CHECK: 36 |
124+
// CHECK: 37 | let x = { () -> Result in
125+
// CHECK: | ^ error: unable to infer complex closure return type; add explicit type to disambiguate
126+
// CHECK: 38 | let y = 1
117127

118128
// CHECK: SOURCE_DIR/test/diagnostics/pretty-printed-diagnostics.swift:6:5
119129
// CHECK: 5 | func foo(a: Int, b: Int) {

0 commit comments

Comments
 (0)