aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_arena/src/lib.rs11
-rw-r--r--crates/ra_lsp_server/src/project_model/sysroot.rs129
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)]
39pub struct Arena<ID: ArenaId, T> { 39pub 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
44impl<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]
45macro_rules! impl_arena_id { 54macro_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
6use ra_syntax::SmolStr; 6use ra_syntax::SmolStr;
7use rustc_hash::FxHashMap; 7use ra_arena::{Arena, RawId, impl_arena_id};
8 8
9use crate::Result; 9use crate::Result;
10 10
11#[derive(Debug, Clone)] 11#[derive(Debug, Clone)]
12pub struct Sysroot { 12pub struct Sysroot {
13 crates: FxHashMap<SmolStr, PathBuf>, 13 crates: Arena<SysrootCrate, SysrootCrateData>,
14}
15
16#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
17pub struct SysrootCrate(RawId);
18impl_arena_id!(SysrootCrate);
19
20#[derive(Debug, Clone)]
21struct SysrootCrateData {
22 name: SmolStr,
23 path: PathBuf,
24 deps: Vec<SysrootCrate>,
14} 25}
15 26
16impl Sysroot { 27impl 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
71const SYSROOT_CRATES: &str = "
72std
73core
74alloc
75collections
76libc
77panic_unwind
78proc_macro
79rustc_unicode
80std_unicode
81test
82alloc_jemalloc
83alloc_system
84compiler_builtins
85getopts
86panic_unwind
87panic_abort
88rand
89term
90unwind
91build_helper
92rustc_asan
93rustc_lsan
94rustc_msan
95rustc_tsan
96syntax";
97
98const STD_DEPS: &str = "
99alloc_jemalloc
100alloc_system
101panic_abort
102rand
103compiler_builtins
104unwind
105rustc_asan
106rustc_lsan
107rustc_msan
108rustc_tsan
109build_helper";