@@ -128,15 +128,32 @@ namespace {
128
128
static void describeFixIt (SourceManager &SM, DiagnosticInfo::FixIt fixIt,
129
129
raw_ostream &Out) {
130
130
if (fixIt.getRange ().getByteLength () == 0 ) {
131
- Out << " [ insert '" << fixIt.getText () << " '] " ;
131
+ Out << " insert '" << fixIt.getText () << " '" ;
132
132
} else if (fixIt.getText ().empty ()) {
133
- Out << " [ remove '" << SM.extractText (fixIt.getRange ()) << " '] " ;
133
+ Out << " remove '" << SM.extractText (fixIt.getRange ()) << " '" ;
134
134
} else {
135
- Out << " [ replace '" << SM.extractText (fixIt.getRange ()) << " ' with '"
136
- << fixIt.getText () << " '] " ;
135
+ Out << " replace '" << SM.extractText (fixIt.getRange ()) << " ' with '"
136
+ << fixIt.getText () << " '" ;
137
137
}
138
138
}
139
139
140
+ static void describeFixIts (SourceManager &SM,
141
+ ArrayRef<DiagnosticInfo::FixIt> fixIts,
142
+ raw_ostream &Out) {
143
+ Out << " [" ;
144
+ for (unsigned i = 0 ; i < fixIts.size (); ++i) {
145
+ if (fixIts.size () > 2 && i + 1 == fixIts.size ()) {
146
+ Out << " , and " ;
147
+ } else if (fixIts.size () > 2 && i > 0 ) {
148
+ Out << " , " ;
149
+ } else if (fixIts.size () == 2 && i == 1 ) {
150
+ Out << " and " ;
151
+ }
152
+ describeFixIt (SM, fixIts[i], Out);
153
+ }
154
+ Out << " ]" ;
155
+ }
156
+
140
157
// / Represents a single line of source code annotated with optional messages,
141
158
// / highlights, and fix-its.
142
159
class AnnotatedLine {
@@ -543,13 +560,13 @@ static void annotateSnippetWithInfo(SourceManager &SM,
543
560
llvm::raw_svector_ostream Out (Text);
544
561
DiagnosticEngine::formatDiagnosticText (Out, Info.FormatString ,
545
562
Info.FormatArgs );
546
- // For notes, show associated fix-its as part of the message. This is a
547
- // better experience when notes offer a choice of fix-its.
548
- if (Info. Kind == DiagnosticKind::Note) {
549
- for ( auto fixIt : Info. FixIts ) {
550
- Out << " " ;
551
- describeFixIt (SM, fixIt, Out) ;
552
- }
563
+ // Show associated fix-its as part of the message. This is a
564
+ // better experience when notes offer a choice of fix-its. It's redundant
565
+ // for fix-its which are also displayed inline, but helps improve
566
+ // readability in some situations.
567
+ if (!Info. FixIts . empty ()) {
568
+ Out << " " ;
569
+ describeFixIts (SM, Info. FixIts , Out);
553
570
}
554
571
}
555
572
0 commit comments