Expose hidden snippet suggestions
This commit is contained in:
parent
05b4e7c8a9
commit
6ea159ea7e
2 changed files with 43 additions and 0 deletions
|
|
@ -323,6 +323,29 @@ impl Diagnostic {
|
|||
self
|
||||
}
|
||||
|
||||
/// Prints out a message with for a 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 span_suggestion_hidden(
|
||||
&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::HideCodeInline,
|
||||
applicability: applicability,
|
||||
});
|
||||
self
|
||||
}
|
||||
|
||||
pub fn set_span<S: Into<MultiSpan>>(&mut self, sp: S) -> &mut Self {
|
||||
self.span = sp.into();
|
||||
self
|
||||
|
|
|
|||
|
|
@ -261,6 +261,26 @@ impl<'a> DiagnosticBuilder<'a> {
|
|||
);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn span_suggestion_hidden(
|
||||
&mut self,
|
||||
sp: Span,
|
||||
msg: &str,
|
||||
suggestion: String,
|
||||
applicability: Applicability,
|
||||
) -> &mut Self {
|
||||
if !self.allow_suggestions {
|
||||
return self
|
||||
}
|
||||
self.diagnostic.span_suggestion_hidden(
|
||||
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);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue