Skip to content

Commit

Permalink
Handle colors correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
neunenak committed Dec 2, 2024
1 parent 8844b43 commit 4bf2f3e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 66 deletions.
64 changes: 6 additions & 58 deletions src/compile_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ impl<'src> CompileError<'src> {
}
}

pub(crate) fn render_compile_error(error: &CompileError) {
use ariadne::{Label, Report, ReportKind, Source};
pub(crate) fn render_compile_error(error: &CompileError, color: Color) {
use ariadne::{Config, Label, Report, ReportKind, Source};

let token = error.token;
let source = Source::from(token.src);
Expand All @@ -31,7 +31,8 @@ pub(crate) fn render_compile_error(error: &CompileError) {
let path = format!("{}", token.path.display());
let label = Label::new((&path, start..end));

let report = Report::build(ReportKind::Error, &path, start);
let config = Config::default().with_color(color.stderr().active());
let report = Report::build(ReportKind::Error, &path, start).with_config(config);

let report = match &*error.kind {
CompileErrorKind::AttributeArgumentCountMismatch {
Expand All @@ -49,27 +50,17 @@ pub(crate) fn render_compile_error(error: &CompileError) {
};

report
.with_code("E01")
.with_message("Attribute argument count mismatch")
.with_label(label.with_message(label_msg))
.with_note(note)
.finish()
}
/*
CompileErrorKind::BacktickShebang => todo!(),
CompileErrorKind::CircularRecipeDependency { recipe, circle } => todo!(),
CompileErrorKind::CircularVariableDependency { variable, circle } => todo!(),
CompileErrorKind::DependencyArgumentCountMismatch { dependency, found, min, max } => todo!(),
CompileErrorKind::Redefinition { first, first_type, name, second_type } => todo!(),
*/
CompileErrorKind::DuplicateAttribute { attribute, first } => {
let original_label = source
.line(*first)
.map(|line| Label::new((&path, line.span())).with_message("original"));

let mut report = report
.with_code("E02")
.with_message(format!("Duplicate attribute `{attribute}`"));
let mut report = report.with_message(format!("Duplicate attribute `{attribute}`"));
if let Some(original) = original_label {
report = report.with_label(original);
}
Expand All @@ -78,50 +69,7 @@ pub(crate) fn render_compile_error(error: &CompileError) {
_ => {
let message = format!("{error}");
report.with_message(message).with_label(label).finish()
} /*
CompileErrorKind::DuplicateParameter { recipe, parameter } => todo!(),
CompileErrorKind::DuplicateSet { setting, first } => todo!(),
CompileErrorKind::DuplicateVariable { variable } => todo!(),
CompileErrorKind::DuplicateUnexport { variable } => todo!(),
CompileErrorKind::ExpectedKeyword { expected, found } => todo!(),
CompileErrorKind::ExportUnexported { variable } => todo!(),
CompileErrorKind::ExtraLeadingWhitespace => todo!(),
CompileErrorKind::ExtraneousAttributes { count } => todo!(),
CompileErrorKind::FunctionArgumentCountMismatch { function, found, expected } => todo!(),
CompileErrorKind::Include => todo!(),
CompileErrorKind::InconsistentLeadingWhitespace { expected, found } => todo!(),
CompileErrorKind::Internal { message } => todo!(),
CompileErrorKind::InvalidAttribute { item_kind, item_name, attribute } => todo!(),
CompileErrorKind::InvalidEscapeSequence { character } => todo!(),
CompileErrorKind::MismatchedClosingDelimiter { close, open, open_line } => todo!(),
CompileErrorKind::MixedLeadingWhitespace { whitespace } => todo!(),
CompileErrorKind::ParameterFollowsVariadicParameter { parameter } => todo!(),
CompileErrorKind::ParsingRecursionDepthExceeded => todo!(),
CompileErrorKind::RequiredParameterFollowsDefaultParameter { parameter } => todo!(),
CompileErrorKind::ShebangAndScriptAttribute { recipe } => todo!(),
CompileErrorKind::ShellExpansion { err } => todo!(),
CompileErrorKind::UndefinedVariable { variable } => todo!(),
CompileErrorKind::UnexpectedCharacter { expected } => todo!(),
CompileErrorKind::UnexpectedClosingDelimiter { close } => todo!(),
CompileErrorKind::UnexpectedEndOfToken { expected } => todo!(),
CompileErrorKind::UnexpectedToken { expected, found } => todo!(),
CompileErrorKind::UnicodeEscapeCharacter { character } => todo!(),
CompileErrorKind::UnicodeEscapeDelimiter { character } => todo!(),
CompileErrorKind::UnicodeEscapeEmpty => todo!(),
CompileErrorKind::UnicodeEscapeLength { hex } => todo!(),
CompileErrorKind::UnicodeEscapeRange { hex } => todo!(),
CompileErrorKind::UnicodeEscapeUnterminated => todo!(),
CompileErrorKind::UnknownAliasTarget { alias, target } => todo!(),
CompileErrorKind::UnknownAttribute { attribute } => todo!(),
CompileErrorKind::UnknownDependency { recipe, unknown } => todo!(),
CompileErrorKind::UnknownFunction { function } => todo!(),
CompileErrorKind::UnknownSetting { setting } => todo!(),
CompileErrorKind::UnknownStartOfToken => todo!(),
CompileErrorKind::UnpairedCarriageReturn => todo!(),
CompileErrorKind::UnterminatedBacktick => todo!(),
CompileErrorKind::UnterminatedInterpolation => todo!(),
CompileErrorKind::UnterminatedString => todo!(),
*/
}
};

report.eprint((&path, source)).unwrap();
Expand Down
2 changes: 1 addition & 1 deletion src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ impl ColorDisplay for Error<'_> {

pub(crate) fn render_error(error: &Error, color: Color) {
match error {
Error::Compile { compile_error } => compile_error::render_compile_error(compile_error),
Error::Compile { compile_error } => compile_error::render_compile_error(compile_error, color),
_ => eprintln!("{}", error.color_display(color.stderr())),
}
}
Expand Down
14 changes: 7 additions & 7 deletions tests/subsequents.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ test! {
justfile: "
foo: && foo
",
stderr: "
error: Recipe `foo` depends on itself
β€”β€”β–Ά justfile:1:9
β”‚
1 β”‚ foo: && foo
β”‚ ^^^
",
stderr:
"Error: Recipe `foo` depends on itself
╭─[justfile:1:9]
β”‚
1 β”‚ foo: && foo
───╯
",
status: EXIT_FAILURE,
}

Expand Down

0 comments on commit 4bf2f3e

Please sign in to comment.