054caa81c5
7690: Extract `fn load_workspace(…)` from `fn load_cargo(…)` r=matklad a=regexident Unfortunately in https://github.com/rust-analyzer/rust-analyzer/pull/7595 I forgot to `pub use` (rather than just `use`) the newly introduced `LoadCargoConfig`. So this PR fixes this now. It also: - splits up `fn load_cargo` into a "workspace loading" and a "project loading" phase - adds a `progress: &dyn Fn(String)` to allow third-parties to provide CLI progress updates, too The motivation behind both of these is the fact that rust-analyzer currently does not support caching. As such any third-party making use of `ra_ap_…` needs to providing a caching layer itself. Unlike for rust-analyzer itself however a common use-pattern of third-parties is to analyze a specific target (`--lib`/`--bin <BIN>`/…) from a specific package (`--package`). The targets/packages of a crate can be obtained via `ProjectWorkspace::load(…)`, which currently is performed inside of `fn load_cargo`, effectively making the returned `ProjectWorkspace` inaccessible to the outer caller. With this information one can then provide early error handling via CLI (in case of ambiguities or invalid arguments, etc), instead of `fn load_cargo` failing with a possibly obscure error message. It also allows for annotating the persisted caches with its specific associated package/target selector and short-circuit quickly if a matching cache is found on disk, significantly cutting load times. Before: ```rust pub struct LoadCargoConfig { pub cargo_config: &CargoConfig, pub load_out_dirs_from_check: bool, pub with_proc_macro: bool, } pub fn load_cargo( root: &Path, config: &LoadCargoConfig ) -> Result<(AnalysisHost, vfs::Vfs)> { // ... } ``` After: ```rust pub fn load_workspace( root: &Path, config: &CargoConfig, progress: &dyn Fn(String), ) -> Result<ProjectWorkspace> { // ... } pub struct LoadCargoConfig { pub load_out_dirs_from_check: bool, pub with_proc_macro: bool, } pub fn load_cargo( ws: ProjectWorkspace, config: &LoadCargoConfig, progress: &dyn Fn(String), ) -> Result<(AnalysisHost, vfs::Vfs)> { // ... } ``` Co-authored-by: Vincent Esche <regexident@gmail.com> |
||
---|---|---|
.cargo | ||
.github | ||
.vscode | ||
assets | ||
bench_data | ||
crates | ||
docs | ||
editors/code | ||
lib | ||
xtask | ||
.gitattributes | ||
.gitignore | ||
bors.toml | ||
Cargo.lock | ||
Cargo.toml | ||
LICENSE-APACHE | ||
LICENSE-MIT | ||
PRIVACY.md | ||
README.md | ||
rustfmt.toml |
rust-analyzer is an experimental modular compiler frontend for the Rust language. It is a part of a larger rls-2.0 effort to create excellent IDE support for Rust.
Work on rust-analyzer is sponsored by
Quick Start
https://rust-analyzer.github.io/manual.html#installation
Documentation
If you want to contribute to rust-analyzer or are just curious about how things work under the hood, check the ./docs/dev folder.
If you want to use rust-analyzer's language server with your editor of choice, check the manual folder. It also contains some tips & tricks to help you be more productive when using rust-analyzer.
Communication
For usage and troubleshooting requests, please use "IDEs and Editors" category of the Rust forum:
https://users.rust-lang.org/c/ide/14
For questions about development and implementation, join rls-2.0 working group on Zulip:
https://rust-lang.zulipchat.com/#narrow/stream/185405-t-compiler.2Frls-2.2E0
Quick Links
- Website: https://rust-analyzer.github.io/
- Metrics: https://rust-analyzer.github.io/metrics/
- API docs: https://rust-analyzer.github.io/rust-analyzer/ide/
License
Rust analyzer is primarily distributed under the terms of both the MIT license and the Apache License (Version 2.0).
See LICENSE-APACHE and LICENSE-MIT for details.