rust-lang / rust-lang/rust-analyzer

workspace.discoverConfig only processes one file on startup when multiple undiscovered files are open

Open
#20,881 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Description:

When using the rust-analyzer.workspace.discoverConfig feature, if multiple Rust files that are not part of any currently undiscovered project are open in VSCode on startup or extension reload, only one of these files seems to trigger the discovery command. The other open files remain undiscovered, if not covered by the other discover.

Steps to Reproduce:

  1. Configure rust-analyzer.workspace.discoverConfig with a command that can output rust-project.json.

  2. Open multiple Rust files in VSCode, each belonging to different project roots that are not currently known to rust-analyzer.

  3. Reload the VSCode window or restart the rust-analyzer extension.

Expected Behavior:

rust-analyzer should trigger the discovery command for each unique project root represented by the open files, or at least queue discovery requests so all opened files eventually get a chance to be discovered.

Actual Behavior:

The discovery command appears to run only for one of the opened files. The other files remain undiscovered, and features like auto-completion, go-to-definition, etc., do not work for them.

I think this is happening because:

  • The server-side logic that
    triggers Task::DiscoverLinkedProjects when CheckIfIndexed finds an unindexed file, provided discoverConfig is set.
  • The handling of Task::DiscoverLinkedProjects includes a check: !self.discover_workspace_queue.op_in_progress().
  • This check seems to prevent more than one discovery operation from running concurrently. On startup, the first file to be processed triggers discovery, and subsequent requests for other open files are effectively ignored because an operation is already in progress.
  • This serialization means that the "discover on open" mechanism only works for one project in a multi-project-file startup scenario.

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/rust-analyzer/src/main_loop.rs at the CheckIfIndexed handling and Task::DiscoverLinkedProjects path, especially the discover_workspace_queue operation check. Reproduce the startup or reload scenario with multiple open Rust files and separate undiscovered project roots. Done means discovery is triggered or queued for each unique root so all opened files become usable.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
devtools
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.