rust-analyzer/crates
bors[bot] 054caa81c5
Merge #7690
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>
2021-02-16 18:24:28 +00:00
..
assists Merge #7620 2021-02-16 14:01:09 +00:00
base_db Fix warnings when running cargo doc --document-private-items 2021-01-18 16:44:40 -05:00
cfg Upgrade expect-test to 1.1 2021-01-03 14:43:29 +01:00
completion Complete builtin type paths 2021-02-11 19:52:46 +01:00
flycheck Make logger-based debugging more pleasant 2021-01-28 17:07:53 +03:00
hir expose hir::Type::type_paramters 2021-02-13 22:04:52 +03:00
hir_def Wrap BuiltinType in code model 2021-02-11 19:52:33 +01:00
hir_expand add more counts 2021-01-27 12:39:19 +03:00
hir_ty Wrap BuiltinType in code model 2021-02-11 19:52:33 +01:00
ide Merge #7657 2021-02-16 16:34:22 +00:00
ide_db Use cfg(target_arch) instead of a Cargo feature 2021-02-16 18:50:06 +01:00
mbe Make sure normal dependencies always have version 2021-02-03 12:51:07 +00:00
parser Specialization for async traits 2021-02-15 18:33:12 +01:00
paths Document paths items 2021-01-22 15:38:33 +01:00
proc_macro_api Remove redundant clones 2021-02-05 16:57:26 +01:00
proc_macro_srv libloading 0.7 2021-02-11 10:07:49 -05:00
proc_macro_test Add description for crates that will be published 2020-08-24 13:07:22 +02:00
profile add more counts 2021-01-27 12:39:19 +03:00
project_model Fix a few clippy::perf warnings 2021-02-16 10:55:34 -05:00
rust-analyzer Merge #7690 2021-02-16 18:24:28 +00:00
ssr . 2021-01-20 01:56:11 +03:00
stdx Cleanup decl_check 2021-02-05 16:09:45 +01:00
syntax Merge #7687 2021-02-16 14:16:47 +00:00
test_utils Add parsing benchmark 2021-02-09 21:52:34 +03:00
text_edit Avoid turning completion objects into builders 2020-11-16 23:16:41 +02:00
toolchain Add description for crates that will be published 2020-08-24 13:07:22 +02:00
tt Refactor TokenBuffer for reduc cloning 2021-01-05 02:00:46 +08:00
vfs Fix slow tests sometimes failing 2021-02-12 16:31:16 +01:00
vfs-notify Fix slow tests sometimes failing 2021-02-12 16:31:16 +01:00