project: Use runnable kind to disambiguate between cargo and shell commands#54011
Conversation
|
We require contributors to sign our Contributor License Agreement, and we don't have @sunshowers on file. You can sign our CLA at https://zed.dev/cla. Once you've signed, post a comment here that says '@cla-bot check'. |
|
@cla-bot check |
|
The cla-bot has been summoned, and re-checked this pull request! |
|
SomeoneToIgnore
left a comment
There was a problem hiding this comment.
Thank you for digging into this.
I guess then
zed/crates/project/src/lsp_store/lsp_ext_command.rs
Lines 503 to 504 in 5a589c4
I think CI fails will go away with a rebase and are not related.
…mmands Found this bug while investigating why configuring nextest based on the instructions at rust-lang/rust-analyzer#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.
f97db6b to
d44c2aa
Compare
|
Thanks @SomeoneToIgnore. I've rebased this on top of main and added a commit with an expanded comment on top. (Happy to squash this in if desired as well.) To be honest I'd consider r-a to not be quite correct here, though I think it only does serializing so it doesn't get hit by this. |
SomeoneToIgnore
left a comment
There was a problem hiding this comment.
Thank you!
No need to squash, we do that in the end anyway.
Fully agree with you that r-a has to get this fix ideally.
Curious to hear what the issue is on the r-a side (in your opinion). Note I haven't checked this PR yet to detail yet to catch up with this. |
|
Ah, the fact that we have the enums defined as untagged despite clearly having a tag field I suppose? |
Yeah, exactly -- I think the functional change in this PR can be directly transferred over to r-a. Do you want to do that or should I? |
|
If you could do that I'd really appreciate it, sounds like a reasonable change |
Did this at rust-lang/rust-analyzer#22295. |
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.
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.
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.
…mmands (zed-industries#54011) Found this bug while investigating why configuring nextest based on the instructions at rust-lang/rust-analyzer#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. I've manually tested this by configuring: ```json { "lsp": { "rust-analyzer": { "initialization_options": { "runnables": { "test": { "overrideCommand": [ "cargo", "nextest", "run", "--package", "${package}", "${target_arg}", "${target}", "--", "${test_name}", "${exact}", "${include_ignored}" ] } } } } } } ``` and ensuring that nextest is correctly invoked. Self-Review Checklist: - [x] I've reviewed my own diff for quality, security, and reliability - [x] Unsafe blocks (if any) have justifying comments - [x] The content is consistent with the [UI/UX checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist) - [x] Tests cover the new/changed behavior - [x] Performance impact has been considered and is acceptable Release Notes: - Fixed deserialization of rust-analyzer shell runnables. --------- Co-authored-by: Kirill Bulatov <kirill@zed.dev>
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.
Found this bug while investigating why configuring nextest based on the instructions at rust-lang/rust-analyzer#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
programandargs.With this fix, we now use the provided
kindas 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.I've manually tested this by configuring:
{ "lsp": { "rust-analyzer": { "initialization_options": { "runnables": { "test": { "overrideCommand": [ "cargo", "nextest", "run", "--package", "${package}", "${target_arg}", "${target}", "--", "${test_name}", "${exact}", "${include_ignored}" ] } } } } } }and ensuring that nextest is correctly invoked.
Self-Review Checklist:
Release Notes: