Add way to completely hide suggestion from cli output
This commit is contained in:
parent
7cfba1c5e8
commit
235523c7d4
@ -346,6 +346,27 @@ impl Diagnostic {
|
||||
self
|
||||
}
|
||||
|
||||
/// Adds a suggestion to the json output, but otherwise remains silent/undisplayed in the cli.
|
||||
///
|
||||
/// This is intended to be used for suggestions that are *very* obvious in what the changes
|
||||
/// need to be from the message, but we still want other tools to be able to apply them.
|
||||
pub fn tool_only_span_suggestion(
|
||||
&mut self, sp: Span, msg: &str, suggestion: String, applicability: Applicability
|
||||
) -> &mut Self {
|
||||
self.suggestions.push(CodeSuggestion {
|
||||
substitutions: vec![Substitution {
|
||||
parts: vec![SubstitutionPart {
|
||||
snippet: suggestion,
|
||||
span: sp,
|
||||
}],
|
||||
}],
|
||||
msg: msg.to_owned(),
|
||||
style: SuggestionStyle::CompletelyHidden,
|
||||
applicability: applicability,
|
||||
});
|
||||
self
|
||||
}
|
||||
|
||||
pub fn set_span<S: Into<MultiSpan>>(&mut self, sp: S) -> &mut Self {
|
||||
self.span = sp.into();
|
||||
self
|
||||
|
@ -281,6 +281,25 @@ impl<'a> DiagnosticBuilder<'a> {
|
||||
self
|
||||
}
|
||||
|
||||
pub fn tool_only_span_suggestion(
|
||||
&mut self,
|
||||
sp: Span,
|
||||
msg: &str,
|
||||
suggestion: String,
|
||||
applicability: Applicability,
|
||||
) -> &mut Self {
|
||||
if !self.allow_suggestions {
|
||||
return self
|
||||
}
|
||||
self.diagnostic.tool_only_span_suggestion(
|
||||
sp,
|
||||
msg,
|
||||
suggestion,
|
||||
applicability,
|
||||
);
|
||||
self
|
||||
}
|
||||
|
||||
forward!(pub fn set_span<S: Into<MultiSpan>>(&mut self, sp: S) -> &mut Self);
|
||||
forward!(pub fn code(&mut self, s: DiagnosticId) -> &mut Self);
|
||||
|
||||
|
@ -1363,7 +1363,9 @@ impl EmitterWriter {
|
||||
}
|
||||
}
|
||||
for sugg in suggestions {
|
||||
if sugg.style == SuggestionStyle::HideCodeAlways {
|
||||
if sugg.style == SuggestionStyle::CompletelyHidden {
|
||||
// do not display this suggestion, it is meant only for tools
|
||||
} else if sugg.style == SuggestionStyle::HideCodeAlways {
|
||||
match self.emit_message_default(
|
||||
&MultiSpan::new(),
|
||||
&[(sugg.msg.to_owned(), Style::HeaderMsg)],
|
||||
|
@ -72,8 +72,10 @@ pub enum Applicability {
|
||||
pub enum SuggestionStyle {
|
||||
/// Hide the suggested code when displaying this suggestion inline.
|
||||
HideCodeInline,
|
||||
/// Always hide the suggested code.
|
||||
/// Always hide the suggested code but display the message.
|
||||
HideCodeAlways,
|
||||
/// Do not display this suggestion in the cli output, it is only meant for tools.
|
||||
CompletelyHidden,
|
||||
/// Always show the suggested code.
|
||||
/// This will *not* show the code if the suggestion is inline *and* the suggested code is
|
||||
/// empty.
|
||||
@ -83,8 +85,8 @@ pub enum SuggestionStyle {
|
||||
impl SuggestionStyle {
|
||||
fn hide_inline(&self) -> bool {
|
||||
match *self {
|
||||
SuggestionStyle::HideCodeAlways | SuggestionStyle::HideCodeInline => true,
|
||||
SuggestionStyle::ShowCode => false,
|
||||
_ => true,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user