@@ -297,15 +297,15 @@ namespace {
297
297
298
298
static void printNumberedGutter (unsigned LineNumber,
299
299
unsigned LineNumberIndent, raw_ostream &Out) {
300
- Out.changeColor (ColoredStream::Colors::BLUE, true );
300
+ Out.changeColor (ColoredStream::Colors::CYAN );
301
301
Out << llvm::formatv (
302
302
" {0} | " ,
303
303
llvm::fmt_align (LineNumber, llvm::AlignStyle::Right, LineNumberIndent));
304
304
Out.resetColor ();
305
305
}
306
306
307
307
static void printEmptyGutter (unsigned LineNumberIndent, raw_ostream &Out) {
308
- Out.changeColor (ColoredStream::Colors::BLUE, true );
308
+ Out.changeColor (ColoredStream::Colors::CYAN );
309
309
Out << std::string (LineNumberIndent + 1 , ' ' ) << " | " ;
310
310
Out.resetColor ();
311
311
}
@@ -402,7 +402,7 @@ namespace {
402
402
if (shouldDelete != Deleted) {
403
403
Out.resetColor ();
404
404
if (shouldDelete) {
405
- Out.changeColor (ColoredStream::Colors::RED);
405
+ Out.changeColor (ColoredStream::Colors::RED, /* bold */ true );
406
406
}
407
407
}
408
408
Deleted = shouldDelete;
@@ -604,15 +604,16 @@ namespace {
604
604
printEmptyGutter (LineNumberIndent, Out);
605
605
if (isASCII) {
606
606
Out << std::string (byteToColumnMap[msg.Byte ], ' ' ) << " ^ " ;
607
- printDiagnosticKind (msg.Kind , Out);
608
- Out << " " << msg.Text << " \n " ;
609
607
} else {
610
- Out.changeColor (ColoredStream::Colors::BLUE, /* bold */ true );
608
+ Out.changeColor (ColoredStream::Colors::CYAN );
611
609
Out << " --> " ;
612
610
Out.resetColor ();
613
- printDiagnosticKind (msg.Kind , Out);
614
- Out << " " << msg.Text << " \n " ;
615
611
}
612
+ printDiagnosticKind (msg.Kind , Out);
613
+ Out.resetColor ();
614
+ Out.changeColor (ColoredStream::Colors::WHITE, /* bold*/ true );
615
+ Out << " " << msg.Text << " \n " ;
616
+ Out.resetColor ();
616
617
}
617
618
delete[] byteToColumnMap;
618
619
}
@@ -648,13 +649,6 @@ namespace {
648
649
}
649
650
}
650
651
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
-
658
652
void printNumberedLine (SourceManager &SM, unsigned BufferID,
659
653
unsigned LineNumber, unsigned LineNumberIndent,
660
654
raw_ostream &Out) {
@@ -698,6 +692,13 @@ namespace {
698
692
SourceLoc PrimaryLoc)
699
693
: SM(SM), BufferID(BufferID), PrimaryLoc(PrimaryLoc) {}
700
694
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
+
701
702
void addMessage (SourceLoc Loc, DiagnosticKind Kind, StringRef Message) {
702
703
lineForLoc (Loc).addMessage (SM, Loc, Kind, Message);
703
704
}
@@ -720,20 +721,22 @@ namespace {
720
721
lineForLoc (lineRange.getStart ()).addFixIt (SM, lineRange, " " );
721
722
}
722
723
723
- void render (raw_ostream &Out) {
724
+ void render (unsigned MinimumLineNumberIndent, raw_ostream &Out) {
724
725
// Tha maximum number of intermediate lines without annotations to render
725
726
// between annotated lines before using an ellipsis.
726
727
static const unsigned maxIntermediateLines = 3 ;
727
728
728
729
assert (!AnnotatedLines.empty () && " File excerpt has no lines" );
729
- unsigned lineNumberIndent = getLineNumberIndent ();
730
+ unsigned lineNumberIndent =
731
+ std::max (getPreferredLineNumberIndent (), MinimumLineNumberIndent);
730
732
731
733
// Print the file name at the top of each excerpt.
732
734
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) << " :"
735
738
<< primaryLineAndColumn.first << " :" << primaryLineAndColumn.second
736
- << " \n " ;
739
+ << " " << std::string (lineNumberIndent + 1 , ' = ' ) << " \n " ;
737
740
Out.resetColor ();
738
741
739
742
// Print one extra line at the top for context.
@@ -755,7 +758,7 @@ namespace {
755
758
// Use an ellipsis to denote an ommitted part of the file.
756
759
printNumberedLine (SM, BufferID, lastLineNumber + 1 , lineNumberIndent,
757
760
Out);
758
- Out.changeColor (ColoredStream::Colors::BLUE, true );
761
+ Out.changeColor (ColoredStream::Colors::CYAN );
759
762
Out << llvm::formatv (" {0}...\n " ,
760
763
llvm::fmt_repeat (" " , lineNumberIndent));
761
764
Out.resetColor ();
@@ -820,19 +823,32 @@ class AnnotatedSourceSnippet {
820
823
821
824
void render (raw_ostream &Out) {
822
825
// 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 ();
823
833
for (auto excerpt : FileExcerpts)
824
- excerpt.second .render (Out);
834
+ excerpt.second .render (lineNumberIndent, Out);
825
835
826
836
// 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);
829
845
Out << " Unknown Location\n " ;
830
846
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
+ }
836
852
}
837
853
}
838
854
};
@@ -931,12 +947,12 @@ void PrintingDiagnosticConsumer::flush(bool includeTrailingBreak) {
931
947
ColoredStream colorStream{Stream};
932
948
currentSnippet->render (colorStream);
933
949
if (includeTrailingBreak)
934
- colorStream << " \n\n " ;
950
+ colorStream << " \n " ;
935
951
} else {
936
952
NoColorStream noColorStream{Stream};
937
953
currentSnippet->render (noColorStream);
938
954
if (includeTrailingBreak)
939
- noColorStream << " \n\n " ;
955
+ noColorStream << " \n " ;
940
956
}
941
957
currentSnippet.reset ();
942
958
}
0 commit comments