diff --git a/Cargo.lock b/Cargo.lock index a46f52be2..b217f2d0e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4412,6 +4412,7 @@ dependencies = [ "async-trait", "cairo-lang-compiler", "cairo-lang-defs", + "cairo-lang-diagnostics", "cairo-lang-filesystem", "cairo-lang-formatter", "cairo-lang-semantic", diff --git a/scarb/Cargo.toml b/scarb/Cargo.toml index cfdc4a22e..910400a7f 100644 --- a/scarb/Cargo.toml +++ b/scarb/Cargo.toml @@ -18,6 +18,7 @@ anyhow.workspace = true async-trait.workspace = true cairo-lang-compiler.workspace = true cairo-lang-defs.workspace = true +cairo-lang-diagnostics.workspace = true cairo-lang-filesystem.workspace = true cairo-lang-formatter.workspace = true cairo-lang-semantic.workspace = true diff --git a/scarb/src/compiler/helpers.rs b/scarb/src/compiler/helpers.rs index 12affb6fd..d7f47e6bb 100644 --- a/scarb/src/compiler/helpers.rs +++ b/scarb/src/compiler/helpers.rs @@ -4,13 +4,12 @@ use anyhow::{Context, Result}; use cairo_lang_compiler::db::RootDatabase; use cairo_lang_compiler::diagnostics::DiagnosticsReporter; use cairo_lang_compiler::CompilerConfig; +use cairo_lang_diagnostics::Severity; use cairo_lang_filesystem::db::FilesGroup; use cairo_lang_filesystem::ids::{CrateId, CrateLongId}; use serde::Serialize; use std::io::{BufWriter, Write}; -use scarb_ui::components::TypedMessage; - use crate::compiler::CompilationUnit; use crate::core::Workspace; use crate::flock::Filesystem; @@ -18,10 +17,14 @@ use crate::flock::Filesystem; pub fn build_compiler_config<'c>(unit: &CompilationUnit, ws: &Workspace<'c>) -> CompilerConfig<'c> { let diagnostics_reporter = DiagnosticsReporter::callback({ let config = ws.config(); - |diagnostic: String| { - config - .ui() - .print(TypedMessage::naked_text("diagnostic", &diagnostic)); + + |severity: Severity, diagnostic: String| { + let msg = diagnostic.clone(); + let msg = msg.strip_suffix('\n').unwrap_or(diagnostic.as_str()); + match severity { + Severity::Error => config.ui().error(msg), + Severity::Warning => config.ui().warn(msg), + }; } }); CompilerConfig { diff --git a/scarb/tests/build.rs b/scarb/tests/build.rs index bf1fc6082..d9761662c 100644 --- a/scarb/tests/build.rs +++ b/scarb/tests/build.rs @@ -80,7 +80,6 @@ fn compile_with_syntax_error() { not_a_keyword ^***********^ - error: could not compile `hello` due to previous error "#}); } @@ -102,7 +101,7 @@ fn compile_with_syntax_error_json() { .code(1) .stdout_matches(indoc! {r#" {"status":"compiling","message":"hello v0.1.0 ([..]Scarb.toml)"} - {"type":"diagnostic","message":"error: Skipped tokens. Expected: Const/Module/Use/FreeFunction/ExternFunction/ExternType/Trait/Impl/Struct/Enum/TypeAlias/InlineMacro or an attribute./n --> [..]/lib.cairo:1:1/nnot_a_keyword/n^***********^/n/n"} + {"type":"error","message":"Skipped tokens. Expected: Const/Module/Use/FreeFunction/ExternFunction/ExternType/Trait/Impl/Struct/Enum/TypeAlias/InlineMacro or an attribute./n --> [..]/lib.cairo:1:1/nnot_a_keyword/n^***********^/n"} {"type":"error","message":"could not compile `hello` due to previous error"} "#}); } @@ -720,7 +719,6 @@ fn dev_dep_used_outside_tests() { use q::dev_dep_function; ^ - error: could not compile `x` due to previous error "#}); } @@ -779,12 +777,11 @@ fn warnings_allowed_by_default() { .success() .stdout_matches(indoc! {r#" [..] Compiling [..] v1.0.0 ([..]Scarb.toml) - warning: Unused variable. Consider ignoring by prefixing with `_`. + warn: Unused variable. Consider ignoring by prefixing with `_`. --> [..]lib.cairo:2:9 let a = 41; ^ - Finished release target(s) in [..] seconds "#}); } @@ -813,12 +810,11 @@ fn warnings_can_be_disallowed() { .failure() .stdout_matches(indoc! {r#" [..] Compiling [..] v1.0.0 ([..]Scarb.toml) - warning: Unused variable. Consider ignoring by prefixing with `_`. + warn: Unused variable. Consider ignoring by prefixing with `_`. --> [..]lib.cairo:2:9 let a = 41; ^ - error: could not compile [..] due to previous error "#}); } diff --git a/scarb/tests/build_starknet_contract.rs b/scarb/tests/build_starknet_contract.rs index 51e888776..9c0bd339d 100644 --- a/scarb/tests/build_starknet_contract.rs +++ b/scarb/tests/build_starknet_contract.rs @@ -363,7 +363,6 @@ fn compile_starknet_contract_without_starknet_dep() { #[starknet::contract] ^*******************^ - error: Plugin diagnostic: Unsupported attribute. --> [..]/lib.cairo:13:5 #[storage] @@ -414,7 +413,6 @@ fn compile_starknet_contract_without_starknet_dep() { self.value.write( self.value.read() + a ); ^***^ - error: could not compile `hello` due to previous error "#}); } diff --git a/scarb/tests/build_targets.rs b/scarb/tests/build_targets.rs index e8ed1483d..8a7ff116d 100644 --- a/scarb/tests/build_targets.rs +++ b/scarb/tests/build_targets.rs @@ -229,7 +229,6 @@ fn compile_dep_not_a_lib() { fn hellp() -> felt252 { dep::forty_two() } ^*^ - error: could not compile `hello` due to previous error "#}); } diff --git a/scarb/tests/package.rs b/scarb/tests/package.rs index 4d4c34a47..e7a4320a3 100644 --- a/scarb/tests/package.rs +++ b/scarb/tests/package.rs @@ -1257,7 +1257,6 @@ fn error_on_verification() { . ^ - error: failed to verify package tarball Caused by: