self.level == Level::Cancelled
}
- /// Add a span/label to be included in the resulting snippet.
+ /// Adds a span/label to be included in the resulting snippet.
/// This is pushed onto the `MultiSpan` that was created when the
/// diagnostic was first built. If you don't call this function at
/// all, and you just supplied a `Span` to create the diagnostic,
self
}
+ /// Prints out a message with for a multipart suggestion without showing the suggested code.
+ ///
+ /// This is intended to be used for suggestions that are obvious in what the changes need to
+ /// be from the message, showing the span label inline would be visually unpleasant
+ /// (marginally overlapping spans or multiline spans) and showing the snippet window wouldn't
+ /// improve understandability.
+ pub fn tool_only_multipart_suggestion(
+ &mut self,
+ msg: &str,
+ suggestion: Vec<(Span, String)>,
+ applicability: Applicability,
+ ) -> &mut Self {
+ self.suggestions.push(CodeSuggestion {
+ substitutions: vec![Substitution {
+ parts: suggestion
+ .into_iter()
+ .map(|(span, snippet)| SubstitutionPart { snippet, span })
+ .collect(),
+ }],
+ msg: msg.to_owned(),
+ style: SuggestionStyle::CompletelyHidden,
+ applicability,
+ });
+ self
+ }
+
/// Prints out a message with a suggested edit of the code.
///
/// In case of short messages and a simple suggestion, rustc displays it as a label:
}],
msg: msg.to_owned(),
style: SuggestionStyle::HideCodeInline,
- applicability: applicability,
+ applicability,
});
self
}
}],
msg: msg.to_owned(),
style: SuggestionStyle::HideCodeInline,
+ applicability,
+ });
+ 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