zed icon indicating copy to clipboard operation
zed copied to clipboard

Rust-Analyzer does not support "OverrideCommand"

Open QuentinPerez opened this issue 10 months ago • 2 comments

Check for existing issues

  • [X] Completed

Describe the bug / provide steps to reproduce it

👋

Not sure if it's a feature request or a bug, since RA/vscode supports it. Given the following .zed/settings.json, it seems that we can not override check command. Here is an example.

{
    "lsp": {
        "rust-analyzer": {
            "initialization_options": {
                "check": {
                    "overrideCommand": [
                        "sh",
                        "-c",
                        "cargo clippy --message-format=json --manifest-path ./a/Cargo.toml;  cargo clippy --message-format=json --manifest-path ./b/Cargo.toml"
                    ]
                }
            }
        }
    }
}

Environment

Zed: v0.131.4 (Zed Preview) OS: macOS 14.3.1 Memory: 64 GiB Architecture: aarch64

If applicable, add mockups / screenshots to help explain present your vision of the feature

No response

If applicable, attach your ~/Library/Logs/Zed/Zed.log file to this issue.

No response

QuentinPerez avatar Apr 12 '24 21:04 QuentinPerez

Hey, that's pretty odd. I use overrideCommand myself and it does work for me;

My config for RA
  "lsp": {
    "rust-analyzer": {
      "initialization_options": {
        "check": {
          "allTargets": false,
          "overrideCommand": ["cargo", "build", "--message-format=json"]
        }
      }
    }
  }
If I were to guess, you're trying to use a shell command as a check command; I wonder if it's being escaped/passed along properly. Could you try to save it as a script in your home directory and then use `["sh", "-c", "~/my_ra_script.sh"] ` as your check command to verify whether that's indeed the case?

osiewicz avatar Apr 17 '24 10:04 osiewicz

It isn't working for me either. These are my settings:

{
  "lsp": {
    "rust-analyzer": {
      "initialization_options": {
        "check": {
          "overrideCommand": [
            "cargo",
            "check",
            "--target=arm-unknown-linux-musleabihf" // "--target=x86_64-apple-darwin"
          ]
        }
      }
    }
  }
}

In the terminal running cargo check --target=arm-unknown-linux-musleabihf works. Same with cargo check --target=x86_64-apple-darwin

Edit: actually, I see in ~/Library/Logs/Zed/Zed.log that the command is being executed correctly because I see the error I'm expecting. It's just that I don't see the error in the UI. And also it still shows me this diagnostic, which shouldn't show up if I'm targeting arm-unknown-linux-musleabihf

image

Edit 2: in my case, the issue was that I was missing "--message-format=json" in my command. Working command is:

{
  "lsp": {
    "rust-analyzer": {
      "initialization_options": {
        "check": {
          "overrideCommand": [
            "cargo",
            "check",
            "--target=arm-unknown-linux-musleabihf",
            "--message-format=json"
          ]

martinschaer avatar May 13 '24 10:05 martinschaer