Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use diagnostic severity in cairo formatter #986

Merged
merged 1 commit into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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/starkware-libs/cairo.git", rev = "e6c338c3a42fd7a50be8c27fbcc1c40173103094" }
cairo-lang-compiler = { git = "https://github.com/starkware-libs/cairo.git", rev = "e6c338c3a42fd7a50be8c27fbcc1c40173103094" }
cairo-lang-diagnostics = { git = "https://github.com/starkware-libs/cairo.git", rev = "e6c338c3a42fd7a50be8c27fbcc1c40173103094" }
cairo-lang-debug = { git = "https://github.com/starkware-libs/cairo.git", rev = "e6c338c3a42fd7a50be8c27fbcc1c40173103094" }
cairo-lang-defs = { git = "https://github.com/starkware-libs/cairo.git", rev = "e6c338c3a42fd7a50be8c27fbcc1c40173103094" }
cairo-lang-filesystem = { git = "https://github.com/starkware-libs/cairo.git", rev = "e6c338c3a42fd7a50be8c27fbcc1c40173103094" }
cairo-lang-formatter = { git = "https://github.com/starkware-libs/cairo.git", rev = "e6c338c3a42fd7a50be8c27fbcc1c40173103094" }
cairo-lang-language-server = { git = "https://github.com/starkware-libs/cairo.git", rev = "e6c338c3a42fd7a50be8c27fbcc1c40173103094" }
cairo-lang-lowering = { git = "https://github.com/starkware-libs/cairo.git", rev = "e6c338c3a42fd7a50be8c27fbcc1c40173103094" }
cairo-lang-project = { git = "https://github.com/starkware-libs/cairo.git", rev = "e6c338c3a42fd7a50be8c27fbcc1c40173103094" }
cairo-lang-runner = { git = "https://github.com/starkware-libs/cairo.git", rev = "e6c338c3a42fd7a50be8c27fbcc1c40173103094" }
cairo-lang-semantic = { git = "https://github.com/starkware-libs/cairo.git", rev = "e6c338c3a42fd7a50be8c27fbcc1c40173103094" }
cairo-lang-sierra = { git = "https://github.com/starkware-libs/cairo.git", rev = "e6c338c3a42fd7a50be8c27fbcc1c40173103094" }
cairo-lang-sierra-generator = { git = "https://github.com/starkware-libs/cairo.git", rev = "e6c338c3a42fd7a50be8c27fbcc1c40173103094" }
cairo-lang-sierra-to-casm = { git = "https://github.com/starkware-libs/cairo.git", rev = "e6c338c3a42fd7a50be8c27fbcc1c40173103094" }
cairo-lang-starknet = { git = "https://github.com/starkware-libs/cairo.git", rev = "e6c338c3a42fd7a50be8c27fbcc1c40173103094" }
cairo-lang-syntax = { git = "https://github.com/starkware-libs/cairo.git", rev = "e6c338c3a42fd7a50be8c27fbcc1c40173103094" }
cairo-lang-test-plugin = { git = "https://github.com/starkware-libs/cairo.git", rev = "e6c338c3a42fd7a50be8c27fbcc1c40173103094" }
cairo-lang-test-runner = { git = "https://github.com/starkware-libs/cairo.git", rev = "e6c338c3a42fd7a50be8c27fbcc1c40173103094" }
cairo-lang-utils = { git = "https://github.com/starkware-libs/cairo.git", rev = "e6c338c3a42fd7a50be8c27fbcc1c40173103094", 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());
maciektr marked this conversation as resolved.
Show resolved Hide resolved
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