From 482a893aaf783e9e9f846421ba3737e4e1c3f50f Mon Sep 17 00:00:00 2001 From: Kinflou Date: Sun, 25 Oct 2026 03:54:14 +0800 Subject: [PATCH] generate: warn when `async = true` changes nothing Async only reshapes protocols on a connection. With none, the output is identical to a blocking build, which reads as the setting being ignored. --- src/commands/generate.rs | 19 +++++++++++++++++++ tests/cli/generate.rs | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) diff --git a/src/commands/generate.rs b/src/commands/generate.rs index 796c0c7..6d7224d 100644 --- a/src/commands/generate.rs +++ b/src/commands/generate.rs @@ -232,6 +232,7 @@ fn generate_once(work_dir: &Path, overrides: &Overrides, dry_run: bool, list: bo // they carry no span to render a snippet against, so there's // nothing for the multi-line branch there to do. warn_ignored(&t.language, &request, &resolved); + warn_async_unused(&t.language, &request); let files = generator(&request).map_err(|e| miette!("`{}` generator: {e}", t.language))?; @@ -396,6 +397,24 @@ fn gen_version_from_commit( }) } +/// `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. +fn warn_async_unused(language: &str, request: &GenRequest) { + 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; + } + ui::warn(format!( + "`{language}`: `async = true`, but no protocol runs on a connection, so the output \ + is the same as without it - a protocol is on one with `@provider = Client` or \ + `Multiple`, a `datagram@2` framing, or JSON-RPC once any of the package's JSON-RPC \ + protocols is client-provided" + )); +} + /// 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 diff --git a/tests/cli/generate.rs b/tests/cli/generate.rs index 690cbb7..848d5ec 100644 --- a/tests/cli/generate.rs +++ b/tests/cli/generate.rs @@ -832,3 +832,37 @@ fn async_generates_connection_protocols_for_the_async_driver() { "the code-mode note names the runtime feature" ); } + +/// `async = true` with no protocol on a connection changes nothing, so +/// generate says so; with one, it doesn't. +#[test] +fn async_without_a_connection_protocol_warns() { + let temp = tempfile::tempdir().unwrap(); + let project = fixture_project(temp.path()); + fs::write( + project.join("src/link.ids"), + "protocol Link {\n function send(n: u32) -> u32;\n}\n", + ) + .unwrap(); + let warning = "`async = true`, but no protocol runs on a connection"; + + fs::write(project.join("comline.toml"), "[generate]\nasync = true\n").unwrap(); + comline_cmd() + .current_dir(&project) + .args(["generate", "--target", "rust"]) + .assert() + .success() + .stderr(predicate::str::contains(warning)); + + fs::write( + project.join("comline.toml"), + "[generate]\ndefault_framing = \"datagram@2\"\nasync = true\n", + ) + .unwrap(); + comline_cmd() + .current_dir(&project) + .args(["generate", "--target", "rust"]) + .assert() + .success() + .stderr(predicate::str::contains(warning).not()); +}