Allow diagnostics to generate multi-edit fixes#3709
Conversation
5fb747f to
1fea8b6
Compare
1fea8b6 to
de40c98
Compare
|
The test fixture updates have intentionally omitted for now, to keep this PR reviewable. (All test fixtures will change in a mechanical way, as we're moving from a single fix to a vector of fixes.) |
PR Check ResultsEcosystem✅ ecosystem check detected no changes. BenchmarkLinuxWindows |
| impl From<Edit> for Fix { | ||
| fn from(edit: Edit) -> Self { | ||
| Self { edits: vec![edit] } | ||
| } | ||
| } |
There was a problem hiding this comment.
Nit: If this is used frequently, then I recommend adding a
pub fn from_edit(edit: Edit) -> Self {
}
function to Fix to make it more explicit. I always find From implementations hard to discover.
c6a8a56 to
b526d51
Compare
3055da9 to
506511e
Compare
726b3cd to
f22598a
Compare
f22598a to
3f140ad
Compare
|
@charliermarsh sorry to boring you on this, but this PR changes the The reason I mention this is, coc-pyright uses ruff's fix info to fix codes, but the format has been changed in this PR, coc-pyright will change to the new output format. Thank you for your work on ruff! |
|
@fannheyward - You're 100% right, I'm not sure how I missed that -- purely an oversight. I'll add it to |
Summary
This PR extends the autofix API to support multiple edits by introducing a basic
Fixstruct:...and propagating those changes throughout the codebase.
To demonstrate its usefulness, the
crates/ruff/src/rules/pyupgrade/rules/replace_stdout_stderr.rsrule was also refactored to leverage this new API. (That rule needs to remove two keyword arguments, which may or may not be adjacent, and replace them withcapture_output=True. Previously, this rule required that we included all intermediary content in the text edit. Now, we can model it as a replacement and a deletion.)There are a few changes that need to be made downstream, to tools that depend on our JSON API (namely, the playground and the LSP, the latter of which can be done in a backwards-compatible way).