@@ -297,15 +297,15 @@ namespace {
297297
298298 static void printNumberedGutter (unsigned LineNumber,
299299 unsigned LineNumberIndent, raw_ostream &Out) {
300- Out.changeColor (ColoredStream::Colors::BLUE, true );
300+ Out.changeColor (ColoredStream::Colors::CYAN );
301301 Out << llvm::formatv (
302302 " {0} | " ,
303303 llvm::fmt_align (LineNumber, llvm::AlignStyle::Right, LineNumberIndent));
304304 Out.resetColor ();
305305 }
306306
307307 static void printEmptyGutter (unsigned LineNumberIndent, raw_ostream &Out) {
308- Out.changeColor (ColoredStream::Colors::BLUE, true );
308+ Out.changeColor (ColoredStream::Colors::CYAN );
309309 Out << std::string (LineNumberIndent + 1 , ' ' ) << " | " ;
310310 Out.resetColor ();
311311 }
@@ -402,7 +402,7 @@ namespace {
402402 if (shouldDelete != Deleted) {
403403 Out.resetColor ();
404404 if (shouldDelete) {
405- Out.changeColor (ColoredStream::Colors::RED);
405+ Out.changeColor (ColoredStream::Colors::RED, /* bold */ true );
406406 }
407407 }
408408 Deleted = shouldDelete;
@@ -604,15 +604,16 @@ namespace {
604604 printEmptyGutter (LineNumberIndent, Out);
605605 if (isASCII) {
606606 Out << std::string (byteToColumnMap[msg.Byte ], ' ' ) << " ^ " ;
607- printDiagnosticKind (msg.Kind , Out);
608- Out << " " << msg.Text << " \n " ;
609607 } else {
610- Out.changeColor (ColoredStream::Colors::BLUE, /* bold */ true );
608+ Out.changeColor (ColoredStream::Colors::CYAN );
611609 Out << " --> " ;
612610 Out.resetColor ();
613- printDiagnosticKind (msg.Kind , Out);
614- Out << " " << msg.Text << " \n " ;
615611 }
612+ printDiagnosticKind (msg.Kind , Out);
613+ Out.resetColor ();
614+ Out.changeColor (ColoredStream::Colors::WHITE, /* bold*/ true );
615+ Out << " " << msg.Text << " \n " ;
616+ Out.resetColor ();
616617 }
617618 delete[] byteToColumnMap;
618619 }
@@ -648,13 +649,6 @@ namespace {
648649 }
649650 }
650651
651- unsigned getLineNumberIndent () {
652- // The lines are already in sorted ascending order, and we render one line
653- // after the last one for context. Use the last line number plus one to
654- // determine the indent.
655- return floor (1 + log10 (AnnotatedLines.back ().getLineNumber () + 1 ));
656- }
657-
658652 void printNumberedLine (SourceManager &SM, unsigned BufferID,
659653 unsigned LineNumber, unsigned LineNumberIndent,
660654 raw_ostream &Out) {
@@ -698,6 +692,13 @@ namespace {
698692 SourceLoc PrimaryLoc)
699693 : SM(SM), BufferID(BufferID), PrimaryLoc(PrimaryLoc) {}
700694
695+ unsigned getPreferredLineNumberIndent () {
696+ // The lines are already in sorted ascending order, and we render one line
697+ // after the last one for context. Use the last line number plus one to
698+ // determine the indent.
699+ return floor (1 + log10 (AnnotatedLines.back ().getLineNumber () + 1 ));
700+ }
701+
701702 void addMessage (SourceLoc Loc, DiagnosticKind Kind, StringRef Message) {
702703 lineForLoc (Loc).addMessage (SM, Loc, Kind, Message);
703704 }
@@ -720,20 +721,22 @@ namespace {
720721 lineForLoc (lineRange.getStart ()).addFixIt (SM, lineRange, " " );
721722 }
722723
723- void render (raw_ostream &Out) {
724+ void render (unsigned MinimumLineNumberIndent, raw_ostream &Out) {
724725 // Tha maximum number of intermediate lines without annotations to render
725726 // between annotated lines before using an ellipsis.
726727 static const unsigned maxIntermediateLines = 3 ;
727728
728729 assert (!AnnotatedLines.empty () && " File excerpt has no lines" );
729- unsigned lineNumberIndent = getLineNumberIndent ();
730+ unsigned lineNumberIndent =
731+ std::max (getPreferredLineNumberIndent (), MinimumLineNumberIndent);
730732
731733 // Print the file name at the top of each excerpt.
732734 auto primaryLineAndColumn = SM.getLineAndColumn (PrimaryLoc);
733- Out.changeColor (ColoredStream::Colors::MAGENTA, /* bold*/ true );
734- Out << SM.getIdentifierForBuffer (BufferID) << " :"
735+ Out.changeColor (ColoredStream::Colors::CYAN);
736+ Out << std::string (lineNumberIndent + 1 , ' =' ) << " "
737+ << SM.getIdentifierForBuffer (BufferID) << " :"
735738 << primaryLineAndColumn.first << " :" << primaryLineAndColumn.second
736- << " \n " ;
739+ << " " << std::string (lineNumberIndent + 1 , ' = ' ) << " \n " ;
737740 Out.resetColor ();
738741
739742 // Print one extra line at the top for context.
@@ -755,7 +758,7 @@ namespace {
755758 // Use an ellipsis to denote an ommitted part of the file.
756759 printNumberedLine (SM, BufferID, lastLineNumber + 1 , lineNumberIndent,
757760 Out);
758- Out.changeColor (ColoredStream::Colors::BLUE, true );
761+ Out.changeColor (ColoredStream::Colors::CYAN );
759762 Out << llvm::formatv (" {0}...\n " ,
760763 llvm::fmt_repeat (" " , lineNumberIndent));
761764 Out.resetColor ();
@@ -820,19 +823,32 @@ class AnnotatedSourceSnippet {
820823
821824 void render (raw_ostream &Out) {
822825 // Print the excerpt for each file.
826+ unsigned lineNumberIndent =
827+ std::max_element (FileExcerpts.begin (), FileExcerpts.end (),
828+ [](auto &a, auto &b) {
829+ return a.second .getPreferredLineNumberIndent () <
830+ b.second .getPreferredLineNumberIndent ();
831+ })
832+ ->second .getPreferredLineNumberIndent ();
823833 for (auto excerpt : FileExcerpts)
824- excerpt.second .render (Out);
834+ excerpt.second .render (lineNumberIndent, Out);
825835
826836 // Handle messages with invalid locations.
827- if (!UnknownLocationMessages.empty ()) {
828- Out.changeColor (ColoredStream::Colors::MAGENTA, /* bold*/ true );
837+ if (UnknownLocationMessages.size () == 1 ) {
838+ Out.changeColor (ColoredStream::Colors::CYAN);
839+ Out << " Unknown Location: " ;
840+ Out.resetColor ();
841+ printDiagnosticKind (UnknownLocationMessages[0 ].first , Out);
842+ Out << " " << UnknownLocationMessages[0 ].second << " \n " ;
843+ } else if (UnknownLocationMessages.size () > 1 ) {
844+ Out.changeColor (ColoredStream::Colors::CYAN);
829845 Out << " Unknown Location\n " ;
830846 Out.resetColor ();
831- }
832- for ( auto unknownMessage : UnknownLocationMessages) {
833- printEmptyGutter ( 2 , Out);
834- printDiagnosticKind ( unknownMessage.first , Out) ;
835- Out << " " << unknownMessage. second << " \n " ;
847+ for ( auto unknownMessage : UnknownLocationMessages) {
848+ printEmptyGutter ( 2 , Out);
849+ printDiagnosticKind (unknownMessage. first , Out);
850+ Out << " " << unknownMessage.second << " \n " ;
851+ }
836852 }
837853 }
838854};
@@ -931,12 +947,12 @@ void PrintingDiagnosticConsumer::flush(bool includeTrailingBreak) {
931947 ColoredStream colorStream{Stream};
932948 currentSnippet->render (colorStream);
933949 if (includeTrailingBreak)
934- colorStream << " \n\n " ;
950+ colorStream << " \n " ;
935951 } else {
936952 NoColorStream noColorStream{Stream};
937953 currentSnippet->render (noColorStream);
938954 if (includeTrailingBreak)
939- noColorStream << " \n\n " ;
955+ noColorStream << " \n " ;
940956 }
941957 currentSnippet.reset ();
942958 }
0 commit comments