Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use cargo check in its own directory avoiding blocking cargo run

I set up the VS Code settings.json with the following configuration:

{
    "rust-analyzer.checkOnSave": true,
    "rust-analyzer.runnables.extraEnv": {
        "RUST_BACKTRACE": "0"
    },
    "rust-analyzer.cargo.targetDir": true,
    // "rust-analyzer.check.command": "clippy",
    "rust-analyzer.check.overrideCommand": [
        "cargo-clif",
        "check",
        "--workspace",
        "--message-format=json",
        "--all-targets"
    ]
}

This works, but when I run watchexec -- cargo-clif run on the project (it's a web server) to restart it on each change in the codebase, it stops with the following message:

Blocking waiting for file lock on build directory

If I use:

"rust-analyzer.check.command": "clippy",

it doesn't block.

How can I make cargo-clif check works in its own directory?

like image 485
Fred Hors Avatar asked Dec 16 '25 11:12

Fred Hors


1 Answers

rust-analyzer does not support using a custom target directory when rust-analyzer.check.overrideCommand is used, however you can do it yourself. What rust-analyzer does when you set "rust-analyzer.cargo.targetDir": true is just passing --target-dir <old_target_dir>/rust-analyzer. You can just as well pass this argument manually to the command.

like image 51
Chayim Friedman Avatar answered Dec 19 '25 01:12

Chayim Friedman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!