Skip to content
This repository was archived by the owner on Mar 1, 2019. It is now read-only.
Merged
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
13 changes: 10 additions & 3 deletions Cargo.lock

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

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ exclude = [
[dependencies]
rustc-serialize = "0.3"
log = "0.4"
rls-data = "= 0.16"
rls-data = "= 0.17"
rls-span = "0.4"
derive-new = "0.5"
fst = { version = "0.3", default-features = false }
itertools = "0.7.3"
json = "0.11.13"

[dev-dependencies]
lazy_static = "1"
Expand Down
53 changes: 53 additions & 0 deletions examples/print-crate-id.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
extern crate rls_analysis;
extern crate env_logger;

use rls_analysis::{AnalysisHost, AnalysisLoader, SearchDirectory};
use std::path::{Path, PathBuf};
use std::env;

#[derive(Clone)]
pub struct Loader {
deps_dir: PathBuf,
}

impl Loader {
pub fn new(deps_dir: PathBuf) -> Self {
Self { deps_dir }
}
}

impl AnalysisLoader for Loader {
fn needs_hard_reload(&self, _: &Path) -> bool {
true
}

fn fresh_host(&self) -> AnalysisHost<Self> {
AnalysisHost::new_with_loader(self.clone())
}

fn set_path_prefix(&mut self, _: &Path) {}

fn abs_path_prefix(&self) -> Option<PathBuf> {
None
}
fn search_directories(&self) -> Vec<SearchDirectory> {
vec![SearchDirectory {
path: self.deps_dir.clone(),
prefix_rewrite: None,
}]
}
}

fn main() {
env_logger::init();
if env::args().len() < 2 {
println!("Usage: print-crate-id <save-analysis-dir>");
std::process::exit(1);
}
let loader = Loader::new(PathBuf::from(env::args().nth(1).unwrap()));
let crates = rls_analysis::read_analysis_from_files(&loader, Default::default(), &[]);

for krate in &crates {
println!("Crate {:?} data version {:?}", krate.id, krate.analysis.version);
}
}
3 changes: 2 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ extern crate rls_span as span;
extern crate rustc_serialize;
extern crate fst;
extern crate itertools;
extern crate json;

mod analysis;
mod raw;
Expand All @@ -31,7 +32,7 @@ mod test;
pub use analysis::{Def, Ref};
use analysis::Analysis;
pub use raw::{name_space_for_def_kind, read_analysis_from_files, CrateId, DefKind};
pub use loader::{AnalysisLoader, CargoAnalysisLoader, Target};
pub use loader::{AnalysisLoader, CargoAnalysisLoader, SearchDirectory, Target};
pub use symbol_query::SymbolQuery;

use std::collections::HashMap;
Expand Down
21 changes: 19 additions & 2 deletions src/raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
// except according to those terms.

use {AnalysisLoader, Blacklist};
use json;
use listings::{DirectoryListing, ListingKind};
pub use data::{CratePreludeData, Def, DefKind, GlobalCrateId as CrateId, Import,
Ref, Relation, RelationKind, SigElement, Signature, SpanData};
use data::Analysis;
use data::config::Config;

use std::collections::HashMap;
use std::fs::File;
Expand Down Expand Up @@ -104,11 +106,26 @@ fn read_crate_data(path: &Path) -> Option<Analysis> {
let t = Instant::now();

let buf = read_file_contents(path).or_else(|err| {
info!("couldn't read file: {}", err);
warn!("couldn't read file: {}", err);
Err(err)
}).ok()?;
let s = ::rustc_serialize::json::decode(&buf).or_else(|err| {
info!("deserialisation error: {:?}", err);
warn!("deserialisation error: {:?}", err);
json::parse(&buf).map(|parsed| {
if let json::JsonValue::Object(obj) = parsed {
let expected = Some(json::JsonValue::from(Analysis::new(Config::default()).version));
let actual = obj.get("version").map(|v| v.clone());
if expected != actual {
warn!("Data file version mismatch; expected {:?} but got {:?}",
expected, actual);
}
} else {
warn!("Data file didn't have a JSON object at the root");
}
}).map_err(|err| {
warn!("Data file was not valid JSON: {:?}", err);
}).ok();

Err(err)
}).ok()?;

Expand Down