aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_lsp_server/src/project_model
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-01-10 19:47:05 +0000
committerAleksey Kladov <[email protected]>2019-01-10 21:51:34 +0000
commit8852408bfb358766d59b83f294148fb5eeae26a0 (patch)
tree1bca8af9f6ac8f668d8ca5a710b6677c6b90e921 /crates/ra_lsp_server/src/project_model
parent66fba88534039ff42a230f1ede3e0a730f61ad3c (diff)
use arena for sysroot
Diffstat (limited to 'crates/ra_lsp_server/src/project_model')
-rw-r--r--crates/ra_lsp_server/src/project_model/sysroot.rs129
1 files changed, 80 insertions, 49 deletions
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";