rust-lang / rust-lang/rust-analyzer
feature request: Option to add directories to the source root for all crates
Nobody has claimed this yet.
- 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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