mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-03 18:28:56 +00:00
Fix autofix capabilities in playground (#5375)
## Summary
These had just bitrotted over time -- we were no longer passing along
the row-and-column indices, etc.
## Test Plan

This commit is contained in:
parent
8a1bb7a5af
commit
d53b986fd4
2 changed files with 27 additions and 13 deletions
|
@ -18,7 +18,6 @@ use ruff::rules::{
|
|||
use ruff::settings::configuration::Configuration;
|
||||
use ruff::settings::options::Options;
|
||||
use ruff::settings::{defaults, flags, Settings};
|
||||
use ruff_diagnostics::Edit;
|
||||
use ruff_python_ast::source_code::{Indexer, Locator, SourceLocation, Stylist};
|
||||
|
||||
#[wasm_bindgen(typescript_custom_section)]
|
||||
|
@ -37,7 +36,7 @@ export interface Diagnostic {
|
|||
fix: {
|
||||
message: string | null;
|
||||
edits: {
|
||||
content: string;
|
||||
content: string | null;
|
||||
location: {
|
||||
row: number;
|
||||
column: number;
|
||||
|
@ -51,12 +50,6 @@ export interface Diagnostic {
|
|||
};
|
||||
"#;
|
||||
|
||||
#[derive(Serialize, Deserialize, Eq, PartialEq, Debug)]
|
||||
pub struct ExpandedFix {
|
||||
message: Option<String>,
|
||||
edits: Vec<Edit>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Eq, PartialEq, Debug)]
|
||||
pub struct ExpandedMessage {
|
||||
pub code: String,
|
||||
|
@ -66,6 +59,19 @@ pub struct ExpandedMessage {
|
|||
pub fix: Option<ExpandedFix>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Eq, PartialEq, Debug)]
|
||||
pub struct ExpandedFix {
|
||||
message: Option<String>,
|
||||
edits: Vec<ExpandedEdit>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Eq, PartialEq, Debug)]
|
||||
struct ExpandedEdit {
|
||||
location: SourceLocation,
|
||||
end_location: SourceLocation,
|
||||
content: Option<String>,
|
||||
}
|
||||
|
||||
#[wasm_bindgen(start)]
|
||||
pub fn run() {
|
||||
use log::Level;
|
||||
|
@ -220,7 +226,15 @@ pub fn check(contents: &str, options: JsValue) -> Result<JsValue, JsValue> {
|
|||
end_location,
|
||||
fix: message.fix.map(|fix| ExpandedFix {
|
||||
message: message.kind.suggestion,
|
||||
edits: fix.into_edits(),
|
||||
edits: fix
|
||||
.into_edits()
|
||||
.into_iter()
|
||||
.map(|edit| ExpandedEdit {
|
||||
location: source_code.source_location(edit.start()),
|
||||
end_location: source_code.source_location(edit.end()),
|
||||
content: edit.content().map(ToString::to_string),
|
||||
})
|
||||
.collect(),
|
||||
}),
|
||||
}
|
||||
})
|
||||
|
|
|
@ -54,7 +54,7 @@ export default function SourceEditor({
|
|||
provideCodeActions: function (model, position) {
|
||||
const actions = diagnostics
|
||||
.filter((check) => position.startLineNumber === check.location.row)
|
||||
.filter((check) => check.fix)
|
||||
.filter(({ fix }) => fix)
|
||||
.map((check) => ({
|
||||
title: check.fix
|
||||
? check.fix.message
|
||||
|
@ -71,11 +71,11 @@ export default function SourceEditor({
|
|||
edit: {
|
||||
range: {
|
||||
startLineNumber: edit.location.row,
|
||||
startColumn: edit.location.column + 1,
|
||||
startColumn: edit.location.column,
|
||||
endLineNumber: edit.end_location.row,
|
||||
endColumn: edit.end_location.column + 1,
|
||||
endColumn: edit.end_location.column,
|
||||
},
|
||||
text: edit.content,
|
||||
text: edit.content || "",
|
||||
},
|
||||
})),
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue