26 auto make_array = []() {
return std::make_unique<StructuredData::Array>(); };
27 auto make_dict = []() {
28 return std::make_unique<StructuredData::Dictionary>();
30 auto dict_up = make_dict();
31 dict_up->AddIntegerItem(
"version", 1u);
32 auto array_up = make_array();
34 auto detail_up = make_dict();
35 if (
auto &sloc = diag.source_location) {
36 auto sloc_up = make_dict();
37 sloc_up->AddStringItem(
"file", sloc->file.GetPath());
38 sloc_up->AddIntegerItem(
"line", sloc->line);
39 sloc_up->AddIntegerItem(
"length", sloc->length);
40 sloc_up->AddBooleanItem(
"hidden", sloc->hidden);
41 sloc_up->AddBooleanItem(
"in_user_input", sloc->in_user_input);
42 detail_up->AddItem(
"source_location", std::move(sloc_up));
44 llvm::StringRef severity =
"unknown";
45 switch (diag.severity) {
56 detail_up->AddStringItem(
"severity", severity);
57 detail_up->AddStringItem(
"message", diag.message);
58 detail_up->AddStringItem(
"rendered", diag.rendered);
59 array_up->AddItem(std::move(detail_up));
61 dict_up->AddItem(
"details", std::move(array_up));
88 std::optional<uint16_t> offset_in_command,
90 llvm::ArrayRef<DiagnosticDetail> details,
95 if (!offset_in_command) {
98 stream << detail.rendered <<
'\n';
103 llvm::StringRef cursor, underline, vbar, joint, hbar, spacer;
121 std::vector<DiagnosticDetail> remaining_details, other_details,
124 if (!show_inline || !detail.source_location) {
125 other_details.push_back(detail);
128 if (detail.source_location->hidden) {
129 hidden_details.push_back(detail);
132 if (!detail.source_location->in_user_input) {
133 other_details.push_back(detail);
137 remaining_details.push_back(detail);
141 auto sort = [](std::vector<DiagnosticDetail> &ds) {
142 llvm::stable_sort(ds, [](
auto &d1,
auto &d2) {
145 return std::tie(l1.line, l1.column) < std::tie(l2.line, l2.column);
148 sort(remaining_details);
150 sort(hidden_details);
153 const size_t padding = *offset_in_command;
154 stream << std::string(padding,
' ');
158 auto &loc = *detail.source_location;
160 if (x_pos > loc.column)
163 stream << std::string(loc.column - x_pos,
' ') << cursor;
164 x_pos = loc.column + 1;
165 for (
unsigned i = 0; i + 1 < loc.length; ++i) {
174 auto group = [](std::vector<DiagnosticDetail> &details) {
175 for (
auto it = details.begin(), end = details.end(); it != end;) {
179 std::reverse(it, eq_end);
183 group(remaining_details);
186 bool did_print =
false;
187 for (; !remaining_details.empty(); remaining_details.pop_back()) {
188 const auto &detail = remaining_details.back();
191 stream << std::string(padding,
' ');
193 for (
auto &remaining_detail :
194 llvm::ArrayRef(remaining_details).drop_back(1)) {
195 uint16_t column = remaining_detail.source_location->column;
197 if (column == detail.source_location->column)
200 if (column >= x_pos) {
201 stream << std::string(column - x_pos,
' ') << vbar;
206 uint16_t column = detail.source_location->column;
209 stream << std::string(column - x_pos,
' ') << joint << hbar << spacer;
215 stream << detail.message <<
'\n';
222 stream << detail.rendered <<
'\n';
230 stream << detail.rendered <<
'\n';