|
8 | 8 |
|
9 | 9 | #include "lldb/Interpreter/CommandReturnObject.h" |
10 | 10 |
|
| 11 | +#include "lldb/Utility/DiagnosticsRendering.h" |
11 | 12 | #include "lldb/Utility/Status.h" |
12 | 13 | #include "lldb/Utility/StreamString.h" |
13 | 14 |
|
@@ -112,8 +113,44 @@ void CommandReturnObject::SetError(Status error) { |
112 | 113 | } |
113 | 114 |
|
114 | 115 | void CommandReturnObject::SetError(llvm::Error error) { |
115 | | - if (error) |
| 116 | + // Retrieve any diagnostics. |
| 117 | + error = llvm::handleErrors(std::move(error), [&](ExpressionErrorBase &error) { |
| 118 | + SetStatus(eReturnStatusFailed); |
| 119 | + m_diagnostics = error.GetDetails(); |
| 120 | + }); |
| 121 | + if (error) { |
116 | 122 | AppendError(llvm::toString(std::move(error))); |
| 123 | + } |
| 124 | +} |
| 125 | + |
| 126 | +llvm::StringRef |
| 127 | +CommandReturnObject::GetInlineDiagnosticsData(unsigned indent, |
| 128 | + llvm::StringRef command) { |
| 129 | + size_t nchar = command.find(m_user_input); |
| 130 | + if (nchar == llvm::StringRef::npos) |
| 131 | + return {}; |
| 132 | + |
| 133 | + indent += nchar; |
| 134 | + RenderDiagnosticDetails(m_diag_stream, indent, true, m_diagnostics); |
| 135 | + // Duplex the diagnostics to the secondary stream (but not inlined). |
| 136 | + if (auto stream_sp = m_err_stream.GetStreamAtIndex(eStreamStringIndex)) |
| 137 | + RenderDiagnosticDetails(*stream_sp, std::nullopt, false, m_diagnostics); |
| 138 | + |
| 139 | + // Clear them so GetErrorData() doesn't render them again. |
| 140 | + m_diagnostics.clear(); |
| 141 | + return m_diag_stream.GetString(); |
| 142 | +} |
| 143 | + |
| 144 | +llvm::StringRef CommandReturnObject::GetErrorData() { |
| 145 | + // Diagnostics haven't been fetched; render them now (not inlined). |
| 146 | + if (!m_diagnostics.empty()) |
| 147 | + RenderDiagnosticDetails(GetErrorStream(), std::nullopt, false, |
| 148 | + m_diagnostics); |
| 149 | + |
| 150 | + lldb::StreamSP stream_sp(m_err_stream.GetStreamAtIndex(eStreamStringIndex)); |
| 151 | + if (stream_sp) |
| 152 | + return std::static_pointer_cast<StreamString>(stream_sp)->GetString(); |
| 153 | + return llvm::StringRef(); |
117 | 154 | } |
118 | 155 |
|
119 | 156 | // Similar to AppendError, but do not prepend 'Status: ' to message, and don't |
|
0 commit comments