rust-lang / rust-lang/rust-analyzer

feature request: Option to add directories to the source root for all crates

Open
#12,909 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Currently when an include! macro or similar references a file which is not within a source root, the result is an empty string, which can lead to poor suggestions when cargo is used as part of a larger build system, with generated files from the other build system being included using include!. It would be nice if there was an option to specify a set of paths in the rust-analyzer config which should be considered to be in the source root for every crate such that include!-ing files from those paths is possible.

Perhaps this flag could be something like:

"rust-analyzer.files.includeSources": ["/path/to/generated/files"],

To my understanding, these paths would then be added to every crate when building the workspace roots around the same place OUT_DIR, and directories for the primary source path are added: https://github.com/rust-lang/rust-analyzer/blob/7ba94a89e9bb6e848077859a9603a2f9a50c03c7/crates/project-model/src/workspace.rs#L330-L359

Depending on how this is implemented, it may also be nice to add an option for excludeSources for completeness.

See this discussion on zulip for more context on the motivation.

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

Start in crates/project-model/src/workspace.rs around lines 330-359, where OUT_DIR and primary source paths are added while building workspace roots. Trace the related configuration and workspace-root handling, then make the requested paths available for include! resolution in every crate; completion should include coverage for the new option and its behavior.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.