mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-01 22:31:47 +00:00
Allow diagnostics to generate multi-edit fixes (#3709)
This commit is contained in:
parent
32be63fd1e
commit
e603382cf0
731 changed files with 17319 additions and 13447 deletions
|
@ -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,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue