Skip to content

Use runnable kind to disambiguate between cargo and shell commands#22295

Draft
sunshowers wants to merge 1 commit intorust-lang:masterfrom
sunshowers:runnable-kind
Draft

Use runnable kind to disambiguate between cargo and shell commands#22295
sunshowers wants to merge 1 commit intorust-lang:masterfrom
sunshowers:runnable-kind

Conversation

@sunshowers
Copy link
Copy Markdown

See zed-industries/zed#54011 for the original fix to Zed. That project had copied over these type definitions from rust-analyzer, so we should fix that here too, even though I don't believe r-a deserializes these in production.

Found this bug while investigating why configuring nextest based on the instructions at #21137 (comment) wasn't working within Zed.

Previously, we'd use serde(untagged), preferring cargo over shell commands. The problem is that every instance of a shell command is a valid instance of a cargo command. For example, the shell command:

{
    "label": "test my_test",
    "kind": "shell",
    "args": {
        "environment": {"RUSTC_TOOLCHAIN": "/path/to/toolchain"},
        "cwd": "/project",
        "program": "cargo",
        "args": ["nextest", "run", "--package", "my-crate", "--lib", "--", "my_test", "--exact", "--include-ignored"]
    }
}

would end up getting deserialized as a Cargo command, silently dropping program and args.

With this fix, we now use the provided kind as a tag. We do have to introduce a #[serde(flatten)] unfortunately, which has a few side effects due to internal buffering, but #[serde(untagged)] also does internal buffering so this doesn't make things worse.

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 6, 2026
@sunshowers
Copy link
Copy Markdown
Author

I'm wondering though if r-a should just drop the Deserialize impl for these types entirely, or restrict it to tests.

Found this bug while investigating why configuring nextest based on the instructions at rust-lang#21137 (comment) wasn't working within Zed.

Previously, we'd use `serde(untagged)`, preferring cargo over shell commands. The problem is that every instance of a shell command is a valid instance of a cargo command. For example, the shell command:

```json
{
    "label": "test my_test",
    "kind": "shell",
    "args": {
        "environment": {"RUSTC_TOOLCHAIN": "/path/to/toolchain"},
        "cwd": "/project",
        "program": "cargo",
        "args": ["nextest", "run", "--package", "my-crate", "--lib", "--", "my_test", "--exact", "--include-ignored"]
    }
}
```

would end up getting deserialized as a Cargo command, silently dropping `program` and `args`.

With this fix, we now use the provided `kind` as a tag. We do have to introduce a `#[serde(flatten)]` unfortunately, which has a few side effects due to internal buffering, but `#[serde(untagged)]` also does internal buffering so this doesn't make things worse.

See zed-industries/zed#54011 for the original fix to Zed.
@sunshowers
Copy link
Copy Markdown
Author

(going to follow up on the test failure tomorrow)

@sunshowers sunshowers marked this pull request as draft May 6, 2026 06:53
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants