diff options
author | Aleksey Kladov <[email protected]> | 2018-12-08 20:16:11 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2018-12-09 10:33:16 +0000 |
commit | 9b1356464a834e0b9a88dd3eeabc50bf1d734f35 (patch) | |
tree | 880f693f1e800c263a08654456c3958cd6c650fe /crates/ra_lsp_server/src/project_model.rs | |
parent | 32c067f8c9aec56bb502c5a569884679bae27af3 (diff) |
propagate deps to CrateGraph
Diffstat (limited to 'crates/ra_lsp_server/src/project_model.rs')
-rw-r--r-- | crates/ra_lsp_server/src/project_model.rs | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/crates/ra_lsp_server/src/project_model.rs b/crates/ra_lsp_server/src/project_model.rs index 22495f49c..5da71b9f5 100644 --- a/crates/ra_lsp_server/src/project_model.rs +++ b/crates/ra_lsp_server/src/project_model.rs | |||
@@ -1,6 +1,5 @@ | |||
1 | use std::path::{Path, PathBuf}; | 1 | use std::path::{Path, PathBuf}; |
2 | 2 | ||
3 | use serde_derive::Serialize; | ||
4 | use cargo_metadata::{metadata_run, CargoOpt}; | 3 | use cargo_metadata::{metadata_run, CargoOpt}; |
5 | use ra_syntax::SmolStr; | 4 | use ra_syntax::SmolStr; |
6 | use rustc_hash::{FxHashMap, FxHashSet}; | 5 | use rustc_hash::{FxHashMap, FxHashSet}; |
@@ -11,15 +10,22 @@ use crate::{ | |||
11 | thread_watcher::{ThreadWatcher, Worker}, | 10 | thread_watcher::{ThreadWatcher, Worker}, |
12 | }; | 11 | }; |
13 | 12 | ||
13 | /// `CargoWorksapce` represents the logical structure of, well, a Cargo | ||
14 | /// workspace. It pretty closely mirrors `cargo metadata` output. | ||
15 | /// | ||
16 | /// Note that internally, rust analyzer uses a differnet structure: | ||
17 | /// `CrateGraph`. `CrateGraph` is lower-level: it knows only about the crates, | ||
18 | /// while this knows about `Pacakges` & `Targets`: purely cargo-related | ||
19 | /// concepts. | ||
14 | #[derive(Debug, Clone)] | 20 | #[derive(Debug, Clone)] |
15 | pub struct CargoWorkspace { | 21 | pub struct CargoWorkspace { |
16 | packages: Vec<PackageData>, | 22 | packages: Vec<PackageData>, |
17 | targets: Vec<TargetData>, | 23 | targets: Vec<TargetData>, |
18 | } | 24 | } |
19 | 25 | ||
20 | #[derive(Clone, Copy, Debug, Serialize)] | 26 | #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] |
21 | pub struct Package(usize); | 27 | pub struct Package(usize); |
22 | #[derive(Clone, Copy, Debug, Serialize)] | 28 | #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] |
23 | pub struct Target(usize); | 29 | pub struct Target(usize); |
24 | 30 | ||
25 | #[derive(Debug, Clone)] | 31 | #[derive(Debug, Clone)] |
@@ -62,6 +68,9 @@ impl Package { | |||
62 | pub fn is_member(self, ws: &CargoWorkspace) -> bool { | 68 | pub fn is_member(self, ws: &CargoWorkspace) -> bool { |
63 | ws.pkg(self).is_member | 69 | ws.pkg(self).is_member |
64 | } | 70 | } |
71 | pub fn dependencies<'a>(self, ws: &'a CargoWorkspace) -> impl Iterator<Item = Package> + 'a { | ||
72 | ws.pkg(self).dependencies.iter().cloned() | ||
73 | } | ||
65 | } | 74 | } |
66 | 75 | ||
67 | impl Target { | 76 | impl Target { |