diff options
-rw-r--r-- | crates/ra_arena/src/lib.rs | 11 | ||||
-rw-r--r-- | crates/ra_lsp_server/src/project_model/sysroot.rs | 129 |
2 files changed, 90 insertions, 50 deletions
diff --git a/crates/ra_arena/src/lib.rs b/crates/ra_arena/src/lib.rs index 43bfa925a..d7d5d5265 100644 --- a/crates/ra_arena/src/lib.rs +++ b/crates/ra_arena/src/lib.rs | |||
@@ -35,12 +35,21 @@ impl fmt::Display for RawId { | |||
35 | } | 35 | } |
36 | } | 36 | } |
37 | 37 | ||
38 | #[derive(Clone, Debug, PartialEq, Eq)] | 38 | #[derive(Clone, PartialEq, Eq)] |
39 | pub struct Arena<ID: ArenaId, T> { | 39 | pub struct Arena<ID: ArenaId, T> { |
40 | data: Vec<T>, | 40 | data: Vec<T>, |
41 | _ty: PhantomData<ID>, | 41 | _ty: PhantomData<ID>, |
42 | } | 42 | } |
43 | 43 | ||
44 | impl<ID: ArenaId, T: fmt::Debug> fmt::Debug for Arena<ID, T> { | ||
45 | fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { | ||
46 | fmt.debug_struct("Arena") | ||
47 | .field("len", &self.len()) | ||
48 | .field("data", &self.data) | ||
49 | .finish() | ||
50 | } | ||
51 | } | ||
52 | |||
44 | #[macro_export] | 53 | #[macro_export] |
45 | macro_rules! impl_arena_id { | 54 | macro_rules! impl_arena_id { |
46 | ($name:ident) => { | 55 | ($name:ident) => { |
diff --git a/crates/ra_lsp_server/src/project_model/sysroot.rs b/crates/ra_lsp_server/src/project_model/sysroot.rs index ae72c9c17..6c1a1a2a3 100644 --- a/crates/ra_lsp_server/src/project_model/sysroot.rs +++ b/crates/ra_lsp_server/src/project_model/sysroot.rs | |||
@@ -4,13 +4,24 @@ use std::{ | |||
4 | }; | 4 | }; |
5 | 5 | ||
6 | use ra_syntax::SmolStr; | 6 | use ra_syntax::SmolStr; |
7 | use rustc_hash::FxHashMap; | 7 | use ra_arena::{Arena, RawId, impl_arena_id}; |
8 | 8 | ||
9 | use crate::Result; | 9 | use crate::Result; |
10 | 10 | ||
11 | #[derive(Debug, Clone)] | 11 | #[derive(Debug, Clone)] |
12 | pub struct Sysroot { | 12 | pub struct Sysroot { |
13 | crates: FxHashMap<SmolStr, PathBuf>, | 13 | crates: Arena<SysrootCrate, SysrootCrateData>, |
14 | } | ||
15 | |||
16 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | ||
17 | pub struct SysrootCrate(RawId); | ||
18 | impl_arena_id!(SysrootCrate); | ||
19 | |||
20 | #[derive(Debug, Clone)] | ||
21 | struct SysrootCrateData { | ||
22 | name: SmolStr, | ||
23 | path: PathBuf, | ||
24 | deps: Vec<SysrootCrate>, | ||
14 | } | 25 | } |
15 | 26 | ||
16 | impl Sysroot { | 27 | impl Sysroot { |
@@ -26,53 +37,73 @@ impl Sysroot { | |||
26 | let sysroot_path = Path::new(stdout.trim()); | 37 | let sysroot_path = Path::new(stdout.trim()); |
27 | let src = sysroot_path.join("lib/rustlib/src/rust/src"); | 38 | let src = sysroot_path.join("lib/rustlib/src/rust/src"); |
28 | 39 | ||
29 | let crates: &[(&str, &[&str])] = &[ | 40 | let mut sysroot = Sysroot { |
30 | ( | 41 | crates: Arena::default(), |
31 | "std", | 42 | }; |
32 | &[ | 43 | for name in SYSROOT_CRATES.trim().lines() { |
33 | "alloc_jemalloc", | 44 | let path = src.join(format!("lib{}", name)).join("lib.rs"); |
34 | "alloc_system", | 45 | if path.exists() { |
35 | "panic_abort", | 46 | sysroot.crates.alloc(SysrootCrateData { |
36 | "rand", | 47 | name: name.into(), |
37 | "compiler_builtins", | 48 | path, |
38 | "unwind", | 49 | deps: Vec::new(), |
39 | "rustc_asan", | 50 | }); |
40 | "rustc_lsan", | 51 | } |
41 | "rustc_msan", | 52 | } |
42 | "rustc_tsan", | 53 | if let Some(std) = sysroot.by_name("std") { |
43 | "build_helper", | 54 | for dep in STD_DEPS.trim().lines() { |
44 | ], | 55 | if let Some(dep) = sysroot.by_name(dep) { |
45 | ), | 56 | sysroot.crates[std].deps.push(dep) |
46 | ("core", &[]), | 57 | } |
47 | ("alloc", &[]), | 58 | } |
48 | ("collections", &[]), | 59 | } |
49 | ("libc", &[]), | 60 | Ok(sysroot) |
50 | ("panic_unwind", &[]), | 61 | } |
51 | ("proc_macro", &[]), | ||
52 | ("rustc_unicode", &[]), | ||
53 | ("std_unicode", &[]), | ||
54 | ("test", &[]), | ||
55 | // Feature gated | ||
56 | ("alloc_jemalloc", &[]), | ||
57 | ("alloc_system", &[]), | ||
58 | ("compiler_builtins", &[]), | ||
59 | ("getopts", &[]), | ||
60 | ("panic_unwind", &[]), | ||
61 | ("panic_abort", &[]), | ||
62 | ("rand", &[]), | ||
63 | ("term", &[]), | ||
64 | ("unwind", &[]), | ||
65 | // Dependencies | ||
66 | ("build_helper", &[]), | ||
67 | ("rustc_asan", &[]), | ||
68 | ("rustc_lsan", &[]), | ||
69 | ("rustc_msan", &[]), | ||
70 | ("rustc_tsan", &[]), | ||
71 | ("syntax", &[]), | ||
72 | ]; | ||
73 | 62 | ||
74 | Ok(Sysroot { | 63 | fn by_name(&self, name: &str) -> Option<SysrootCrate> { |
75 | crates: FxHashMap::default(), | 64 | self.crates |
76 | }) | 65 | .iter() |
66 | .find(|(_id, data)| data.name == name) | ||
67 | .map(|(id, _data)| id) | ||
77 | } | 68 | } |
78 | } | 69 | } |
70 | |||
71 | const SYSROOT_CRATES: &str = " | ||
72 | std | ||
73 | core | ||
74 | alloc | ||
75 | collections | ||
76 | libc | ||
77 | panic_unwind | ||
78 | proc_macro | ||
79 | rustc_unicode | ||
80 | std_unicode | ||
81 | test | ||
82 | alloc_jemalloc | ||
83 | alloc_system | ||
84 | compiler_builtins | ||
85 | getopts | ||
86 | panic_unwind | ||
87 | panic_abort | ||
88 | rand | ||
89 | term | ||
90 | unwind | ||
91 | build_helper | ||
92 | rustc_asan | ||
93 | rustc_lsan | ||
94 | rustc_msan | ||
95 | rustc_tsan | ||
96 | syntax"; | ||
97 | |||
98 | const STD_DEPS: &str = " | ||
99 | alloc_jemalloc | ||
100 | alloc_system | ||
101 | panic_abort | ||
102 | rand | ||
103 | compiler_builtins | ||
104 | unwind | ||
105 | rustc_asan | ||
106 | rustc_lsan | ||
107 | rustc_msan | ||
108 | rustc_tsan | ||
109 | build_helper"; | ||