Skip to content
This repository was archived by the owner on Mar 1, 2019. It is now read-only.

add function to find all imports #124

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
13 changes: 12 additions & 1 deletion src/analysis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -39,6 +39,7 @@ pub struct PerCrateAnalysis {
pub ref_spans: HashMap<Id, Vec<Span>>,
pub globs: HashMap<Span, Glob>,
pub impls: HashMap<Id, Vec<Span>>,
pub imports: Vec<Import>,

pub root_id: Option<Id>,
pub timestamp: SystemTime,
Expand Down Expand Up @@ -88,6 +89,15 @@ pub struct Def {
// pub sig: Option<Signature>,
}

#[derive(Debug, Clone)]
pub struct Import {
pub kind: ImportKind,
pub parent: Option<Id>,

/// The imported def.
pub def_id: Option<Id>,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would just call this def, not def_id

}

#[derive(Debug, Clone)]
pub struct Signature {
pub span: Span,
Expand Down Expand Up @@ -123,6 +133,7 @@ impl PerCrateAnalysis {
ref_spans: HashMap::new(),
globs: HashMap::new(),
impls: HashMap::new(),
imports: Vec::new(),
root_id: None,
timestamp,
}
Expand Down
7 changes: 6 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -286,6 +286,11 @@ impl<L: AnalysisLoader> AnalysisHost<L> {
})
}

/// Returns all the imports in the analysis data.
pub fn find_all_imports(&self) -> AResult<Vec<Import>> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would call this all_imports - it's not really finding anything, just dumping everything at once.

self.with_analysis(|a| Some(a.for_all_crates(|c| Some(c.imports.clone()))))
}

pub fn id(&self, span: &Span) -> AResult<Id> {
self.with_analysis(|a| a.def_id_for_span(span))
}
Expand Down
10 changes: 9 additions & 1 deletion src/lowering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down