-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Support inline diagnostics in CommandReturnObject #110901
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
//===-- DiagnosticsRendering.h ----------------------------------*- C++ -*-===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef LLDB_UTILITY_DIAGNOSTICSRENDERING_H | ||
#define LLDB_UTILITY_DIAGNOSTICSRENDERING_H | ||
|
||
#include "lldb/Utility/Status.h" | ||
#include "lldb/Utility/Stream.h" | ||
#include "llvm/Support/WithColor.h" | ||
|
||
namespace lldb_private { | ||
|
||
/// A compiler-independent representation of an \c | ||
/// lldb_private::Diagnostic. Expression evaluation failures often | ||
/// have more than one diagnostic that a UI layer might want to render | ||
/// differently, for example to colorize it. | ||
/// | ||
/// Running example: | ||
/// (lldb) expr 1 + foo | ||
/// error: <user expression 0>:1:3: use of undeclared identifier 'foo' | ||
/// 1 + foo | ||
/// ^~~ | ||
struct DiagnosticDetail { | ||
/// A source location consisting of a file name and position. | ||
struct SourceLocation { | ||
/// \c "<user expression 0>" in the example above. | ||
FileSpec file; | ||
/// \c 1 in the example above. | ||
unsigned line = 0; | ||
/// \c 5 in the example above. | ||
uint16_t column = 0; | ||
/// \c 3 in the example above. | ||
uint16_t length = 0; | ||
/// Whether this source location should be surfaced to the | ||
/// user. For example, syntax errors diagnosed in LLDB's | ||
/// expression wrapper code have this set to true. | ||
bool hidden = false; | ||
/// Whether this source location refers to something the user | ||
/// typed as part of the command, i.e., if this qualifies for | ||
/// inline display, or if the source line would need to be echoed | ||
/// again for the message to make sense. | ||
bool in_user_input = false; | ||
}; | ||
/// Contains this diagnostic's source location, if applicable. | ||
std::optional<SourceLocation> source_location; | ||
/// Contains \c eSeverityError in the example above. | ||
lldb::Severity severity = lldb::eSeverityInfo; | ||
/// Contains "use of undeclared identifier 'foo'" in the example above. | ||
std::string message; | ||
/// Contains the fully rendered error message, without "error: ", | ||
/// but including the source context. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What does this contain for "inline display"? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jimingham I don't understand the question. Concretely, in the example
this is what a client can use if they choose to not show diagnostics inline. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was confused because it didn't seem like there was a way to get the inline rendering if you wanted to use that, for instance if you were writing your own driver. Presumably there's no way to do that? That set me to wondering whether BTW, I don't actually think it's necessary to have a way to fetch the inline rendered form (properly offset for the prompt string, etc.) The possibility set me wondering, however. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is no "fetching of the inline rendered form". Either you use the prerendered non-inline form or you have to render the message yourself using all the details in the struct. The point is to allow different drivers to render errors in a way that makes sense for them. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You have a bool saying whether this can be used in inline displays, which leads to the question "can I get you to make that for me here". That the answer to that is no is fine, butsaying that explicitly would have reduced confusion. No biggie... |
||
std::string rendered; | ||
}; | ||
|
||
class DiagnosticError | ||
: public llvm::ErrorInfo<DiagnosticError, CloneableECError> { | ||
public: | ||
using llvm::ErrorInfo<DiagnosticError, CloneableECError>::ErrorInfo; | ||
DiagnosticError(std::error_code ec) : ErrorInfo(ec) {} | ||
lldb::ErrorType GetErrorType() const override; | ||
virtual llvm::ArrayRef<DiagnosticDetail> GetDetails() const = 0; | ||
static char ID; | ||
}; | ||
|
||
void RenderDiagnosticDetails(Stream &stream, | ||
std::optional<uint16_t> offset_in_command, | ||
bool show_inline, | ||
llvm::ArrayRef<DiagnosticDetail> details); | ||
} // namespace lldb_private | ||
#endif |
Uh oh!
There was an error while loading. Please reload this page.