Skip to content

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

Merged
Veykril merged 1 commit intorust-lang:masterfrom
sunshowers:runnable-kind
May 8, 2026
Merged

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

Conversation

@sunshowers
Copy link
Copy Markdown
Contributor

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
Contributor Author

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

@sunshowers sunshowers force-pushed the runnable-kind branch 2 times, most recently from c3b2616 to 65668d9 Compare May 6, 2026 06:14
@sunshowers

This comment was marked as outdated.

@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
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 sunshowers marked this pull request as ready for review May 6, 2026 21:03
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 6, 2026
Copy link
Copy Markdown
Member

@Veykril Veykril left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Veykril
Copy link
Copy Markdown
Member

Veykril commented May 7, 2026

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

I think restricting to tests would make sense. I don't think r-a would ever need to deserialize these.

@Veykril Veykril added this pull request to the merge queue May 8, 2026
Merged via the queue into rust-lang:master with commit 804bcd8 May 8, 2026
18 checks passed
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 8, 2026
@Veykril
Copy link
Copy Markdown
Member

Veykril commented May 8, 2026

Turns out we can't test cfg these due to the Request trait requirements on its assoc types

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.

3 participants