Skip to content

Commit def44c5

Browse files
authored
Merge pull request #63223 from DougGregor/colorize-swift-syntax-diagnostics
Colorize swift syntax diagnostics
2 parents c86c741 + c7b7c4a commit def44c5

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

lib/ASTGen/Sources/ASTGen/Diagnostics.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,13 +244,17 @@ public func addQueuedDiagnostic(
244244
@_cdecl("swift_ASTGen_renderQueuedDiagnostics")
245245
public func renterQueuedDiagnostics(
246246
queuedDiagnosticsPtr: UnsafeMutablePointer<UInt8>,
247+
contextSize: Int,
248+
colorize: Int,
247249
renderedPointer: UnsafeMutablePointer<UnsafePointer<UInt8>?>,
248250
renderedLength: UnsafeMutablePointer<Int>
249251
) {
250252
queuedDiagnosticsPtr.withMemoryRebound(to: QueuedDiagnostics.self, capacity: 1) { queuedDiagnostics in
251253
let renderedStr = DiagnosticsFormatter.annotatedSource(
252254
tree: queuedDiagnostics.pointee.sourceFile,
253-
diags: queuedDiagnostics.pointee.diagnostics
255+
diags: queuedDiagnostics.pointee.diagnostics,
256+
contextSize: contextSize,
257+
colorize: colorize != 0
254258
)
255259

256260
(renderedPointer.pointee, renderedLength.pointee) =

lib/Frontend/PrintingDiagnosticConsumer.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ extern "C" void swift_ASTGen_addQueuedDiagnostic(
4242
const void *sourceLoc
4343
);
4444
extern "C" void swift_ASTGen_renderQueuedDiagnostics(
45-
void *queued, char **outBuffer, ptrdiff_t *outBufferLength);
45+
void *queued, ptrdiff_t contextSize, ptrdiff_t colorize,
46+
char **outBuffer, ptrdiff_t *outBufferLength);
4647

4748
// FIXME: Hack because we cannot easily get to the already-parsed source
4849
// file from here. Fix this egregious oversight!
@@ -1106,7 +1107,8 @@ void PrintingDiagnosticConsumer::flush(bool includeTrailingBreak) {
11061107
char *renderedString = nullptr;
11071108
ptrdiff_t renderedStringLen = 0;
11081109
swift_ASTGen_renderQueuedDiagnostics(
1109-
queuedDiagnostics, &renderedString, &renderedStringLen);
1110+
queuedDiagnostics, /*contextSize=*/2, ForceColors ? 1 : 0,
1111+
&renderedString, &renderedStringLen);
11101112
if (renderedString) {
11111113
Stream.write(renderedString, renderedStringLen);
11121114
}

0 commit comments

Comments
 (0)