Skip to content

Commit

Permalink
Respect changes in playground
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh committed Mar 26, 2023
1 parent 460a7e4 commit 506511e
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 23 deletions.
8 changes: 8 additions & 0 deletions crates/ruff_diagnostics/src/fix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ impl Fix {
}
}

impl FromIterator<Edit> for Fix {
fn from_iter<T: IntoIterator<Item = Edit>>(iter: T) -> Self {
Self {
edits: Vec::from_iter(iter),
}
}
}

impl From<Edit> for Fix {
fn from(edit: Edit) -> Self {
Self { edits: vec![edit] }
Expand Down
20 changes: 11 additions & 9 deletions crates/ruff_wasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,18 @@ export interface Diagnostic {
column: number;
};
fix: {
content: string;
message: string | null;
location: {
row: number;
column: number;
};
end_location: {
row: number;
column: number;
};
edits: {
content: string;
location: {
row: number;
column: number;
};
end_location: {
row: number;
column: number;
};
}[];
} | null;
};
"#;
Expand Down
28 changes: 14 additions & 14 deletions playground/src/Editor/SourceEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,27 +57,27 @@ export default function SourceEditor({
.filter((check) => check.fix)
.map((check) => ({
title: check.fix
? `${check.code}: ${check.fix.message}` ?? `Fix ${check.code}`
? check.fix.message
? `${check.code}: ${check.fix.message}`
: `Fix ${check.code}`
: "Autofix",
id: `fix-${check.code}`,
kind: "quickfix",
edit: check.fix
? {
edits: [
{
resource: model.uri,
versionId: model.getVersionId(),
edit: {
range: {
startLineNumber: check.fix.location.row,
startColumn: check.fix.location.column + 1,
endLineNumber: check.fix.end_location.row,
endColumn: check.fix.end_location.column + 1,
},
text: check.fix.content,
edits: check.fix.edits.map((edit) => ({
resource: model.uri,
versionId: model.getVersionId(),
edit: {
range: {
startLineNumber: edit.location.row,
startColumn: edit.location.column + 1,
endLineNumber: edit.end_location.row,
endColumn: edit.end_location.column + 1,
},
text: edit.content,
},
],
})),
}
: undefined,
}));
Expand Down

0 comments on commit 506511e

Please sign in to comment.