mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-28 12:55:05 +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(),
|
||||
}),
|
||||
}
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue