24 auto make_array = []() {
return std::make_unique<StructuredData::Array>(); };
25 auto make_dict = []() {
26 return std::make_unique<StructuredData::Dictionary>();
28 auto dict_up = make_dict();
29 dict_up->AddIntegerItem(
"version", 1u);
30 auto array_up = make_array();
32 auto detail_up = make_dict();
33 if (
auto &sloc = diag.source_location) {
34 auto sloc_up = make_dict();
35 sloc_up->AddStringItem(
"file", sloc->file.GetPath());
36 sloc_up->AddIntegerItem(
"line", sloc->line);
37 sloc_up->AddIntegerItem(
"length", sloc->length);
38 sloc_up->AddBooleanItem(
"hidden", sloc->hidden);
39 sloc_up->AddBooleanItem(
"in_user_input", sloc->in_user_input);
40 detail_up->AddItem(
"source_location", std::move(sloc_up));
42 llvm::StringRef severity =
"unknown";
43 switch (diag.severity) {
54 detail_up->AddStringItem(
"severity", severity);
55 detail_up->AddStringItem(
"message", diag.message);
56 detail_up->AddStringItem(
"rendered", diag.rendered);
57 array_up->AddItem(std::move(detail_up));
59 dict_up->AddItem(
"details", std::move(array_up));
65 llvm::HighlightColor color;
69 color = llvm::HighlightColor::Error;
73 color = llvm::HighlightColor::Warning;
77 color = llvm::HighlightColor::Remark;
81 return llvm::WithColor(stream.
AsRawOstream(), color, llvm::ColorMode::Enable)
86 std::optional<uint16_t> offset_in_command,
88 llvm::ArrayRef<DiagnosticDetail> details) {
92 if (!offset_in_command) {
95 stream << detail.rendered <<
'\n';
104 llvm::StringRef cursor, underline, vbar, joint, hbar, spacer;
122 std::vector<DiagnosticDetail> remaining_details, other_details,
125 if (!show_inline || !detail.source_location) {
126 other_details.push_back(detail);
129 if (detail.source_location->hidden) {
130 hidden_details.push_back(detail);
133 if (!detail.source_location->in_user_input) {
134 other_details.push_back(detail);
138 remaining_details.push_back(detail);
142 auto sort = [](std::vector<DiagnosticDetail> &ds) {
143 std::stable_sort(ds.begin(), ds.end(), [](
auto &d1,
auto &d2) {
144 auto l1 = d1.source_location.value_or(DiagnosticDetail::SourceLocation{});
146 return std::tie(l1.line, l1.column) < std::tie(l2.line, l2.column);
149 sort(remaining_details);
151 sort(hidden_details);
154 const size_t padding = *offset_in_command;
155 stream << std::string(padding,
' ');
159 auto &loc = *detail.source_location;
161 if (x_pos > loc.column)
164 stream << std::string(loc.column - x_pos,
' ') << cursor;
165 x_pos = loc.column + 1;
166 for (
unsigned i = 0; i + 1 < loc.length; ++i) {
175 auto group = [](std::vector<DiagnosticDetail> &details) {
176 for (
auto it = details.begin(), end = details.end(); it != end;) {
180 std::reverse(it, eq_end);
184 group(remaining_details);
187 bool did_print =
false;
188 for (
auto detail = remaining_details.rbegin();
189 detail != remaining_details.rend();
190 ++detail, remaining_details.pop_back()) {
193 stream << std::string(padding,
' ');
195 for (
auto &remaining_detail :
196 llvm::ArrayRef(remaining_details).drop_back(1)) {
197 uint16_t column = remaining_detail.source_location->column;
199 if (column == detail->source_location->column)
202 if (column >= x_pos) {
203 stream << std::string(column - x_pos,
' ') << vbar;
208 uint16_t column = detail->source_location->column;
211 stream << std::string(column - x_pos,
' ') << joint << hbar << spacer;
217 stream << detail->message <<
'\n';
224 stream << detail.rendered <<
'\n';
232 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.
std::shared_ptr< Object > ObjectSP
A class that represents a running process on the host machine.
static llvm::raw_ostream & PrintSeverity(Stream &stream, lldb::Severity severity)
StructuredData::ObjectSP Serialize(llvm::ArrayRef< DiagnosticDetail > details)
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.