rust-lang / rust-lang/rust-analyzer

Proper support for standalone/detached files

Open
#14,318 15 comments 11 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

https://github.com/rust-lang/rust-analyzer/blob/9fca0a4afefead3daf8f66fd357999d7cd520880/crates/project-model/src/workspace.rs#L86-L96

Ideally, you should be able to just open a random detached file in existing cargo projects, and get the basic features working. That needs some changes on the salsa-level though. In particular, we should split the unified CrateGraph (which currently has maximal durability) into proper crate graph, and a set of ad hoc roots (with minimal durability). Then, we need to hide the graph behind the queries such that most queries look only at the proper crate graph, and fall back to ad hoc roots only if there's no results. After this, we should be able to tweak the logic in reload.rs to add newly opened files, which don't belong to any existing crates, to the set of the detached files.

Fixing this would be beneficial to the rustlings project, removing the need for the rust-project.json generation step they currently employ.

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 linked section of crates/project-model/src/workspace.rs and then inspect reload.rs, focusing on how the Salsa-level CrateGraph and detached files are represented. Trace the relevant queries and existing behavior before changing the design. Done means standalone files in existing Cargo projects receive basic features without rust-project.json generation, including the rustlings use case.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
developer-experience, tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.