diff --git a/Cargo.lock b/Cargo.lock index 031ff47..8e7de7c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -106,14 +106,14 @@ dependencies = [ "lazy_static 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", "radix_trie 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "rls-data 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rls-data 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)", "rls-span 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-serialize 0.3.24 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "rls-data" -version = "0.13.0" +version = "0.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "rls-span 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -203,7 +203,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum radix_trie 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "211c49b6a9995cac0fd1dd9ca60b42cf3a51e151a12eb954b3a9e75513426ee8" "checksum regex 0.1.80 (registry+https://github.com/rust-lang/crates.io-index)" = "4fd4ace6a8cf7860714a2c2280d6c1f7e6a413486c13298bbc86fd3da019402f" "checksum regex-syntax 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "f9ec002c35e86791825ed294b50008eea9ddfc8def4420124fbc6b08db834957" -"checksum rls-data 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ff85bb3a0daf9f64207a5530d90ae1c10f5515cef064c88b6821090678382b44" +"checksum rls-data 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8024f1feaca72d0aa4ae1e2a8d454a31b9a33ed02f8d0e9c8559bf53c267ec3c" "checksum rls-span 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5d7c7046dc6a92f2ae02ed302746db4382e75131b9ce20ce967259f6b5867a6a" "checksum rustc-serialize 0.3.24 (registry+https://github.com/rust-lang/crates.io-index)" = "dcf128d1287d2ea9d80910b5f1120d0b8eede3fbf1abe91c40d39ea7d51e6fda" "checksum syn 0.11.11 (registry+https://github.com/rust-lang/crates.io-index)" = "d3b891b9015c88c576343b9b3e41c2c11a51c219ef067b264bd9c8aa9b441dad" diff --git a/Cargo.toml b/Cargo.toml index f09feee..e21b214 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,7 +10,7 @@ categories = ["development-tools"] [dependencies] rustc-serialize = "0.3" log = "0.3" -rls-data = "= 0.13" +rls-data = "= 0.14" rls-span = "0.4" derive-new = "0.5" radix_trie = "0.1" diff --git a/src/analysis.rs b/src/analysis.rs index c83ba1a..b1549ff 100644 --- a/src/analysis.rs +++ b/src/analysis.rs @@ -12,7 +12,7 @@ use std::time::SystemTime; use radix_trie::{Trie, TrieCommon}; use {Id, Span}; -use raw::{CrateId, DefKind}; +use raw::{CrateId, DefKind, ImportKind}; /// This is the main database that contains all the collected symbol information, /// such as definitions, their mapping between spans, hierarchy and so on, @@ -39,6 +39,7 @@ pub struct PerCrateAnalysis { pub ref_spans: HashMap>, pub globs: HashMap, pub impls: HashMap>, + pub imports: Vec, pub root_id: Option, pub timestamp: SystemTime, @@ -88,6 +89,15 @@ pub struct Def { // pub sig: Option, } +#[derive(Debug, Clone)] +pub struct Import { + pub kind: ImportKind, + pub parent: Option, + + /// The imported def. + pub def_id: Option, +} + #[derive(Debug, Clone)] pub struct Signature { pub span: Span, @@ -123,6 +133,7 @@ impl PerCrateAnalysis { ref_spans: HashMap::new(), globs: HashMap::new(), impls: HashMap::new(), + imports: Vec::new(), root_id: None, timestamp, } diff --git a/src/lib.rs b/src/lib.rs index 1195475..18bbcc3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -26,7 +26,7 @@ mod util; #[cfg(test)] mod test; -pub use analysis::{Def, Ref}; +pub use analysis::{Def, Ref, Import}; use analysis::Analysis; pub use raw::{name_space_for_def_kind, read_analysis_from_files, CrateId, DefKind}; pub use loader::{AnalysisLoader, CargoAnalysisLoader, Target}; @@ -286,6 +286,11 @@ impl AnalysisHost { }) } + /// Returns all the imports in the analysis data. + pub fn find_all_imports(&self) -> AResult> { + self.with_analysis(|a| Some(a.for_all_crates(|c| Some(c.imports.clone())))) + } + pub fn id(&self, span: &Span) -> AResult { self.with_analysis(|a| a.def_id_for_span(span)) } diff --git a/src/lowering.rs b/src/lowering.rs index 11996b5..e80e692 100644 --- a/src/lowering.rs +++ b/src/lowering.rs @@ -9,7 +9,7 @@ //! For processing the raw save-analysis data from rustc into the rls //! in-memory representation. -use analysis::{Def, Glob, PerCrateAnalysis, Ref}; +use analysis::{Def, Glob, Import, PerCrateAnalysis, Ref}; use data; use raw::{self, RelationKind, CrateId}; use {AResult, AnalysisHost, Id, Span, NULL}; @@ -176,6 +176,14 @@ impl CrateReader { let def_id = self.id_from_compiler_id(ref_id); self.record_ref(def_id, span, analysis, project_analysis); } + + let import = Import { + kind: i.kind, + parent: i.parent.map(|id| self.id_from_compiler_id(&id)), + def_id: i.ref_id.map(|id| self.id_from_compiler_id(&id)), + }; + trace!("record import {:?}", import); + analysis.imports.push(import); } } diff --git a/src/raw.rs b/src/raw.rs index f73dd01..4b24d38 100644 --- a/src/raw.rs +++ b/src/raw.rs @@ -8,7 +8,7 @@ use {AnalysisLoader, Blacklist}; use listings::{DirectoryListing, ListingKind}; -pub use data::{CratePreludeData, Def, DefKind, GlobalCrateId as CrateId, Import, +pub use data::{CratePreludeData, Def, DefKind, GlobalCrateId as CrateId, Import, ImportKind, Ref, Relation, RelationKind, SigElement, Signature, SpanData}; use data::Analysis;