Allow diagnostics to generate multi-edit fixes (#3709)

This commit is contained in:
Charlie Marsh 2023-03-26 16:45:19 -04:00 committed by GitHub
parent 32be63fd1e
commit e603382cf0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
731 changed files with 17319 additions and 13447 deletions

View file

@ -38,13 +38,18 @@ bitflags! {
}
#[derive(Serialize)]
struct ExpandedFix<'a> {
struct ExpandedEdit<'a> {
content: &'a str,
message: Option<&'a str>,
location: &'a Location,
end_location: &'a Location,
}
#[derive(Serialize)]
struct ExpandedFix<'a> {
message: Option<&'a str>,
edits: Vec<ExpandedEdit<'a>>,
}
#[derive(Serialize)]
struct ExpandedMessage<'a> {
code: SerializeRuleAsCode,
@ -197,12 +202,23 @@ impl Printer {
.map(|message| ExpandedMessage {
code: message.kind.rule().into(),
message: message.kind.body.clone(),
fix: message.fix.as_ref().map(|fix| ExpandedFix {
content: &fix.content,
location: &fix.location,
end_location: &fix.end_location,
message: message.kind.suggestion.as_deref(),
}),
fix: if message.fix.is_empty() {
None
} else {
Some(ExpandedFix {
message: message.kind.suggestion.as_deref(),
edits: message
.fix
.edits()
.iter()
.map(|edit| ExpandedEdit {
content: &edit.content,
location: &edit.location,
end_location: &edit.end_location,
})
.collect(),
})
},
location: message.location,
end_location: message.end_location,
filename: &message.filename,