Allow specifying multiple alternative suggestions
This allows porting uses of span_suggestions() to diagnostic structs. Doesn't work for multipart_suggestions() because the rank would be reversed - the struct would specify multiple spans, each of which has multiple possible replacements, while multipart_suggestions() creates multiple possible replacements, each with multiple spans.
This commit is contained in:
parent
9be2f35a4c
commit
8bc43f99e9
8 changed files with 263 additions and 26 deletions
|
@ -690,6 +690,24 @@ impl Diagnostic {
|
|||
msg: impl Into<SubdiagnosticMessage>,
|
||||
suggestions: impl Iterator<Item = String>,
|
||||
applicability: Applicability,
|
||||
) -> &mut Self {
|
||||
self.span_suggestions_with_style(
|
||||
sp,
|
||||
msg,
|
||||
suggestions,
|
||||
applicability,
|
||||
SuggestionStyle::ShowCode,
|
||||
)
|
||||
}
|
||||
|
||||
/// [`Diagnostic::span_suggestions()`] but you can set the [`SuggestionStyle`].
|
||||
pub fn span_suggestions_with_style(
|
||||
&mut self,
|
||||
sp: Span,
|
||||
msg: impl Into<SubdiagnosticMessage>,
|
||||
suggestions: impl Iterator<Item = String>,
|
||||
applicability: Applicability,
|
||||
style: SuggestionStyle,
|
||||
) -> &mut Self {
|
||||
let mut suggestions: Vec<_> = suggestions.collect();
|
||||
suggestions.sort();
|
||||
|
@ -706,14 +724,15 @@ impl Diagnostic {
|
|||
self.push_suggestion(CodeSuggestion {
|
||||
substitutions,
|
||||
msg: self.subdiagnostic_message_to_diagnostic_message(msg),
|
||||
style: SuggestionStyle::ShowCode,
|
||||
style,
|
||||
applicability,
|
||||
});
|
||||
self
|
||||
}
|
||||
|
||||
/// Prints out a message with multiple suggested edits of the code.
|
||||
/// See also [`Diagnostic::span_suggestion()`].
|
||||
/// Prints out a message with multiple suggested edits of the code, where each edit consists of
|
||||
/// multiple parts.
|
||||
/// See also [`Diagnostic::multipart_suggestion()`].
|
||||
pub fn multipart_suggestions(
|
||||
&mut self,
|
||||
msg: impl Into<SubdiagnosticMessage>,
|
||||
|
@ -745,6 +764,7 @@ impl Diagnostic {
|
|||
});
|
||||
self
|
||||
}
|
||||
|
||||
/// Prints out a message with a suggested edit of the code. If the suggestion is presented
|
||||
/// inline, it will only show the message and not the suggestion.
|
||||
///
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue