Merge pull request #63223 from DougGregor/colorize-swift-syntax-diagnostics

Colorize swift syntax diagnostics
This commit is contained in:
swift-ci
2023-01-26 01:16:31 -08:00
committed by GitHub
2 changed files with 9 additions and 3 deletions

View File

@@ -244,13 +244,17 @@ public func addQueuedDiagnostic(
@_cdecl("swift_ASTGen_renderQueuedDiagnostics")
public func renterQueuedDiagnostics(
queuedDiagnosticsPtr: UnsafeMutablePointer<UInt8>,
contextSize: Int,
colorize: Int,
renderedPointer: UnsafeMutablePointer<UnsafePointer<UInt8>?>,
renderedLength: UnsafeMutablePointer<Int>
) {
queuedDiagnosticsPtr.withMemoryRebound(to: QueuedDiagnostics.self, capacity: 1) { queuedDiagnostics in
let renderedStr = DiagnosticsFormatter.annotatedSource(
tree: queuedDiagnostics.pointee.sourceFile,
diags: queuedDiagnostics.pointee.diagnostics
diags: queuedDiagnostics.pointee.diagnostics,
contextSize: contextSize,
colorize: colorize != 0
)
(renderedPointer.pointee, renderedLength.pointee) =

View File

@@ -42,7 +42,8 @@ extern "C" void swift_ASTGen_addQueuedDiagnostic(
const void *sourceLoc
);
extern "C" void swift_ASTGen_renderQueuedDiagnostics(
void *queued, char **outBuffer, ptrdiff_t *outBufferLength);
void *queued, ptrdiff_t contextSize, ptrdiff_t colorize,
char **outBuffer, ptrdiff_t *outBufferLength);
// FIXME: Hack because we cannot easily get to the already-parsed source
// file from here. Fix this egregious oversight!
@@ -1106,7 +1107,8 @@ void PrintingDiagnosticConsumer::flush(bool includeTrailingBreak) {
char *renderedString = nullptr;
ptrdiff_t renderedStringLen = 0;
swift_ASTGen_renderQueuedDiagnostics(
queuedDiagnostics, &renderedString, &renderedStringLen);
queuedDiagnostics, /*contextSize=*/2, ForceColors ? 1 : 0,
&renderedString, &renderedStringLen);
if (renderedString) {
Stream.write(renderedString, renderedStringLen);
}