25 llvm::HighlightColor color;
29 color = llvm::HighlightColor::Error;
33 color = llvm::HighlightColor::Warning;
37 color = llvm::HighlightColor::Remark;
41 return llvm::WithColor(stream.
AsRawOstream(), color, llvm::ColorMode::Enable)
46 std::optional<uint16_t> offset_in_command,
48 llvm::ArrayRef<DiagnosticDetail> details) {
52 if (!offset_in_command) {
55 stream << detail.rendered <<
'\n';
64 llvm::StringRef cursor, underline, vbar, joint, hbar, spacer;
82 std::vector<DiagnosticDetail> remaining_details, other_details,
85 if (!show_inline || !detail.source_location) {
86 other_details.push_back(detail);
89 if (detail.source_location->hidden) {
90 hidden_details.push_back(detail);
93 if (!detail.source_location->in_user_input) {
94 other_details.push_back(detail);
98 remaining_details.push_back(detail);
102 auto sort = [](std::vector<DiagnosticDetail> &ds) {
103 std::stable_sort(ds.begin(), ds.end(), [](
auto &d1,
auto &d2) {
104 auto l1 = d1.source_location.value_or(DiagnosticDetail::SourceLocation{});
106 return std::tie(l1.line, l1.column) < std::tie(l2.line, l2.column);
109 sort(remaining_details);
111 sort(hidden_details);
114 const size_t padding = *offset_in_command;
115 stream << std::string(padding,
' ');
119 auto &loc = *detail.source_location;
121 if (x_pos > loc.column)
124 stream << std::string(loc.column - x_pos,
' ') << cursor;
125 x_pos = loc.column + 1;
126 for (
unsigned i = 0; i + 1 < loc.length; ++i) {
135 auto group = [](std::vector<DiagnosticDetail> &details) {
136 for (
auto it = details.begin(), end = details.end(); it != end;) {
140 std::reverse(it, eq_end);
144 group(remaining_details);
147 bool did_print =
false;
148 for (
auto detail = remaining_details.rbegin();
149 detail != remaining_details.rend();
150 ++detail, remaining_details.pop_back()) {
153 stream << std::string(padding,
' ');
155 for (
auto &remaining_detail :
156 llvm::ArrayRef(remaining_details).drop_back(1)) {
157 uint16_t column = remaining_detail.source_location->column;
159 if (column == detail->source_location->column)
162 if (column >= x_pos) {
163 stream << std::string(column - x_pos,
' ') << vbar;
168 uint16_t column = detail->source_location->column;
171 stream << std::string(column - x_pos,
' ') << joint << hbar << spacer;
177 stream << detail->message <<
'\n';
184 stream << detail.rendered <<
'\n';
192 stream << detail.rendered <<
'\n';
lldb::ErrorType GetErrorType() const override
A stream class that can stream formatted output to a file.
llvm::raw_ostream & AsRawOstream()
Returns a raw_ostream that forwards the data to this Stream object.
A class that represents a running process on the host machine.
static llvm::raw_ostream & PrintSeverity(Stream &stream, lldb::Severity severity)
void RenderDiagnosticDetails(Stream &stream, std::optional< uint16_t > offset_in_command, bool show_inline, llvm::ArrayRef< DiagnosticDetail > details)
Severity
Used for expressing severity in logs and diagnostics.
@ eErrorTypeExpression
These are from the ExpressionResults enum.
A source location consisting of a file name and position.
A compiler-independent representation of an lldb_private::Diagnostic.
std::optional< SourceLocation > source_location
Contains this diagnostic's source location, if applicable.