rust-lang / rust-lang/rust-analyzer

Configure test runner to use vendor directory

Open
#17,198 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-support
Dominant language
Rust
Stars
16.9k
Forks
2.2k
Avg merge
1d 12h
Merged PRs (30d)
72

Description

In my workspace project we use vendored dependencies in the vendor directory, but we do not add the replace-with configuration in the .cargo/config.toml because doing so effectively cuts off all access to crates.io. Instead we use aliases for build and test that set the replacement for those commands e.g.:

test-vendor = [
    "test",
    "--config",
    "source.vendored-sources.directory='vendor'",
    "--config",
    "source.crates-io.replace-with='vendored-sources'",
    "--locked",
]

I'd like to be able to replicate something like this in rust-analyzer in VS Code for running tests.

What I've tried:

  • Creating a supplemental config.vendor.toml with the required source settings and setting --config .cargo/config.vendor.toml in rust-analyzer.cargo.extraArgs
  • Setting the --config source.vendored-sources... etc, in rust-analyzer.cargo.extraArgs
  • Setting:
    "rust-analyzer.cargo.extraEnv": {
        "CARGO_SOURCE_VENDORED_SOURCES_DIRECTORY": "vendor",
        "CARGO_SOURCE_CRATES_IO_REPLACE_WITH": "vendored-sources"
    }
  • Setting:
    "rust-analyzer.cargo.cfgs": {
        "source.crates-io.replace-with": "vendored-sources",
        "source.vendored-sources.directory": "vendor"
    }
  • Creating a launch.json and adding either the --config with a path or with the key/value pairs to the cargo args tables.

Is there any way of specifying additional arguments to pass to the invocation of cargo test?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No source files or tests are named. Start by reading rust-analyzer's cargo configuration and VS Code test-runner documentation, then trace how cargo test is invoked and how cargo.extraArgs is applied. Done means users can supply additional cargo test arguments, including the requested --config settings, for test runs.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
devtools, testing-qa
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.