|
3 | 3 | mod cargo_workspace;
|
4 | 4 | mod json_project;
|
5 | 5 | mod sysroot;
|
| 6 | +mod workspace_error; |
6 | 7 |
|
7 | 8 | use std::{
|
8 |
| - fmt, |
9 | 9 | fs::File,
|
10 | 10 | io::BufReader,
|
11 | 11 | path::{Path, PathBuf},
|
12 | 12 | process::Command,
|
13 | 13 | };
|
14 | 14 |
|
15 | 15 | use ra_cfg::CfgOptions;
|
16 |
| -use ra_db::{CrateGraph, CrateId, Edition, Env, FileId, ParseEditionError}; |
| 16 | +use ra_db::{CrateGraph, CrateId, Edition, Env, FileId}; |
17 | 17 | use rustc_hash::FxHashMap;
|
18 | 18 | use serde_json::from_reader;
|
19 | 19 |
|
| 20 | +use crate::workspace_error::WorkspaceError; |
| 21 | + |
20 | 22 | pub use crate::{
|
21 | 23 | cargo_workspace::{CargoFeatures, CargoWorkspace, Package, Target, TargetKind},
|
22 | 24 | json_project::JsonProject,
|
23 | 25 | sysroot::Sysroot,
|
24 | 26 | };
|
25 | 27 |
|
26 |
| -#[derive(Debug)] |
27 |
| -pub enum WorkspaceError { |
28 |
| - CargoMetadataFailed(cargo_metadata::Error), |
29 |
| - CargoTomlNotFound(PathBuf), |
30 |
| - NoStdLib(PathBuf), |
31 |
| - OpenWorkspaceError(std::io::Error), |
32 |
| - ParseEditionError(ParseEditionError), |
33 |
| - ReadWorkspaceError(serde_json::Error), |
34 |
| - RustcCfgError, |
35 |
| - RustcError(std::io::Error), |
36 |
| - RustcOutputError(std::string::FromUtf8Error), |
37 |
| - SysrootNotFound, |
38 |
| -} |
39 |
| - |
40 |
| -impl fmt::Display for WorkspaceError { |
41 |
| - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
42 |
| - match self { |
43 |
| - Self::OpenWorkspaceError(err) | Self::RustcError(err) => write!(f, "{}", err), |
44 |
| - Self::ParseEditionError(err) => write!(f, "{}", err), |
45 |
| - Self::ReadWorkspaceError(err) => write!(f, "{}", err), |
46 |
| - Self::RustcOutputError(err) => write!(f, "{}", err), |
47 |
| - Self::CargoMetadataFailed(err) => write!(f, "cargo metadata failed: {}", err), |
48 |
| - Self::RustcCfgError => write!(f, "failed to get rustc cfgs"), |
49 |
| - Self::SysrootNotFound => write!(f, "failed to locate sysroot"), |
50 |
| - Self::CargoTomlNotFound(path) => { |
51 |
| - write!(f, "can't find Cargo.toml at {}", path.display()) |
52 |
| - } |
53 |
| - Self::NoStdLib(sysroot) => write!( |
54 |
| - f, |
55 |
| - "can't load standard library from sysroot\n\ |
56 |
| - {:?}\n\ |
57 |
| - try running `rustup component add rust-src` or set `RUST_SRC_PATH`", |
58 |
| - sysroot, |
59 |
| - ), |
60 |
| - } |
61 |
| - } |
62 |
| -} |
63 |
| - |
64 |
| -impl std::error::Error for WorkspaceError {} |
65 |
| - |
66 |
| -impl From<ParseEditionError> for WorkspaceError { |
67 |
| - fn from(err: ParseEditionError) -> Self { |
68 |
| - Self::ParseEditionError(err.into()) |
69 |
| - } |
70 |
| -} |
71 |
| - |
72 |
| -impl From<cargo_metadata::Error> for WorkspaceError { |
73 |
| - fn from(err: cargo_metadata::Error) -> Self { |
74 |
| - Self::CargoMetadataFailed(err.into()) |
75 |
| - } |
76 |
| -} |
77 |
| - |
78 | 28 | #[derive(Debug, Clone)]
|
79 | 29 | pub enum ProjectWorkspace {
|
80 | 30 | /// Project workspace was discovered by running `cargo metadata` and `rustc --print sysroot`.
|
|
0 commit comments