From 9b1356464a834e0b9a88dd3eeabc50bf1d734f35 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 8 Dec 2018 23:16:11 +0300 Subject: propagate deps to CrateGraph --- crates/ra_db/src/input.rs | 3 +++ 1 file changed, 3 insertions(+) (limited to 'crates/ra_db/src') diff --git a/crates/ra_db/src/input.rs b/crates/ra_db/src/input.rs index 7d9faa43c..a48d05b98 100644 --- a/crates/ra_db/src/input.rs +++ b/crates/ra_db/src/input.rs @@ -48,6 +48,9 @@ impl CrateGraph { assert!(prev.is_none()); crate_id } + //FIXME: check that we don't have cycles here. + // Just a simple depth first search from `to` should work, + // the graph is small. pub fn add_dep(&mut self, from: CrateId, to: CrateId) { self.arena.get_mut(&from).unwrap().add_dep(to) } -- cgit v1.2.3 From ca7e5905c1daffbed6a08fe674ae821f99bd274d Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 9 Dec 2018 00:51:06 +0300 Subject: more crate boilerplate --- crates/ra_db/src/input.rs | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'crates/ra_db/src') diff --git a/crates/ra_db/src/input.rs b/crates/ra_db/src/input.rs index a48d05b98..37da8c549 100644 --- a/crates/ra_db/src/input.rs +++ b/crates/ra_db/src/input.rs @@ -20,25 +20,31 @@ pub struct CrateGraph { #[derive(Debug, Clone, PartialEq, Eq)] struct CrateData { file_id: FileId, - deps: Vec, + dependencies: Vec, } impl CrateData { fn new(file_id: FileId) -> CrateData { CrateData { file_id, - deps: Vec::new(), + dependencies: Vec::new(), } } fn add_dep(&mut self, dep: CrateId) { - self.deps.push(Dependency { crate_: dep }) + self.dependencies.push(Dependency { crate_id: dep }) } } #[derive(Debug, Clone, PartialEq, Eq)] pub struct Dependency { - crate_: CrateId, + crate_id: CrateId, +} + +impl Dependency { + pub fn crate_id(&self) -> CrateId { + self.crate_id + } } impl CrateGraph { @@ -64,6 +70,12 @@ impl CrateGraph { .find(|(_crate_id, data)| data.file_id == file_id)?; Some(crate_id) } + pub fn dependencies<'a>( + &'a self, + crate_id: CrateId, + ) -> impl Iterator + 'a { + self.arena[&crate_id].dependencies.iter() + } } salsa::query_group! { -- cgit v1.2.3 From 961cae7e53a05625f3e010076673ca083479b481 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 9 Dec 2018 01:02:53 +0300 Subject: thread info about dep names --- crates/ra_db/src/input.rs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'crates/ra_db/src') diff --git a/crates/ra_db/src/input.rs b/crates/ra_db/src/input.rs index 37da8c549..44c5bac93 100644 --- a/crates/ra_db/src/input.rs +++ b/crates/ra_db/src/input.rs @@ -1,7 +1,7 @@ use std::sync::Arc; -use rustc_hash::FxHashMap; -use rustc_hash::FxHashSet; +use rustc_hash::{FxHashSet, FxHashMap}; +use ra_syntax::SmolStr; use salsa; use crate::file_resolver::FileResolverImp; @@ -31,14 +31,15 @@ impl CrateData { } } - fn add_dep(&mut self, dep: CrateId) { - self.dependencies.push(Dependency { crate_id: dep }) + fn add_dep(&mut self, name: SmolStr, crate_id: CrateId) { + self.dependencies.push(Dependency { name, crate_id }) } } #[derive(Debug, Clone, PartialEq, Eq)] pub struct Dependency { crate_id: CrateId, + name: SmolStr, } impl Dependency { @@ -57,8 +58,8 @@ impl CrateGraph { //FIXME: check that we don't have cycles here. // Just a simple depth first search from `to` should work, // the graph is small. - pub fn add_dep(&mut self, from: CrateId, to: CrateId) { - self.arena.get_mut(&from).unwrap().add_dep(to) + pub fn add_dep(&mut self, from: CrateId, name: SmolStr, to: CrateId) { + self.arena.get_mut(&from).unwrap().add_dep(name, to) } pub fn crate_root(&self, crate_id: CrateId) -> FileId { self.arena[&crate_id].file_id -- cgit v1.2.3 From 74fe581061be5175835efda69ee1fa3817716a59 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 9 Dec 2018 01:05:49 +0300 Subject: return dependencies with names --- crates/ra_db/src/input.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'crates/ra_db/src') diff --git a/crates/ra_db/src/input.rs b/crates/ra_db/src/input.rs index 44c5bac93..ac144b991 100644 --- a/crates/ra_db/src/input.rs +++ b/crates/ra_db/src/input.rs @@ -38,8 +38,8 @@ impl CrateData { #[derive(Debug, Clone, PartialEq, Eq)] pub struct Dependency { - crate_id: CrateId, - name: SmolStr, + pub crate_id: CrateId, + pub name: SmolStr, } impl Dependency { -- cgit v1.2.3 From 7784c7a701ba944decf671f80dea581d68667663 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 9 Dec 2018 13:49:54 +0300 Subject: resolve extern crates propertly --- crates/ra_db/src/mock.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'crates/ra_db/src') diff --git a/crates/ra_db/src/mock.rs b/crates/ra_db/src/mock.rs index 2840f9655..2f7551597 100644 --- a/crates/ra_db/src/mock.rs +++ b/crates/ra_db/src/mock.rs @@ -5,7 +5,7 @@ use relative_path::{RelativePath, RelativePathBuf}; use crate::{FileId, FileResolver, SourceRoot, FileResolverImp}; -#[derive(Default, Debug)] +#[derive(Default, Debug, Clone)] pub struct FileMap(Vec<(FileId, RelativePathBuf)>); impl FileMap { @@ -28,6 +28,11 @@ impl FileMap { self.iter().map(|(id, _)| id).collect() } + pub fn file_id(&self, path: &str) -> FileId { + assert!(path.starts_with('/')); + self.iter().find(|(_, p)| p == &path[1..]).unwrap().0 + } + fn iter<'a>(&'a self) -> impl Iterator + 'a { self.0 .iter() -- cgit v1.2.3