diff --git a/Cargo.lock b/Cargo.lock index 98cdcc6..2462e33 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -515,7 +515,7 @@ source = "git+https://github.com/ComlineProject/runtime?rev=8f8c0cb6fb0bc3a734aa [[package]] name = "comline-codegen" version = "0.1.0" -source = "git+https://github.com/ComlineProject/generation?rev=332e0f0357a67b12e335a89a3036b2cd0bf1a7be#332e0f0357a67b12e335a89a3036b2cd0bf1a7be" +source = "git+https://github.com/ComlineProject/generation?rev=05771e0679ff514da3ba73a3b0b94643e5262fe5#05771e0679ff514da3ba73a3b0b94643e5262fe5" dependencies = [ "comline-core", "eyre", @@ -529,7 +529,7 @@ dependencies = [ [[package]] name = "comline-codegen-rust" version = "0.1.0" -source = "git+https://github.com/ComlineProject/comline-rust?rev=2659fbf6daf6da96d320905604dc2b88a48f31d8#2659fbf6daf6da96d320905604dc2b88a48f31d8" +source = "git+https://github.com/ComlineProject/comline-rust?rev=df91e2e0a416cab594303f11d44a6555a72f891b#df91e2e0a416cab594303f11d44a6555a72f891b" dependencies = [ "comline-codegen", "comline-core", @@ -539,7 +539,7 @@ dependencies = [ [[package]] name = "comline-codegen-typescript" version = "0.1.0" -source = "git+https://github.com/ComlineProject/comline-typescript?rev=c5d80c772631de17b03c0b039321887707a80e4d#c5d80c772631de17b03c0b039321887707a80e4d" +source = "git+https://github.com/ComlineProject/comline-typescript?rev=8d829be859feac26d775f4877f098fedc38fdd9f#8d829be859feac26d775f4877f098fedc38fdd9f" dependencies = [ "comline-codegen", "comline-core", @@ -549,7 +549,7 @@ dependencies = [ [[package]] name = "comline-core" version = "0.1.0" -source = "git+https://github.com/ComlineProject/core?rev=e4c54404657337ae24c7c30ec67a781960cbd652#e4c54404657337ae24c7c30ec67a781960cbd652" +source = "git+https://github.com/ComlineProject/core?rev=868e8310e33df317e3cba4f76b81fbcd8639c1c2#868e8310e33df317e3cba4f76b81fbcd8639c1c2" dependencies = [ "ariadne", "blake3", @@ -579,12 +579,12 @@ dependencies = [ [[package]] name = "comline-core-stdlib" version = "0.1.0" -source = "git+https://github.com/ComlineProject/core?rev=e4c54404657337ae24c7c30ec67a781960cbd652#e4c54404657337ae24c7c30ec67a781960cbd652" +source = "git+https://github.com/ComlineProject/core?rev=868e8310e33df317e3cba4f76b81fbcd8639c1c2#868e8310e33df317e3cba4f76b81fbcd8639c1c2" [[package]] name = "comline-doc-html" version = "0.1.0" -source = "git+https://github.com/ComlineProject/generation?rev=332e0f0357a67b12e335a89a3036b2cd0bf1a7be#332e0f0357a67b12e335a89a3036b2cd0bf1a7be" +source = "git+https://github.com/ComlineProject/generation?rev=05771e0679ff514da3ba73a3b0b94643e5262fe5#05771e0679ff514da3ba73a3b0b94643e5262fe5" dependencies = [ "comline-codegen", "eyre", @@ -595,7 +595,7 @@ dependencies = [ [[package]] name = "comline-doc-markdown" version = "0.1.0" -source = "git+https://github.com/ComlineProject/generation?rev=332e0f0357a67b12e335a89a3036b2cd0bf1a7be#332e0f0357a67b12e335a89a3036b2cd0bf1a7be" +source = "git+https://github.com/ComlineProject/generation?rev=05771e0679ff514da3ba73a3b0b94643e5262fe5#05771e0679ff514da3ba73a3b0b94643e5262fe5" dependencies = [ "comline-codegen", "eyre", diff --git a/Cargo.toml b/Cargo.toml index 242195e..3699677 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -32,20 +32,20 @@ eyre = "0.6.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 = "e4c54404657337ae24c7c30ec67a781960cbd652", features = ["deps"] } +comline-core = { git = "https://github.com/ComlineProject/core", rev = "868e8310e33df317e3cba4f76b81fbcd8639c1c2", features = ["deps"] } # All three pinned to revs that agree on one `comline-codegen`, and bumped # together: comline-rust and comline-typescript's codegen crates consume # `comline-codegen`'s types, so the rev below must be byte-identical to the # one *they* pin - Cargo only unifies a git dependency across identical rev # strings, and two copies of `GenRequest` are two incompatible types. -comline-codegen = { git = "https://github.com/ComlineProject/generation", rev = "332e0f0357a67b12e335a89a3036b2cd0bf1a7be" } +comline-codegen = { git = "https://github.com/ComlineProject/generation", rev = "05771e0679ff514da3ba73a3b0b94643e5262fe5" } # The official Markdown and HTML documentation renderers (`comline doc`), # linked in like the official generators. Same generation rev as # `comline-codegen`. -comline-doc-markdown = { git = "https://github.com/ComlineProject/generation", rev = "332e0f0357a67b12e335a89a3036b2cd0bf1a7be" } -comline-doc-html = { git = "https://github.com/ComlineProject/generation", rev = "332e0f0357a67b12e335a89a3036b2cd0bf1a7be" } -comline-codegen-rust = { git = "https://github.com/ComlineProject/comline-rust", rev = "2659fbf6daf6da96d320905604dc2b88a48f31d8", optional = true } -comline-codegen-typescript = { git = "https://github.com/ComlineProject/comline-typescript", rev = "c5d80c772631de17b03c0b039321887707a80e4d", optional = true } +comline-doc-markdown = { git = "https://github.com/ComlineProject/generation", rev = "05771e0679ff514da3ba73a3b0b94643e5262fe5" } +comline-doc-html = { git = "https://github.com/ComlineProject/generation", rev = "05771e0679ff514da3ba73a3b0b94643e5262fe5" } +comline-codegen-rust = { git = "https://github.com/ComlineProject/comline-rust", rev = "df91e2e0a416cab594303f11d44a6555a72f891b", optional = true } +comline-codegen-typescript = { git = "https://github.com/ComlineProject/comline-typescript", rev = "8d829be859feac26d775f4877f098fedc38fdd9f", optional = true } # `comline conformance`: the conformance runner (corpus loading, judging, # profile proofs) and its case format, a public spec. Pinned by git rev. comline-runtime-conformance = { git = "https://github.com/ComlineProject/runtime", rev = "8f8c0cb6fb0bc3a734aafbdbbf187fb9da73e00d" } diff --git a/src/commands/generation.rs b/src/commands/generation.rs index 36b09cf..814e461 100644 --- a/src/commands/generation.rs +++ b/src/commands/generation.rs @@ -9,7 +9,6 @@ //! `compile_package` — no `.comline/` write, no version bump. `"all"` or an //! explicit list reads committed versions from the CAS chain instead. -use std::collections::BTreeMap; use std::path::{Path, PathBuf}; use std::time::Duration; @@ -26,8 +25,9 @@ use comline_codegen::docs::{self, Topic}; use comline_codegen::protocol::{Description, TargetLanguage}; use comline_codegen::versions::LangVersion; use comline_codegen::{ - connections, features, GenerateRequest, Mode, PackageMeta, Registry, Resolved, Unresolved, + checks, features, GenerateRequest, Mode, PackageMeta, Registry, Resolved, Unresolved, }; +use comline_core::diagnostics::{Diagnostic, Severity}; use comline_core::package::build::{self, cas::ObjectStore}; use comline_core::package::config::ir::frozen::{self, FrozenUnit as ConfigUnit}; use comline_core::schema::idl::constants::SCHEMA_EXTENSION; @@ -369,11 +369,17 @@ fn generate_once(work_dir: &Path, overrides: &Overrides, dry_run: bool, list: bo // 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. - if let Source::Builtin(resolved) = &source { - warn_ignored(&t.language, &request, resolved); + // What there is to know about this target before it generates: + // what its generator ignores (a built-in one's table is the only + // one known here), an `async` that does nothing, and the + // package's connection. + let resolved = match &source { + Source::Builtin(resolved) => Some(resolved), + Source::External(_) => None, + }; + for diagnostic in checks::generation(&request, resolved, connections_doc.as_deref()) { + report(&t.language, &diagnostic)?; } - warn_async_unused(&t.language, &request); - warn_no_package_connection(&t.language, &request, connections_doc.as_deref()); // Both kinds answer the same protocol request, and either // response is checked whole - every path, the total size - // before anything below writes a file. @@ -626,168 +632,24 @@ fn facts_for( Ok(Some(facts)) } -/// `async = true` changes only protocols on a connection; with none, the -/// output is the same as without it, which looks like the setting did nothing. -/// A protocol is on one by default when its framing's frames go both ways and -/// name the protocol, so that's a package whose protocols are all lockstep: -/// each on a framing that keeps it off a connection -/// ([`connections::why_lockstep`]), which the warning names. -fn warn_async_unused(language: &str, request: &GenerateRequest) { - if !request.async_api { - return; - } - - let uses = features::used(&request.schemas, &features::Options::of(request)); - if uses.iter().any(|u| u.feature == features::Feature::Async) { - return; - } - - let lockstep: Vec = framings_in_use(request) - .iter() - .filter_map(|framing| lockstep_description(framing)) - .collect(); - - let why = if lockstep.is_empty() { - "the package has no protocols".to_owned() - } else { - format!( - "every protocol here is lockstep: on {}", - lockstep.join(" or ") - ) +/// Show one of generation's checks for the target `language`, as the severity +/// its code has: a warning, a note, or an error that stops generation. +/// +/// The messages are written for a reader who has the target named beside +/// them, so this puts the language in front. The diagnostic's `unit` (where +/// in the package it is) isn't shown yet; nothing here drops it before then. +fn report(language: &str, diagnostic: &Diagnostic) -> Result<()> { + // The message of an ignored feature continues "ignores". + let message = match diagnostic.code.id == checks::IGNORED_FEATURE.id { + true => format!("`{language}` ignores {}", diagnostic.message), + false => format!("`{language}`: {}", diagnostic.message), }; - ui::warn(format!( - "`{language}`: `async = true`, but no protocol runs on a connection, so the output \ - is the same as without it - {why}" - )); -} - -/// The framings the package's protocols are on, canonical (`jsonrpc`, -/// `datagram@2`, `com.acme.lines@1`), once each. -fn framings_in_use(request: &GenerateRequest) -> std::collections::BTreeSet { - let mut framings = std::collections::BTreeSet::new(); - for (_, units) in &request.schemas { - for unit in units { - if let FrozenUnit::Protocol { parameters, .. } = unit { - framings.insert(connections::framing_name(parameters)); - } - } + match diagnostic.effective_severity() { + Severity::Error => return Err(miette!("{message}")), + Severity::Warning => ui::warn(message), + Severity::Info | Severity::Hint => ui::note(message), } - framings -} - -/// A framing for a message about protocols that aren't on a connection: its -/// title, and why its protocols stay off one unless the client provides -/// them. `None` for a framing that has no such reason (its frames go both -/// ways and name the protocol), where a protocol is on a connection already. -fn lockstep_description(framing: &str) -> Option { - let reason = match connections::why_lockstep(framing)? { - connections::Lockstep::OneDirection => { - "its frames go one way, so the server can't call the client" - } - connections::Lockstep::UnnamedServerProvided => { - "its frames don't name the protocol, and none of its protocols is client-provided" - } - connections::Lockstep::Unknown => { - "a framing of the package's own: a protocol on it is on a connection only when \ - the client provides it" - } - }; - - Some(format!( - "{} ({reason})", - connections::framing_title(framing) - )) -} - -/// The package's `serve` / `connect` need its protocols on one connection; -/// when they disagree on the framing or handshake, the generators leave them -/// out, which would otherwise look like they forgot. -fn warn_no_package_connection( - language: &str, - request: &GenerateRequest, - connections_doc: Option<&str>, -) { - match connections::package_connection(&request.schemas) { - Err(reason) => ui::warn(format!( - "`{language}`: no package `serve` / `connect` - {reason}; each protocol still has \ - its own" - )), - Ok(None) => note_no_connection_protocols(language, request, connections_doc), - Ok(Some(_)) => {} - } -} - -/// The silent case: protocols are declared, but none is on a connection, so -/// there is no `Services` / `serve` to look for. A package with no protocols -/// has nothing to serve and gets no note. `connections_doc` is the generator's -/// own page on connections, which the note links to when it has one. -fn note_no_connection_protocols( - language: &str, - request: &GenerateRequest, - connections_doc: Option<&str>, -) { - let framings = framings_in_use(request); - - if framings.is_empty() { - return; - } - - // Each framing's title and why it keeps its protocols off a connection; - // one with no such reason (not expected here) is just its title. - let framings: Vec = framings - .iter() - .map(|f| lockstep_description(f).unwrap_or_else(|| connections::framing_title(f))) - .collect(); - - let page = connections_doc - .map(|url| format!(" ({url})")) - .unwrap_or_default(); - - ui::note(format!( - "`{language}`: no package `Services` / `serve` / `connect` - every protocol is \ - server-provided on {}, and none is on a connection{page}", - framings.join(" or ") - )); -} - -/// A warning per feature `request` uses that this generator ignores - it -/// generates, but without the feature (a TypeScript target with -/// `@validators` gets the types, not the checks). An unsupported feature -/// needs nothing here: the generator refuses it, naming every use. -fn warn_ignored(language: &str, request: &GenerateRequest, resolved: &Resolved) { - let uses = features::used(&request.schemas, &features::Options::of(request)); - let mut ignored: BTreeMap> = BTreeMap::new(); - for u in &uses { - if resolved.support(u.feature).state == features::State::Ignored { - ignored.entry(u.feature).or_default().push(u); - } - } - - for (feature, uses) in ignored { - let s = resolved.support(feature); - let mut message = format!("`{language}` ignores {}", feature.title()); - - if let Some(note) = s.note { - message.push_str(&format!(": {note}")); - } - - if let Some(tracking) = s.tracking { - message.push_str(&format!(" ({tracking})")); - } - - let first = uses[0]; - let place = match first.namespace.is_empty() { - true => first.owner.clone(), - false => format!("schema '{}', {}", first.namespace, first.owner), - }; - - message.push_str(&format!(" - used by {place}")); - if uses.len() > 1 { - message.push_str(&format!(" and {} more", uses.len() - 1)); - } - - ui::warn(message); - } + Ok(()) } diff --git a/src/lang_targets.rs b/src/lang_targets.rs index e271c97..dd0d92d 100644 --- a/src/lang_targets.rs +++ b/src/lang_targets.rs @@ -249,8 +249,8 @@ pub fn check_declared(context: &ProjectContext, registry: &Registry) -> eyre::Re // JSON-RPC protocols on one connection whose bare method names a side // couldn't tell apart: no generator can emit them. - for clash in comline_codegen::connections::bare_name_clashes(&schemas, &framings) { - problems.push(format!("every target: {clash}")); + for clash in comline_codegen::checks::method_name_clashes(&schemas, &framings) { + problems.push(format!("every target: {}", clash.message)); } if problems.is_empty() { diff --git a/tests/fixtures/generators/Cargo.lock b/tests/fixtures/generators/Cargo.lock index 134e82e..a0ac331 100644 --- a/tests/fixtures/generators/Cargo.lock +++ b/tests/fixtures/generators/Cargo.lock @@ -84,7 +84,7 @@ source = "git+https://github.com/ComlineProject/specification?rev=6d39fc363ab3dc [[package]] name = "comline-codegen" version = "0.1.0" -source = "git+https://github.com/ComlineProject/generation?rev=332e0f0357a67b12e335a89a3036b2cd0bf1a7be#332e0f0357a67b12e335a89a3036b2cd0bf1a7be" +source = "git+https://github.com/ComlineProject/generation?rev=05771e0679ff514da3ba73a3b0b94643e5262fe5#05771e0679ff514da3ba73a3b0b94643e5262fe5" dependencies = [ "comline-core", "eyre", @@ -98,7 +98,7 @@ dependencies = [ [[package]] name = "comline-codegen-rust" version = "0.1.0" -source = "git+https://github.com/ComlineProject/comline-rust?rev=2659fbf6daf6da96d320905604dc2b88a48f31d8#2659fbf6daf6da96d320905604dc2b88a48f31d8" +source = "git+https://github.com/ComlineProject/comline-rust?rev=df91e2e0a416cab594303f11d44a6555a72f891b#df91e2e0a416cab594303f11d44a6555a72f891b" dependencies = [ "comline-codegen", "comline-core", @@ -108,7 +108,7 @@ dependencies = [ [[package]] name = "comline-core" version = "0.1.0" -source = "git+https://github.com/ComlineProject/core?rev=e4c54404657337ae24c7c30ec67a781960cbd652#e4c54404657337ae24c7c30ec67a781960cbd652" +source = "git+https://github.com/ComlineProject/core?rev=868e8310e33df317e3cba4f76b81fbcd8639c1c2#868e8310e33df317e3cba4f76b81fbcd8639c1c2" dependencies = [ "blake3", "ciborium", @@ -126,12 +126,12 @@ dependencies = [ [[package]] name = "comline-core-stdlib" version = "0.1.0" -source = "git+https://github.com/ComlineProject/core?rev=e4c54404657337ae24c7c30ec67a781960cbd652#e4c54404657337ae24c7c30ec67a781960cbd652" +source = "git+https://github.com/ComlineProject/core?rev=868e8310e33df317e3cba4f76b81fbcd8639c1c2#868e8310e33df317e3cba4f76b81fbcd8639c1c2" [[package]] name = "comline-doc-html" version = "0.1.0" -source = "git+https://github.com/ComlineProject/generation?rev=332e0f0357a67b12e335a89a3036b2cd0bf1a7be#332e0f0357a67b12e335a89a3036b2cd0bf1a7be" +source = "git+https://github.com/ComlineProject/generation?rev=05771e0679ff514da3ba73a3b0b94643e5262fe5#05771e0679ff514da3ba73a3b0b94643e5262fe5" dependencies = [ "comline-codegen", "eyre", @@ -142,7 +142,7 @@ dependencies = [ [[package]] name = "comline-doc-markdown" version = "0.1.0" -source = "git+https://github.com/ComlineProject/generation?rev=332e0f0357a67b12e335a89a3036b2cd0bf1a7be#332e0f0357a67b12e335a89a3036b2cd0bf1a7be" +source = "git+https://github.com/ComlineProject/generation?rev=05771e0679ff514da3ba73a3b0b94643e5262fe5#05771e0679ff514da3ba73a3b0b94643e5262fe5" dependencies = [ "comline-codegen", "eyre", diff --git a/tests/fixtures/generators/Cargo.toml b/tests/fixtures/generators/Cargo.toml index f3b6e9c..1d99eef 100644 --- a/tests/fixtures/generators/Cargo.toml +++ b/tests/fixtures/generators/Cargo.toml @@ -12,7 +12,7 @@ publish = false [dependencies] # The same revs the CLI pins, so the real generator's output is comparable # byte for byte with the CLI's built-in one. -comline-codegen = { git = "https://github.com/ComlineProject/generation", rev = "332e0f0357a67b12e335a89a3036b2cd0bf1a7be" } -comline-doc-markdown = { git = "https://github.com/ComlineProject/generation", rev = "332e0f0357a67b12e335a89a3036b2cd0bf1a7be" } -comline-doc-html = { git = "https://github.com/ComlineProject/generation", rev = "332e0f0357a67b12e335a89a3036b2cd0bf1a7be" } -comline-codegen-rust = { git = "https://github.com/ComlineProject/comline-rust", rev = "2659fbf6daf6da96d320905604dc2b88a48f31d8" } +comline-codegen = { git = "https://github.com/ComlineProject/generation", rev = "05771e0679ff514da3ba73a3b0b94643e5262fe5" } +comline-doc-markdown = { git = "https://github.com/ComlineProject/generation", rev = "05771e0679ff514da3ba73a3b0b94643e5262fe5" } +comline-doc-html = { git = "https://github.com/ComlineProject/generation", rev = "05771e0679ff514da3ba73a3b0b94643e5262fe5" } +comline-codegen-rust = { git = "https://github.com/ComlineProject/comline-rust", rev = "df91e2e0a416cab594303f11d44a6555a72f891b" }