Skip to content

Commit

Permalink
Use diagnostic severity in cairo formatter
Browse files Browse the repository at this point in the history
commit-id:d7f87008
  • Loading branch information
maciektr committed Dec 7, 2023
1 parent 31b92d4 commit 558479d
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 58 deletions.
57 changes: 29 additions & 28 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 20 additions & 20 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,26 +31,26 @@ assert_fs = "1"
async-trait = "0.1"
axum = { version = "0.6", features = ["http2"] }
cairo-felt = "0.9"
cairo-lang-casm = { git = "https://github.com/starkware-libs/cairo.git", rev = "a4e7753f73b9731fe08c50a2f3af2b39e11ae657" }
cairo-lang-compiler = { git = "https://github.com/starkware-libs/cairo.git", rev = "a4e7753f73b9731fe08c50a2f3af2b39e11ae657" }
cairo-lang-diagnostics = { git = "https://github.com/starkware-libs/cairo.git", rev = "a4e7753f73b9731fe08c50a2f3af2b39e11ae657" }
cairo-lang-debug = { git = "https://github.com/starkware-libs/cairo.git", rev = "a4e7753f73b9731fe08c50a2f3af2b39e11ae657" }
cairo-lang-defs = { git = "https://github.com/starkware-libs/cairo.git", rev = "a4e7753f73b9731fe08c50a2f3af2b39e11ae657" }
cairo-lang-filesystem = { git = "https://github.com/starkware-libs/cairo.git", rev = "a4e7753f73b9731fe08c50a2f3af2b39e11ae657" }
cairo-lang-formatter = { git = "https://github.com/starkware-libs/cairo.git", rev = "a4e7753f73b9731fe08c50a2f3af2b39e11ae657" }
cairo-lang-language-server = { git = "https://github.com/starkware-libs/cairo.git", rev = "a4e7753f73b9731fe08c50a2f3af2b39e11ae657" }
cairo-lang-lowering = { git = "https://github.com/starkware-libs/cairo.git", rev = "a4e7753f73b9731fe08c50a2f3af2b39e11ae657" }
cairo-lang-project = { git = "https://github.com/starkware-libs/cairo.git", rev = "a4e7753f73b9731fe08c50a2f3af2b39e11ae657" }
cairo-lang-runner = { git = "https://github.com/starkware-libs/cairo.git", rev = "a4e7753f73b9731fe08c50a2f3af2b39e11ae657" }
cairo-lang-semantic = { git = "https://github.com/starkware-libs/cairo.git", rev = "a4e7753f73b9731fe08c50a2f3af2b39e11ae657" }
cairo-lang-sierra = { git = "https://github.com/starkware-libs/cairo.git", rev = "a4e7753f73b9731fe08c50a2f3af2b39e11ae657" }
cairo-lang-sierra-generator = { git = "https://github.com/starkware-libs/cairo.git", rev = "a4e7753f73b9731fe08c50a2f3af2b39e11ae657" }
cairo-lang-sierra-to-casm = { git = "https://github.com/starkware-libs/cairo.git", rev = "a4e7753f73b9731fe08c50a2f3af2b39e11ae657" }
cairo-lang-starknet = { git = "https://github.com/starkware-libs/cairo.git", rev = "a4e7753f73b9731fe08c50a2f3af2b39e11ae657" }
cairo-lang-syntax = { git = "https://github.com/starkware-libs/cairo.git", rev = "a4e7753f73b9731fe08c50a2f3af2b39e11ae657" }
cairo-lang-test-plugin = { git = "https://github.com/starkware-libs/cairo.git", rev = "a4e7753f73b9731fe08c50a2f3af2b39e11ae657" }
cairo-lang-test-runner = { git = "https://github.com/starkware-libs/cairo.git", rev = "a4e7753f73b9731fe08c50a2f3af2b39e11ae657" }
cairo-lang-utils = { git = "https://github.com/starkware-libs/cairo.git", rev = "a4e7753f73b9731fe08c50a2f3af2b39e11ae657", features = ["env_logger"] }
cairo-lang-casm = { git = "https://github.com/maciektr/cairo.git", rev = "dc55ecd69ffb87a524008e6daa7fec788471e3b5" }
cairo-lang-compiler = { git = "https://github.com/maciektr/cairo.git", rev = "dc55ecd69ffb87a524008e6daa7fec788471e3b5" }
cairo-lang-diagnostics = { git = "https://github.com/maciektr/cairo.git", rev = "dc55ecd69ffb87a524008e6daa7fec788471e3b5" }
cairo-lang-debug = { git = "https://github.com/maciektr/cairo.git", rev = "dc55ecd69ffb87a524008e6daa7fec788471e3b5" }
cairo-lang-defs = { git = "https://github.com/maciektr/cairo.git", rev = "dc55ecd69ffb87a524008e6daa7fec788471e3b5" }
cairo-lang-filesystem = { git = "https://github.com/maciektr/cairo.git", rev = "dc55ecd69ffb87a524008e6daa7fec788471e3b5" }
cairo-lang-formatter = { git = "https://github.com/maciektr/cairo.git", rev = "dc55ecd69ffb87a524008e6daa7fec788471e3b5" }
cairo-lang-language-server = { git = "https://github.com/maciektr/cairo.git", rev = "dc55ecd69ffb87a524008e6daa7fec788471e3b5" }
cairo-lang-lowering = { git = "https://github.com/maciektr/cairo.git", rev = "dc55ecd69ffb87a524008e6daa7fec788471e3b5" }
cairo-lang-project = { git = "https://github.com/maciektr/cairo.git", rev = "dc55ecd69ffb87a524008e6daa7fec788471e3b5" }
cairo-lang-runner = { git = "https://github.com/maciektr/cairo.git", rev = "dc55ecd69ffb87a524008e6daa7fec788471e3b5" }
cairo-lang-semantic = { git = "https://github.com/maciektr/cairo.git", rev = "dc55ecd69ffb87a524008e6daa7fec788471e3b5" }
cairo-lang-sierra = { git = "https://github.com/maciektr/cairo.git", rev = "dc55ecd69ffb87a524008e6daa7fec788471e3b5" }
cairo-lang-sierra-generator = { git = "https://github.com/maciektr/cairo.git", rev = "dc55ecd69ffb87a524008e6daa7fec788471e3b5" }
cairo-lang-sierra-to-casm = { git = "https://github.com/maciektr/cairo.git", rev = "dc55ecd69ffb87a524008e6daa7fec788471e3b5" }
cairo-lang-starknet = { git = "https://github.com/maciektr/cairo.git", rev = "dc55ecd69ffb87a524008e6daa7fec788471e3b5" }
cairo-lang-syntax = { git = "https://github.com/maciektr/cairo.git", rev = "dc55ecd69ffb87a524008e6daa7fec788471e3b5" }
cairo-lang-test-plugin = { git = "https://github.com/maciektr/cairo.git", rev = "dc55ecd69ffb87a524008e6daa7fec788471e3b5" }
cairo-lang-test-runner = { git = "https://github.com/maciektr/cairo.git", rev = "dc55ecd69ffb87a524008e6daa7fec788471e3b5" }
cairo-lang-utils = { git = "https://github.com/maciektr/cairo.git", rev = "dc55ecd69ffb87a524008e6daa7fec788471e3b5", features = ["env_logger"] }
camino = { version = "1", features = ["serde1"] }
cargo_metadata = ">=0.18"
clap = { version = "4", features = ["derive", "env", "string"] }
Expand Down
30 changes: 21 additions & 9 deletions scarb/src/ops/fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ use std::path::{Path, PathBuf};
use std::sync::atomic::{AtomicBool, Ordering};

use anyhow::Result;
use cairo_lang_diagnostics::Severity;
use cairo_lang_formatter::cairo_formatter::FormattingError;
use cairo_lang_formatter::{CairoFormatter, FormatOutcome, FormatterConfig};
use clap::ValueEnum;
use ignore::WalkState::{Continue, Skip};
Expand Down Expand Up @@ -108,15 +110,25 @@ fn print_diff(ws: &Workspace<'_>, path: &Path, diff: impl Display) {
.print(format!("Diff in file {}:\n {}", path.display(), diff));
}

fn print_error(ws: &Workspace<'_>, path: &Path, error: anyhow::Error) {
let error_msg = error.to_string();
ws.config().ui().error(format!(
"{}Error writing files: cannot parse {}",
// TODO(maciektr): Fix this with proper upstream changes.
// The slice is a hacky way of avoiding duplicated "error: " prefix.
&error_msg[7..],
path.display()
));
fn print_error(ws: &Workspace<'_>, path: &Path, error: FormattingError) {
match error {
FormattingError::ParsingError(error) => {
for entry in error.iter() {
let msg = entry
.message()
.strip_suffix('\n')
.unwrap_or(entry.message());
match entry.severity() {
Severity::Error => ws.config().ui().error(msg),
Severity::Warning => ws.config().ui().warn(msg),
};
}
}
FormattingError::Error(error) => {
let error = error.context(format!("cannot format file {}", path.display()));
ws.config().ui().error(error.to_string());
}
}
}

fn check_file_formatting(
Expand Down
1 change: 0 additions & 1 deletion scarb/tests/fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ fn simple_format_with_parsing_error() {
fn main() -> { 42 }
^
Error writing files: cannot parse [..]lib.cairo
"#});
}

Expand Down

0 comments on commit 558479d

Please sign in to comment.