Skip to content
This repository has been archived by the owner on Dec 29, 2022. It is now read-only.

Commit

Permalink
Auto merge of #1312 - Xanewok:format-subcrates, r=alexheretic
Browse files Browse the repository at this point in the history
Format all pulled subcrates

#1304 but for pulled subcrates.

r? @alexheretic
  • Loading branch information
bors committed Feb 13, 2019
2 parents 6c0bbf5 + 95d0ed0 commit 78664f4
Show file tree
Hide file tree
Showing 17 changed files with 433 additions and 650 deletions.
8 changes: 2 additions & 6 deletions rls-analysis/benches/std_api_crate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,8 @@ impl AnalysisLoader for TestAnalysisLoader {
lazy_static! {
static ref STDLIB_FILE_PATH: PathBuf = PathBuf::from("/checkout/src/libstd/lib.rs");
static ref STDLIB_DATA_PATH: PathBuf = PathBuf::from("test_data/rust-analysis");

static ref HOST: RwLock<AnalysisHost<TestAnalysisLoader>> = {
let host = AnalysisHost::new_with_loader(TestAnalysisLoader::new(
STDLIB_DATA_PATH.clone(),
));
let host = AnalysisHost::new_with_loader(TestAnalysisLoader::new(STDLIB_DATA_PATH.clone()));
host.reload(&STDLIB_DATA_PATH, &STDLIB_DATA_PATH).unwrap();
RwLock::new(host)
};
Expand All @@ -73,7 +70,6 @@ fn search(b: &mut Bencher) {
let host = HOST.read().unwrap();
b.iter(|| {
let _ = host.search("some_inexistent_symbol");

})
}

Expand All @@ -91,4 +87,4 @@ fn reload(b: &mut Bencher) {
b.iter(|| {
host.reload(&STDLIB_DATA_PATH, &STDLIB_DATA_PATH).unwrap();
})
}
}
9 changes: 3 additions & 6 deletions rls-analysis/examples/print-crate-id.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
extern crate rls_analysis;
extern crate env_logger;
extern crate rls_analysis;

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

#[derive(Clone)]
pub struct Loader {
Expand Down Expand Up @@ -31,10 +31,7 @@ impl AnalysisLoader for Loader {
None
}
fn search_directories(&self) -> Vec<SearchDirectory> {
vec![SearchDirectory {
path: self.deps_dir.clone(),
prefix_rewrite: None,
}]
vec![SearchDirectory { path: self.deps_dir.clone(), prefix_rewrite: None }]
}
}

Expand Down
33 changes: 13 additions & 20 deletions rls-analysis/src/analysis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use fst;
use std::collections::{HashMap, HashSet};
use std::iter;
use std::path::{Path, PathBuf};
use std::time::SystemTime;
use std::iter;
use fst;

use {Id, Span, SymbolQuery};
use raw::{CrateId, DefKind};
use {Id, Span, SymbolQuery};

/// This is the main database that contains all the collected symbol information,
/// such as definitions, their mapping between spans, hierarchy and so on,
Expand Down Expand Up @@ -133,11 +133,9 @@ pub struct Glob {
pub value: String,
}


impl PerCrateAnalysis {
pub fn new(timestamp: SystemTime, path: Option<PathBuf>) -> PerCrateAnalysis {
let empty_fst =
fst::Map::from_iter(iter::empty::<(String, u64)>()).unwrap();
let empty_fst = fst::Map::from_iter(iter::empty::<(String, u64)>()).unwrap();
PerCrateAnalysis {
def_id_for_span: HashMap::new(),
defs: HashMap::new(),
Expand Down Expand Up @@ -244,14 +242,13 @@ impl Analysis {
// crate.
pub fn local_def_id_for_span(&self, span: &Span) -> Option<Id> {
self.for_each_crate(|c| {
c.def_id_for_span
.get(span)
.map(|r| r.some_id())
.and_then(|id| if c.defs.contains_key(&id) {
c.def_id_for_span.get(span).map(|r| r.some_id()).and_then(|id| {
if c.defs.contains_key(&id) {
Some(id)
} else {
None
})
}
})
})
}

Expand Down Expand Up @@ -316,19 +313,15 @@ impl Analysis {

pub fn query_defs(&self, query: SymbolQuery) -> Vec<Def> {
let mut crates = Vec::with_capacity(self.per_crate.len());
let stream = query.build_stream(
self.per_crate.values().map(|c| {
crates.push(c);
&c.def_fst
})
);
let stream = query.build_stream(self.per_crate.values().map(|c| {
crates.push(c);
&c.def_fst
}));

query.search_stream(stream, |acc, e| {
let c = &crates[e.index];
let ids = &c.def_fst_values[e.value as usize];
acc.extend(
ids.iter().flat_map(|id| c.defs.get(id)).cloned()
);
acc.extend(ids.iter().flat_map(|id| c.defs.get(id)).cloned());
})
}

Expand Down
Loading

0 comments on commit 78664f4

Please sign in to comment.