rust-lang / rust-lang/rust-analyzer

Clarifying behavior of rust-project.json `source.include_dirs`

Open
#16,792 2 comments 2 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

I have a project structured like...

.
├── generated
│   └── foo.rs
├── rust-project.json
└── src
    └── lib.rs

I want to refer to the module foo from src/lib.rs. I thought I could do that with a rust-project.json that looks like...

{
  "crates": [
    {
      "display_name": "rust_test",
      "root_module": "./src/lib.rs",
      "edition": "2021",
      "is_workspace_member": true,
      "source": {
        "exclude_dirs": [],
        "include_dirs": ["./src", "./generated"]
      },
      "deps": []
    }
  ]
}

But mod foo; in src/lib.rs results in unresolved module, can't find module file: foo.rs, or foo/mod.rs.

I think this happens because the attempt to resolve the path to the module is relative to the original file:
https://github.com/rust-lang/rust-analyzer/blob/2397e7a887252aa995d3790164b34b6c76ed94b4/crates/hir-def/src/nameres/mod_resolution.rs#L92-L95
so only paths in src are considered:
https://github.com/rust-lang/rust-analyzer/blob/2397e7a887252aa995d3790164b34b6c76ed94b4/crates/vfs/src/file_set.rs#L30-L35

Should this work, or am I misunderstanding include_dirs?

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 with the reproduced rust-project.json layout and the mod foo; lookup, then read crates/hir-def/src/nameres/mod_resolution.rs around lines 92–95 and crates/vfs/src/file_set.rs around lines 30–35. Determine whether source.include_dirs is intended to affect module resolution; done means the behavior is clarified and, if needed, the relevant implementation or documentation is updated.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.