rust-lang / rust-analyzer

A Rust compiler front-end for IDEs
https://rust-analyzer.github.io/
Apache License 2.0
13.8k stars 1.53k forks source link

Lazy Workspace/Project Discovery #17537

Open davidbarsky opened 3 days ago

davidbarsky commented 3 days ago

Few notes:

Anyway! Project discovery should be entirely lazy. This change makes the following easier:

To make this change happen, the currently eager (that is, they occur on startup/workspace folder change) ProjectManifest::discover_all + cargo metadata-style operations would become lazy, rust-analyzer.workspace.DiscoverCommand-style operations that only happen after startup. This would mean several things:

To support this change, I think three things need to happen:

Veykril commented 3 days ago

cargo_metadata::MetadataCommand::new() would become the default mode for flycheck/src/json_workspace.rs

I'd expect these to still be different from another, unless I misunderstand this phrase makes it sound like we are unify-ing cargo and rust-project.json like projects.

The crate graph should be lifted into a standalone, Salsa database.

I don't think this is necessary for this change. It is necessary to support standalone files, but that is a separate issue that can follow afterwards.

A nice performance bonus, the VFS should be able to load all a project's files https://github.com/rust-lang/rust-analyzer/issues/17491#issuecomment-2189251164.

Likewise I don't think this is necessary either, this is a separate issue as well. We can implement lazy discovery without this change.

davidbarsky commented 3 days ago

cargo_metadata::MetadataCommand::new() would become the default mode for flycheck/src/json_workspace.rs

I'd expect these to still be different from another, unless I misunderstand this phrase makes it sound like we are unify-ing cargo and rust-project.json like projects.

They are different, sorry! I'm trying to say that these would go through similar codepaths/mechanisms, as opposed to being fully distinct today.

The crate graph should be lifted into a standalone, Salsa database.

I don't think this is necessary for this change. It is necessary to support standalone files, but that is a separate issue that can follow afterwards.

It's not, strictly speaking, necessary for https://github.com/rust-lang/rust-analyzer/pull/17246, but it would simply the currently complicated state machine.

A nice performance bonus, the VFS should be able to load all a project's files #17491 (comment).

Likewise I don't think this is necessary either, this is a separate issue as well. We can implement lazy discovery without this change.

Same thing: it's not really required, but I really think it makes a lot of the subtle bugs would crop up substantially easier to reason about as a result.