rust/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
cfg
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
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
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
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
toolchain
tt
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