Skip to content
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
30 changes: 5 additions & 25 deletions Cargo.lock

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

21 changes: 11 additions & 10 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,18 @@ toml = "0.8"
# needs real I/O (git fetch, filesystem), so it's off by default for
# `comline-core`'s wasm32 consumers (the playground editor, the language
# server); the CLI is the one consumer that actually runs `comline build`.
comline-core = { git = "https://github.com/ComlineProject/core", rev = "5e6cc3af04964590b43c3c53f8924f474f00951e", features = ["deps"] }
# All three pinned to revs that already agree on comline-core@5e6cc3a
# (core#67's block-comment support) - bumped together: generation#34's
# branch-tip commit (comline-rust/comline-typescript's own codegen crates
# consume `comline-codegen`'s types, so this pins the exact same generation
# rev they do - a5b1b31, not generation's later merge commit, since Cargo
comline-core = { git = "https://github.com/ComlineProject/core", rev = "f8861a8716ff597e8623ce0b3f067eda0ea1923b", features = ["deps"] }
# All three pinned to revs that already agree on comline-core@f8861a8
# (core#69 - the Diagnostic rename + dead-code cleanup half of the
# error-reporting work) - bumped together: generation#35's branch-tip
# commit (comline-rust/comline-typescript's own codegen crates consume
# `comline-codegen`'s types, so this pins the exact same generation rev
# they do - 5682674, not generation's later merge commit, since Cargo
# only unifies a git dependency across byte-identical revs), then
# comline-rust#23 and comline-typescript#20.
comline-codegen = { git = "https://github.com/ComlineProject/generation", rev = "a5b1b319e810fe5723ee94966ec174c6a1b2e7f1" }
comline-codegen-rust = { git = "https://github.com/ComlineProject/comline-rust", rev = "6b3f4ffd027b37219efa36e167f769e7362821cc", optional = true }
comline-codegen-typescript = { git = "https://github.com/ComlineProject/comline-typescript", rev = "56bea641f6d163120006e853bff4eec4d0a7c88e", optional = true }
# comline-rust#24 and comline-typescript#21.
comline-codegen = { git = "https://github.com/ComlineProject/generation", rev = "56826746326799e7cfbf988deb80156c3a4bcdfb" }
comline-codegen-rust = { git = "https://github.com/ComlineProject/comline-rust", rev = "9366ea18b706aed357c3c745f239c32797048780", optional = true }
comline-codegen-typescript = { git = "https://github.com/ComlineProject/comline-typescript", rev = "132630a7d61ec7a2c6425b50bce716098befe617", optional = true }

[features]
# Which language generators are compiled in. Drop one to shed its whole
Expand Down
5 changes: 5 additions & 0 deletions src/commands/generate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,11 @@ fn generate_once(work_dir: &Path, overrides: &Overrides) -> Result<()> {
},
default_framing: t.default_framing.clone(),
};
// Deliberately not `core_err`: a generator's errors are about
// schema/package *structure* (e.g. a namespace that's both a
// schema and a parent of deeper schemas), not source *text* -
// they carry no span to render a snippet against, so there's
// nothing for the multi-line branch there to do.
let files =
generator(&request).map_err(|e| miette!("`{}` generator: {e}", t.language))?;

Expand Down
14 changes: 12 additions & 2 deletions src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,17 @@ pub fn ensure_project(dir: &Path) -> Result<()> {
}

/// Wrap a `comline-core` (`eyre`) error as a `miette` one for the reporting
/// path. `{:#}` renders the message plus its cause chain, without a backtrace.
/// path. `{:#}` renders the message plus its cause chain, without a
/// backtrace. `comline-core`'s own diagnostics (parse/validation errors)
/// now arrive as a multi-line, already-rendered `ariadne` source snippet
/// (`comline_core::diagnostics::render`) - gluing `"{context}: "` onto the
/// front of that would run the prefix into the snippet's own box-drawing on
/// one line, so a multi-line detail gets its own paragraph instead.
pub fn core_err(context: &str, e: impl std::fmt::Display) -> miette::Report {
miette::miette!("{context}: {e:#}")
let detail = format!("{e:#}");
if detail.contains('\n') {
miette::miette!("{context}:\n\n{detail}")
} else {
miette::miette!("{context}: {detail}")
}
}
44 changes: 44 additions & 0 deletions tests/cli/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,50 @@ fn reports_a_broken_schema() {
.stderr(predicate::str::contains("validation failed"));
}

#[test]
fn a_broken_schema_reports_a_source_snippet_not_a_debug_dump() {
let temp = tempfile::tempdir().unwrap();
let project = fixture_project(temp.path());
fs::write(
project.join("src/main.ids"),
"struct Greeting {\n / name: string\n}\n",
)
.unwrap();

comline_cmd()
.current_dir(&project)
.arg("check")
.assert()
.failure()
.code(1)
.stderr(predicate::str::contains("ParseError {").not())
.stderr(predicate::str::contains("FailedNode(").not())
.stderr(predicate::str::contains("main.ids"))
.stderr(predicate::str::contains("unexpected token"))
.stderr(predicate::str::is_match(r"\d+:\d+").unwrap());
}

#[test]
fn a_broken_config_idp_reports_a_source_snippet_not_a_debug_dump() {
let temp = tempfile::tempdir().unwrap();
let project = fixture_project(temp.path());
fs::write(
project.join("config.idp"),
"congregation test\nspecification_version =\n",
)
.unwrap();

comline_cmd()
.current_dir(&project)
.arg("check")
.assert()
.failure()
.code(1)
.stderr(predicate::str::contains("ParseError {").not())
.stderr(predicate::str::contains("FailedNode(").not())
.stderr(predicate::str::contains("config.idp"));
}

#[test]
fn std_is_usable_and_checked() {
let temp = tempfile::tempdir().unwrap();
Expand Down
Loading