store file id inside symbol

This commit is contained in:
Aleksey Kladov 2018-09-02 23:36:23 +03:00
parent a5e319ec7e
commit 83e2ab434c
2 changed files with 27 additions and 14 deletions

View file

@ -59,18 +59,18 @@ impl SourceRoot {
} }
} }
} }
pub(crate) fn symbols(&self) -> Vec<(FileId, &FileSymbols)> { pub(crate) fn symbols(&self) -> Vec<&FileSymbols> {
self.file_map self.file_map
.iter() .iter()
.map(|(&file_id, data)| (file_id, symbols(data))) .map(|(&file_id, data)| symbols(file_id, data))
.collect() .collect()
} }
pub fn reindex(&self) { pub fn reindex(&self) {
let now = Instant::now(); let now = Instant::now();
self.file_map self.file_map
.par_iter() .par_iter()
.for_each(|(_, data)| { .for_each(|(&file_id, data)| {
symbols(data); symbols(file_id, data);
}); });
info!("parallel indexing took {:?}", now.elapsed()); info!("parallel indexing took {:?}", now.elapsed());
@ -83,9 +83,9 @@ impl SourceRoot {
} }
} }
fn symbols((data, symbols): &(FileData, OnceCell<FileSymbols>)) -> &FileSymbols { fn symbols(file_id: FileId, (data, symbols): &(FileData, OnceCell<FileSymbols>)) -> &FileSymbols {
let syntax = data.syntax_transient(); let syntax = data.syntax_transient();
symbols.get_or_init(|| FileSymbols::new(&syntax)) symbols.get_or_init(|| FileSymbols::new(file_id, &syntax))
} }
#[derive(Debug)] #[derive(Debug)]
@ -108,3 +108,14 @@ impl FileData {
.unwrap_or_else(|| File::parse(&self.text)) .unwrap_or_else(|| File::parse(&self.text))
} }
} }
// #[derive(Clone, Default, Debug)]
// pub(crate) struct ReadonlySourceRoot {
// data: Arc<ReadonlySourceRoot>
// }
// #[derive(Clone, Default, Debug)]
// pub(crate) struct ReadonlySourceRootInner {
// file_map: HashMap<FileId, FileData>,
// module_map: ModuleMap,
// }

View file

@ -8,12 +8,12 @@ use {Query, FileId, JobToken};
#[derive(Debug)] #[derive(Debug)]
pub(crate) struct FileSymbols { pub(crate) struct FileSymbols {
symbols: Vec<FileSymbol>, symbols: Vec<(FileId, FileSymbol)>,
map: fst::Map, map: fst::Map,
} }
impl FileSymbols { impl FileSymbols {
pub(crate) fn new(file: &File) -> FileSymbols { pub(crate) fn new(file_id: FileId, file: &File) -> FileSymbols {
let mut symbols = file_symbols(file) let mut symbols = file_symbols(file)
.into_iter() .into_iter()
.map(|s| (s.name.as_str().to_lowercase(), s)) .map(|s| (s.name.as_str().to_lowercase(), s))
@ -21,8 +21,10 @@ impl FileSymbols {
symbols.sort_by(|s1, s2| s1.0.cmp(&s2.0)); symbols.sort_by(|s1, s2| s1.0.cmp(&s2.0));
symbols.dedup_by(|s1, s2| s1.0 == s2.0); symbols.dedup_by(|s1, s2| s1.0 == s2.0);
let (names, symbols): (Vec<String>, Vec<FileSymbol>) = let (names, symbols): (Vec<String>, Vec<(FileId, FileSymbol)>) =
symbols.into_iter().unzip(); symbols.into_iter()
.map(|(name, symbol)| (name, (file_id, symbol)))
.unzip();
let map = fst::Map::from_iter( let map = fst::Map::from_iter(
names.into_iter().zip(0u64..) names.into_iter().zip(0u64..)
@ -34,12 +36,12 @@ impl FileSymbols {
impl Query { impl Query {
pub(crate) fn search( pub(crate) fn search(
mut self, mut self,
indices: &[(FileId, &FileSymbols)], indices: &[&FileSymbols],
token: &JobToken, token: &JobToken,
) -> Vec<(FileId, FileSymbol)> { ) -> Vec<(FileId, FileSymbol)> {
let mut op = fst::map::OpBuilder::new(); let mut op = fst::map::OpBuilder::new();
for (_, file_symbols) in indices.iter() { for file_symbols in indices.iter() {
let automaton = fst::automaton::Subsequence::new(&self.lowercased); let automaton = fst::automaton::Subsequence::new(&self.lowercased);
op = op.add(file_symbols.map.search(automaton)) op = op.add(file_symbols.map.search(automaton))
} }
@ -50,10 +52,10 @@ impl Query {
break; break;
} }
for indexed_value in indexed_values { for indexed_value in indexed_values {
let (file_id, file_symbols) = &indices[indexed_value.index]; let file_symbols = &indices[indexed_value.index];
let idx = indexed_value.value as usize; let idx = indexed_value.value as usize;
let symbol = &file_symbols.symbols[idx]; let (file_id, symbol) = &file_symbols.symbols[idx];
if self.only_types && !is_type(symbol.kind) { if self.only_types && !is_type(symbol.kind) {
continue; continue;
} }