|
13 | 13 |
|
14 | 14 | #include "lldb/ValueObject/DILParser.h" |
15 | 15 | #include "lldb/Target/ExecutionContextScope.h" |
| 16 | +#include "lldb/Utility/DiagnosticsRendering.h" |
16 | 17 | #include "lldb/ValueObject/DILAST.h" |
17 | 18 | #include "lldb/ValueObject/DILEval.h" |
18 | 19 | #include "llvm/ADT/StringRef.h" |
19 | 20 | #include "llvm/Support/FormatAdapters.h" |
| 21 | +#include <cstdlib> |
20 | 22 | #include <limits.h> |
21 | 23 | #include <memory> |
22 | 24 | #include <sstream> |
23 | | -#include <cstdlib> |
24 | 25 | #include <string> |
25 | 26 |
|
26 | 27 | namespace lldb_private::dil { |
27 | 28 |
|
28 | | -std::string FormatDiagnostics(llvm::StringRef text, const std::string &message, |
29 | | - uint32_t loc) { |
| 29 | +std::string NewFormatDiagnostics(llvm::StringRef text, |
| 30 | + const std::string &message, uint32_t loc, |
| 31 | + uint16_t err_len) { |
| 32 | + DiagnosticDetail::SourceLocation sloc = { |
| 33 | + FileSpec{}, /*line=*/1, loc + 1, err_len, false, /*in_user_input=*/true}; |
| 34 | + std::string arrow_str = "^"; |
| 35 | + std::string rendered_msg = |
| 36 | + llvm::formatv("<user expression 0>:1:{0}: {1}\n 1 | {2}\n | ^", |
| 37 | + loc + 1, message, text); |
| 38 | + DiagnosticDetail detail; |
| 39 | + detail.source_location = sloc; |
| 40 | + detail.severity = lldb::eSeverityError; |
| 41 | + detail.message = message; |
| 42 | + detail.rendered = rendered_msg; |
| 43 | + std::vector<DiagnosticDetail> diagnostics; |
| 44 | + diagnostics.push_back(detail); |
| 45 | + StreamString diag_stream(true); |
| 46 | + RenderDiagnosticDetails(diag_stream, 7, true, diagnostics); |
| 47 | + std::string ret_str = text.str() + "\n" + diag_stream.GetString().str(); |
| 48 | + return ret_str; |
| 49 | +} |
| 50 | + |
| 51 | +std::string OldFormatDiagnostics(llvm::StringRef text, |
| 52 | + const std::string &message, uint32_t loc) { |
30 | 53 | // Get the position, in the current line of text, of the diagnostics pointer. |
31 | 54 | // ('loc' is the location of the start of the current token/error within the |
32 | 55 | // overall text line). |
33 | 56 | int32_t arrow = loc + 1; // Column offset starts at 1, not 0. |
34 | 57 |
|
35 | | - return llvm::formatv("<expr:1:{0}>: {1}\n{2}\n{3}", loc, message, |
| 58 | + return llvm::formatv("<expr:1:{0}>: {1}\n{2}\n{3}", loc + 1, message, |
36 | 59 | llvm::fmt_pad(text, 0, 0), |
37 | 60 | llvm::fmt_pad("^", arrow - 1, 0)); |
38 | 61 | } |
@@ -234,7 +257,8 @@ void DILParser::BailOut(ErrorCode code, const std::string &error, |
234 | 257 | } |
235 | 258 |
|
236 | 259 | m_error = Status((uint32_t)code, lldb::eErrorTypeGeneric, |
237 | | - FormatDiagnostics(m_input_expr, error, loc)); |
| 260 | + NewFormatDiagnostics(m_input_expr, error, loc, |
| 261 | + CurToken().GetSpelling().length())); |
238 | 262 | // Advance the lexer token index to the end of the lexed tokens vector. |
239 | 263 | m_dil_lexer.ResetTokenIdx(m_dil_lexer.NumLexedTokens() - 1); |
240 | 264 | } |
|
0 commit comments