aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_lsp_server/src/project_model
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_lsp_server/src/project_model')
-rw-r--r--crates/ra_lsp_server/src/project_model/sysroot.rs27
1 files changed, 23 insertions, 4 deletions
diff --git a/crates/ra_lsp_server/src/project_model/sysroot.rs b/crates/ra_lsp_server/src/project_model/sysroot.rs
index c4028a1fe..1dbab57f8 100644
--- a/crates/ra_lsp_server/src/project_model/sysroot.rs
+++ b/crates/ra_lsp_server/src/project_model/sysroot.rs
@@ -20,7 +20,7 @@ impl_arena_id!(SysrootCrate);
20#[derive(Debug, Clone)] 20#[derive(Debug, Clone)]
21struct SysrootCrateData { 21struct SysrootCrateData {
22 name: SmolStr, 22 name: SmolStr,
23 path: PathBuf, 23 root: PathBuf,
24 deps: Vec<SysrootCrate>, 24 deps: Vec<SysrootCrate>,
25} 25}
26 26
@@ -29,6 +29,10 @@ impl Sysroot {
29 self.by_name("std") 29 self.by_name("std")
30 } 30 }
31 31
32 pub(crate) fn crates<'a>(&'a self) -> impl Iterator<Item = SysrootCrate> + 'a {
33 self.crates.iter().map(|(id, _data)| id)
34 }
35
32 pub(super) fn discover(cargo_toml: &Path) -> Result<Sysroot> { 36 pub(super) fn discover(cargo_toml: &Path) -> Result<Sysroot> {
33 let rustc_output = Command::new("rustc") 37 let rustc_output = Command::new("rustc")
34 .current_dir(cargo_toml.parent().unwrap()) 38 .current_dir(cargo_toml.parent().unwrap())
@@ -45,11 +49,11 @@ impl Sysroot {
45 crates: Arena::default(), 49 crates: Arena::default(),
46 }; 50 };
47 for name in SYSROOT_CRATES.trim().lines() { 51 for name in SYSROOT_CRATES.trim().lines() {
48 let path = src.join(format!("lib{}", name)).join("lib.rs"); 52 let root = src.join(format!("lib{}", name)).join("lib.rs");
49 if path.exists() { 53 if root.exists() {
50 sysroot.crates.alloc(SysrootCrateData { 54 sysroot.crates.alloc(SysrootCrateData {
51 name: name.into(), 55 name: name.into(),
52 path, 56 root,
53 deps: Vec::new(), 57 deps: Vec::new(),
54 }); 58 });
55 } 59 }
@@ -72,6 +76,21 @@ impl Sysroot {
72 } 76 }
73} 77}
74 78
79impl SysrootCrate {
80 pub(crate) fn name(self, sysroot: &Sysroot) -> &SmolStr {
81 &sysroot.crates[self].name
82 }
83 pub(crate) fn root(self, sysroot: &Sysroot) -> &Path {
84 sysroot.crates[self].root.as_path()
85 }
86 pub(crate) fn root_dir(self, sysroot: &Sysroot) -> &Path {
87 self.root(sysroot).parent().unwrap()
88 }
89 pub(crate) fn deps<'a>(self, sysroot: &'a Sysroot) -> impl Iterator<Item = SysrootCrate> + 'a {
90 sysroot.crates[self].deps.iter().map(|&it| it)
91 }
92}
93
75const SYSROOT_CRATES: &str = " 94const SYSROOT_CRATES: &str = "
76std 95std
77core 96core