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
19 changes: 19 additions & 0 deletions src/commands/generate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))?;

Expand Down Expand Up @@ -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
Expand Down
34 changes: 34 additions & 0 deletions tests/cli/generate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Loading