@@ -99,6 +99,12 @@ class ErrorSinkCompiler : ErrorSink
9999
100100 void plugSink ()
101101 {
102+ if (global.params.v.messageStyle == MessageStyle.diagreport)
103+ {
104+ foreach (ref group; completedEvents)
105+ // callEvent(group);
106+ }
107+
102108 // Exit if there are no collected diagnostics
103109 if (! diagnostics.length) return ;
104110
@@ -452,6 +458,54 @@ private struct DiagnosticContext
452458 bool supplemental; // true if supplemental error
453459}
454460
461+ /**
462+ * Collects diagnostics for the diagreport messagestyle.
463+ * Params:
464+ * loc = location of error
465+ * format = printf-style format specification
466+ * ap = printf-style variadic arguments
467+ * kind = kind of error being printed
468+ */
469+ private void collectDiagnostic (const SourceLoc loc, const (char )* format, va_list ap, ErrorKind kind) nothrow
470+ {
471+ // A new primary diagnostic means the previous causal group is complete
472+ if (diagnostics.length > 0 )
473+ {
474+ completedEvents ~= diagnostics;
475+ diagnostics.length = 0 ;
476+ }
477+
478+ OutBuffer tmp;
479+ tmp.vprintf(format, ap);
480+
481+ Diagnostic d;
482+ d.loc = loc;
483+ d.kind = kind;
484+ d.message = tmp.extractSlice().idup;
485+ diagnostics ~= d;
486+ }
487+
488+ /**
489+ * Collects supplementals of diagnostics for the diagreport messagestyle.
490+ * Params:
491+ * loc = location of error
492+ * format = printf-style format specification
493+ * ap = printf-style variadic arguments
494+ * kind = kind of error being printed
495+ */
496+ private void collectSupplemental (const SourceLoc loc, const (char )* format, va_list ap, ErrorKind kind) nothrow
497+ {
498+ // Append to the currently open causal group
499+ OutBuffer tmp;
500+ tmp.vprintf(format, ap);
501+
502+ Diagnostic d;
503+ d.loc = loc;
504+ d.kind = kind;
505+ d.message = tmp.extractSlice().idup;
506+ diagnostics ~= d;
507+ }
508+
455509/**
456510 * Implements $(D error), $(D warning), $(D deprecation), $(D message), and
457511 * $(D tip). Report a diagnostic error, taking a va_list parameter, and
@@ -487,6 +541,11 @@ private extern(C++) void vreportDiagnostic(const SourceLoc loc, const(char)* for
487541 addSarifDiagnostic(loc, format, ap, kind);
488542 return ;
489543 }
544+ if (global.params.v.messageStyle == MessageStyle.diagreport)
545+ {
546+ collectDiagnostic(loc, format, ap, kind);
547+ return ;
548+ }
490549 printDiagnostic(format, ap, info);
491550 if (global.params.v.errorLimit && global.errors >= global.params.v.errorLimit)
492551 {
@@ -521,6 +580,11 @@ private extern(C++) void vreportDiagnostic(const SourceLoc loc, const(char)* for
521580 addSarifDiagnostic(loc, format, ap, kind);
522581 return ;
523582 }
583+ if (global.params.v.messageStyle == MessageStyle.diagreport)
584+ {
585+ collectDiagnostic(loc, format, ap, kind);
586+ return ;
587+ }
524588 printDiagnostic(format, ap, info);
525589 }
526590 }
@@ -542,6 +606,11 @@ private extern(C++) void vreportDiagnostic(const SourceLoc loc, const(char)* for
542606 addSarifDiagnostic(loc, format, ap, kind);
543607 return ;
544608 }
609+ if (global.params.v.messageStyle == MessageStyle.diagreport)
610+ {
611+ collectDiagnostic(loc, format, ap, kind);
612+ return ;
613+ }
545614 printDiagnostic(format, ap, info);
546615 if (global.params.useWarnings == DiagnosticReporting.error)
547616 global.warnings++ ;
@@ -558,6 +627,11 @@ private extern(C++) void vreportDiagnostic(const SourceLoc loc, const(char)* for
558627 addSarifDiagnostic(loc, format, ap, kind);
559628 return ;
560629 }
630+ if (global.params.v.messageStyle == MessageStyle.diagreport)
631+ {
632+ collectDiagnostic(loc, format, ap, kind);
633+ return ;
634+ }
561635 printDiagnostic(format, ap, info);
562636 }
563637 return ;
@@ -578,6 +652,11 @@ private extern(C++) void vreportDiagnostic(const SourceLoc loc, const(char)* for
578652 addSarifDiagnostic(loc, format, ap, kind);
579653 return ;
580654 }
655+ if (global.params.v.messageStyle == MessageStyle.diagreport)
656+ {
657+ collectDiagnostic(loc, format, ap, kind);
658+ return ;
659+ }
581660 return ;
582661 }
583662}
@@ -614,6 +693,11 @@ private extern(C++) void vsupplementalDiagnostic(const SourceLoc loc, const(char
614693 }
615694 else
616695 info.headerColor = Classification.error;
696+ if (global.params.v.messageStyle == MessageStyle.diagreport)
697+ {
698+ collectSupplemental(loc, format, ap, kind);
699+ return ;
700+ }
617701 printDiagnostic(format, ap, info);
618702 return ;
619703
@@ -625,6 +709,11 @@ private extern(C++) void vsupplementalDiagnostic(const SourceLoc loc, const(char
625709 if (global.params.v.errorLimit == 0 || global.deprecations <= global.params.v.errorLimit)
626710 {
627711 info.headerColor = Classification.deprecation;
712+ if (global.params.v.messageStyle == MessageStyle.diagreport)
713+ {
714+ collectSupplemental(loc, format, ap, kind);
715+ return ;
716+ }
628717 printDiagnostic(format, ap, info);
629718 }
630719 }
0 commit comments