@@ -99,6 +99,10 @@ class ErrorSinkCompiler : ErrorSink
9999
100100 void plugSink ()
101101 {
102+ if (global.params.v.messageStyle == MessageStyle.diagreport)
103+ {
104+ }
105+
102106 // Exit if there are no collected diagnostics
103107 if (! diagnostics.length) return ;
104108
@@ -452,6 +456,54 @@ private struct DiagnosticContext
452456 bool supplemental; // true if supplemental error
453457}
454458
459+ /**
460+ * Collects diagnostics for the diagreport messagestyle.
461+ * Params:
462+ * loc = location of error
463+ * format = printf-style format specification
464+ * ap = printf-style variadic arguments
465+ * kind = kind of error being printed
466+ */
467+ private void collectDiagnostic (const SourceLoc loc, const (char )* format, va_list ap, ErrorKind kind) nothrow
468+ {
469+ // A new primary diagnostic means the previous causal group is complete
470+ if (diagnostics.length > 0 )
471+ {
472+ completedEvents ~= diagnostics;
473+ diagnostics.length = 0 ;
474+ }
475+
476+ OutBuffer tmp;
477+ tmp.vprintf(format, ap);
478+
479+ Diagnostic d;
480+ d.loc = loc;
481+ d.kind = kind;
482+ d.message = tmp.extractSlice().idup;
483+ diagnostics ~= d;
484+ }
485+
486+ /**
487+ * Collects supplementals of diagnostics for the diagreport messagestyle.
488+ * Params:
489+ * loc = location of error
490+ * format = printf-style format specification
491+ * ap = printf-style variadic arguments
492+ * kind = kind of error being printed
493+ */
494+ private void collectSupplemental (const SourceLoc loc, const (char )* format, va_list ap, ErrorKind kind) nothrow
495+ {
496+ // Append to the currently open causal group
497+ OutBuffer tmp;
498+ tmp.vprintf(format, ap);
499+
500+ Diagnostic d;
501+ d.loc = loc;
502+ d.kind = kind;
503+ d.message = tmp.extractSlice().idup;
504+ diagnostics ~= d;
505+ }
506+
455507/**
456508 * Implements $(D error), $(D warning), $(D deprecation), $(D message), and
457509 * $(D tip). Report a diagnostic error, taking a va_list parameter, and
@@ -487,6 +539,11 @@ private extern(C++) void vreportDiagnostic(const SourceLoc loc, const(char)* for
487539 addSarifDiagnostic(loc, format, ap, kind);
488540 return ;
489541 }
542+ if (global.params.v.messageStyle == MessageStyle.diagreport)
543+ {
544+ collectDiagnostic(loc, format, ap, kind);
545+ return ;
546+ }
490547 printDiagnostic(format, ap, info);
491548 if (global.params.v.errorLimit && global.errors >= global.params.v.errorLimit)
492549 {
@@ -521,6 +578,11 @@ private extern(C++) void vreportDiagnostic(const SourceLoc loc, const(char)* for
521578 addSarifDiagnostic(loc, format, ap, kind);
522579 return ;
523580 }
581+ if (global.params.v.messageStyle == MessageStyle.diagreport)
582+ {
583+ collectDiagnostic(loc, format, ap, kind);
584+ return ;
585+ }
524586 printDiagnostic(format, ap, info);
525587 }
526588 }
@@ -542,6 +604,11 @@ private extern(C++) void vreportDiagnostic(const SourceLoc loc, const(char)* for
542604 addSarifDiagnostic(loc, format, ap, kind);
543605 return ;
544606 }
607+ if (global.params.v.messageStyle == MessageStyle.diagreport)
608+ {
609+ collectDiagnostic(loc, format, ap, kind);
610+ return ;
611+ }
545612 printDiagnostic(format, ap, info);
546613 if (global.params.useWarnings == DiagnosticReporting.error)
547614 global.warnings++ ;
@@ -558,6 +625,11 @@ private extern(C++) void vreportDiagnostic(const SourceLoc loc, const(char)* for
558625 addSarifDiagnostic(loc, format, ap, kind);
559626 return ;
560627 }
628+ if (global.params.v.messageStyle == MessageStyle.diagreport)
629+ {
630+ collectDiagnostic(loc, format, ap, kind);
631+ return ;
632+ }
561633 printDiagnostic(format, ap, info);
562634 }
563635 return ;
@@ -578,6 +650,11 @@ private extern(C++) void vreportDiagnostic(const SourceLoc loc, const(char)* for
578650 addSarifDiagnostic(loc, format, ap, kind);
579651 return ;
580652 }
653+ if (global.params.v.messageStyle == MessageStyle.diagreport)
654+ {
655+ collectDiagnostic(loc, format, ap, kind);
656+ return ;
657+ }
581658 return ;
582659 }
583660}
@@ -614,6 +691,11 @@ private extern(C++) void vsupplementalDiagnostic(const SourceLoc loc, const(char
614691 }
615692 else
616693 info.headerColor = Classification.error;
694+ if (global.params.v.messageStyle == MessageStyle.diagreport)
695+ {
696+ collectSupplemental(loc, format, ap, kind);
697+ return ;
698+ }
617699 printDiagnostic(format, ap, info);
618700 return ;
619701
@@ -625,6 +707,11 @@ private extern(C++) void vsupplementalDiagnostic(const SourceLoc loc, const(char
625707 if (global.params.v.errorLimit == 0 || global.deprecations <= global.params.v.errorLimit)
626708 {
627709 info.headerColor = Classification.deprecation;
710+ if (global.params.v.messageStyle == MessageStyle.diagreport)
711+ {
712+ collectSupplemental(loc, format, ap, kind);
713+ return ;
714+ }
628715 printDiagnostic(format, ap, info);
629716 }
630717 }
0 commit comments