Skip to content

Commit 08b2780

Browse files
authored
Merge pull request #80378 from DougGregor/remove-educational-note-markdown-rendering
[Diagnostics] Remove rendering of educational notes to the terminal
2 parents 6e436a5 + 62a96bc commit 08b2780

File tree

7 files changed

+0
-411
lines changed

7 files changed

+0
-411
lines changed

include/swift/Basic/DiagnosticOptions.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,6 @@ class DiagnosticOptions {
6969
PrintDiagnosticNamesMode PrintDiagnosticNames =
7070
PrintDiagnosticNamesMode::None;
7171

72-
/// If set to true, include educational notes in printed output if available.
73-
/// Educational notes are documentation which supplement diagnostics.
74-
bool PrintEducationalNotes = false;
75-
7672
/// Whether to emit diagnostics in the terse LLVM style or in a more
7773
/// descriptive style that's specific to Swift.
7874
FormattingStyle PrintedFormattingStyle = FormattingStyle::Swift;

include/swift/Frontend/PrintingDiagnosticConsumer.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,10 @@ namespace swift {
3232
class PrintingDiagnosticConsumer : public DiagnosticConsumer {
3333
llvm::raw_ostream &Stream;
3434
bool ForceColors = false;
35-
bool PrintEducationalNotes = false;
3635
bool EmitMacroExpansionFiles = false;
3736
bool DidErrorOccur = false;
3837
DiagnosticOptions::FormattingStyle FormattingStyle =
3938
DiagnosticOptions::FormattingStyle::LLVM;
40-
// Educational notes which are buffered until the consumer is finished
41-
// constructing a snippet.
42-
SmallVector<std::string, 1> BufferedEducationalNotes;
4339
bool SuppressOutput = false;
4440

4541
#if SWIFT_BUILD_SWIFT_SYNTAX
@@ -65,10 +61,6 @@ class PrintingDiagnosticConsumer : public DiagnosticConsumer {
6561
llvm::sys::Process::UseANSIEscapeCodes(true);
6662
}
6763

68-
void setPrintEducationalNotes(bool ShouldPrint) {
69-
PrintEducationalNotes = ShouldPrint;
70-
}
71-
7264
void setFormattingStyle(DiagnosticOptions::FormattingStyle style) {
7365
FormattingStyle = style;
7466
}

lib/Frontend/CompilerInvocation.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2562,7 +2562,6 @@ static bool ParseDiagnosticArgs(DiagnosticOptions &Opts, ArgList &Args,
25622562
} else if (Args.hasArg(OPT_print_diagnostic_groups)) {
25632563
Opts.PrintDiagnosticNames = PrintDiagnosticNamesMode::Group;
25642564
}
2565-
Opts.PrintEducationalNotes |= Args.hasArg(OPT_print_educational_notes);
25662565
if (Arg *A = Args.getLastArg(OPT_diagnostic_documentation_path)) {
25672566
Opts.DiagnosticDocumentationPath = A->getValue();
25682567
}

lib/Frontend/DiagnosticHelper.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -377,9 +377,6 @@ void DiagnosticHelper::Implementation::beginMessage() {
377377
if (invocation.getDiagnosticOptions().UseColor)
378378
PDC.forceColors();
379379

380-
PDC.setPrintEducationalNotes(
381-
invocation.getDiagnosticOptions().PrintEducationalNotes);
382-
383380
PDC.setFormattingStyle(
384381
invocation.getDiagnosticOptions().PrintedFormattingStyle);
385382

lib/Frontend/PrintingDiagnosticConsumer.cpp

Lines changed: 0 additions & 214 deletions
Original file line numberDiff line numberDiff line change
@@ -22,210 +22,13 @@
2222
#include "swift/Basic/LLVM.h"
2323
#include "swift/Basic/SourceManager.h"
2424
#include "swift/Bridging/ASTGen.h"
25-
#include "swift/Markup/Markup.h"
2625
#include "llvm/ADT/SmallString.h"
2726
#include "llvm/ADT/StringRef.h"
2827
#include "llvm/ADT/Twine.h"
2928
#include "llvm/Support/MemoryBuffer.h"
3029
#include "llvm/Support/raw_ostream.h"
3130

3231
using namespace swift;
33-
using namespace swift::markup;
34-
35-
namespace {
36-
// MARK: Markdown Printing
37-
class TerminalMarkupPrinter : public MarkupASTVisitor<TerminalMarkupPrinter> {
38-
llvm::raw_ostream &OS;
39-
unsigned Indent;
40-
unsigned ShouldBold;
41-
42-
void indent(unsigned Amount = 2) { Indent += Amount; }
43-
44-
void dedent(unsigned Amount = 2) {
45-
assert(Indent >= Amount && "dedent without matching indent");
46-
Indent -= Amount;
47-
}
48-
49-
void bold() {
50-
++ShouldBold;
51-
updateFormatting();
52-
}
53-
54-
void unbold() {
55-
assert(ShouldBold > 0 && "unbolded without matching bold");
56-
--ShouldBold;
57-
updateFormatting();
58-
}
59-
60-
void updateFormatting() {
61-
OS.resetColor();
62-
if (ShouldBold > 0)
63-
OS.changeColor(raw_ostream::Colors::SAVEDCOLOR, true);
64-
}
65-
66-
void print(StringRef Str) {
67-
for (auto c : Str) {
68-
OS << c;
69-
if (c == '\n')
70-
for (unsigned i = 0; i < Indent; ++i)
71-
OS << ' ';
72-
}
73-
}
74-
75-
public:
76-
TerminalMarkupPrinter(llvm::raw_ostream &OS)
77-
: OS(OS), Indent(0), ShouldBold(0) {}
78-
79-
void printNewline() { print("\n"); }
80-
81-
void visitDocument(const Document *D) {
82-
for (const auto *Child : D->getChildren()) {
83-
if (Child->getKind() == markup::ASTNodeKind::Paragraph) {
84-
// Add a newline before top-level paragraphs
85-
printNewline();
86-
}
87-
visit(Child);
88-
}
89-
}
90-
91-
void visitInlineAttributes(const InlineAttributes *A) {
92-
print("^[");
93-
for (const auto *Child : A->getChildren())
94-
visit(Child);
95-
print("](");
96-
print(A->getAttributes());
97-
print(")");
98-
}
99-
100-
void visitBlockQuote(const BlockQuote *BQ) {
101-
indent();
102-
printNewline();
103-
for (const auto *Child : BQ->getChildren())
104-
visit(Child);
105-
dedent();
106-
}
107-
108-
void visitList(const List *BL) {
109-
indent();
110-
printNewline();
111-
for (const auto *Child : BL->getChildren())
112-
visit(Child);
113-
dedent();
114-
}
115-
116-
void visitItem(const Item *I) {
117-
print("- ");
118-
for (const auto *N : I->getChildren())
119-
visit(N);
120-
}
121-
122-
void visitCodeBlock(const CodeBlock *CB) {
123-
indent();
124-
printNewline();
125-
print(CB->getLiteralContent());
126-
dedent();
127-
}
128-
129-
void visitCode(const Code *C) {
130-
print("'");
131-
print(C->getLiteralContent());
132-
print("'");
133-
}
134-
135-
void visitHTML(const HTML *H) { print(H->getLiteralContent()); }
136-
137-
void visitInlineHTML(const InlineHTML *IH) {
138-
print(IH->getLiteralContent());
139-
}
140-
141-
void visitSoftBreak(const SoftBreak *SB) { printNewline(); }
142-
143-
void visitLineBreak(const LineBreak *LB) {
144-
printNewline();
145-
printNewline();
146-
}
147-
148-
void visitLink(const Link *L) {
149-
print("[");
150-
for (const auto *Child : L->getChildren())
151-
visit(Child);
152-
print("](");
153-
print(L->getDestination());
154-
print(")");
155-
}
156-
157-
void visitImage(const Image *I) { llvm_unreachable("unsupported"); }
158-
159-
void visitParagraph(const Paragraph *P) {
160-
for (const auto *Child : P->getChildren())
161-
visit(Child);
162-
printNewline();
163-
}
164-
165-
// TODO: add raw_ostream support for italics ANSI codes in LLVM.
166-
void visitEmphasis(const Emphasis *E) {
167-
for (const auto *Child : E->getChildren())
168-
visit(Child);
169-
}
170-
171-
void visitStrong(const Strong *E) {
172-
bold();
173-
for (const auto *Child : E->getChildren())
174-
visit(Child);
175-
unbold();
176-
}
177-
178-
void visitHRule(const HRule *HR) {
179-
print("--------------");
180-
printNewline();
181-
}
182-
183-
void visitHeader(const Header *H) {
184-
bold();
185-
for (const auto *Child : H->getChildren())
186-
visit(Child);
187-
unbold();
188-
printNewline();
189-
}
190-
191-
void visitText(const Text *T) { print(T->getLiteralContent()); }
192-
193-
void visitPrivateExtension(const PrivateExtension *PE) {
194-
llvm_unreachable("unsupported");
195-
}
196-
197-
void visitParamField(const ParamField *PF) {
198-
llvm_unreachable("unsupported");
199-
}
200-
201-
void visitReturnField(const ReturnsField *RF) {
202-
llvm_unreachable("unsupported");
203-
}
204-
205-
void visitThrowField(const ThrowsField *TF) {
206-
llvm_unreachable("unsupported");
207-
}
208-
209-
#define MARKUP_SIMPLE_FIELD(Id, Keyword, XMLKind) \
210-
void visit##Id(const Id *Field) { llvm_unreachable("unsupported"); }
211-
#include "swift/Markup/SimpleFields.def"
212-
};
213-
214-
static void printMarkdown(StringRef Content, raw_ostream &Out,
215-
bool UseColor) {
216-
markup::MarkupContext ctx;
217-
auto document = markup::parseDocument(ctx, Content);
218-
if (UseColor) {
219-
ColoredStream stream{Out};
220-
TerminalMarkupPrinter printer(stream);
221-
printer.visit(document);
222-
} else {
223-
NoColorStream stream{Out};
224-
TerminalMarkupPrinter printer(stream);
225-
printer.visit(document);
226-
}
227-
}
228-
} // end anonymous namespace
22932

23033
// MARK: Main DiagnosticConsumer entrypoint.
23134
void PrintingDiagnosticConsumer::handleDiagnostic(SourceManager &SM,
@@ -261,16 +64,6 @@ void PrintingDiagnosticConsumer::handleDiagnostic(SourceManager &SM,
26164

26265
case DiagnosticOptions::FormattingStyle::LLVM:
26366
printDiagnostic(SM, Info);
264-
265-
if (PrintEducationalNotes) {
266-
for (auto path : Info.EducationalNotePaths) {
267-
if (auto buffer = SM.getFileSystem()->getBufferForFile(path)) {
268-
printMarkdown(buffer->get()->getBuffer(), Stream, ForceColors);
269-
Stream << "\n";
270-
}
271-
}
272-
}
273-
27467
for (auto ChildInfo : Info.ChildDiagnosticInfo) {
27568
printDiagnostic(SM, *ChildInfo);
27669
}
@@ -283,13 +76,6 @@ void PrintingDiagnosticConsumer::flush(bool includeTrailingBreak) {
28376
DiagBridge.flush(Stream, includeTrailingBreak,
28477
/*forceColors=*/ForceColors);
28578
#endif
286-
287-
for (auto note : BufferedEducationalNotes) {
288-
printMarkdown(note, Stream, ForceColors);
289-
Stream << "\n";
290-
}
291-
292-
BufferedEducationalNotes.clear();
29379
}
29480

29581
bool PrintingDiagnosticConsumer::finishProcessing() {

test/CAS/educational-notes.swift

Lines changed: 0 additions & 97 deletions
This file was deleted.

0 commit comments

Comments
 (0)