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));
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 llvm::stable_sort(ds, [](
auto &d1,
auto &d2) {
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 (; !remaining_details.empty(); remaining_details.pop_back()) {
189 const auto &detail = remaining_details.back();
192 stream << std::string(padding,
' ');
194 for (
auto &remaining_detail :
195 llvm::ArrayRef(remaining_details).drop_back(1)) {
196 uint16_t column = remaining_detail.source_location->column;
198 if (column == detail.source_location->column)
201 if (column >= x_pos) {
202 stream << std::string(column - x_pos,
' ') << vbar;
207 uint16_t column = detail.source_location->column;
210 stream << std::string(column - x_pos,
' ') << joint << hbar << spacer;
216 stream << detail.message <<
'\n';
223 stream << detail.rendered <<
'\n';
231 stream << detail.rendered <<
'\n';