From 83e2ab434cf20313c9248fbbe7e90f65f27d31ce Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 2 Sep 2018 23:36:23 +0300 Subject: store file id inside symbol --- crates/libanalysis/src/roots.rs | 23 +++++++++++++++++------ crates/libanalysis/src/symbol_index.rs | 18 ++++++++++-------- 2 files changed, 27 insertions(+), 14 deletions(-) (limited to 'crates/libanalysis/src') diff --git a/crates/libanalysis/src/roots.rs b/crates/libanalysis/src/roots.rs index eb14e7567..01de3e128 100644 --- a/crates/libanalysis/src/roots.rs +++ b/crates/libanalysis/src/roots.rs @@ -59,18 +59,18 @@ impl SourceRoot { } } } - pub(crate) fn symbols(&self) -> Vec<(FileId, &FileSymbols)> { + pub(crate) fn symbols(&self) -> Vec<&FileSymbols> { self.file_map .iter() - .map(|(&file_id, data)| (file_id, symbols(data))) + .map(|(&file_id, data)| symbols(file_id, data)) .collect() } pub fn reindex(&self) { let now = Instant::now(); self.file_map .par_iter() - .for_each(|(_, data)| { - symbols(data); + .for_each(|(&file_id, data)| { + symbols(file_id, data); }); info!("parallel indexing took {:?}", now.elapsed()); @@ -83,9 +83,9 @@ impl SourceRoot { } } -fn symbols((data, symbols): &(FileData, OnceCell)) -> &FileSymbols { +fn symbols(file_id: FileId, (data, symbols): &(FileData, OnceCell)) -> &FileSymbols { let syntax = data.syntax_transient(); - symbols.get_or_init(|| FileSymbols::new(&syntax)) + symbols.get_or_init(|| FileSymbols::new(file_id, &syntax)) } #[derive(Debug)] @@ -108,3 +108,14 @@ impl FileData { .unwrap_or_else(|| File::parse(&self.text)) } } + +// #[derive(Clone, Default, Debug)] +// pub(crate) struct ReadonlySourceRoot { +// data: Arc +// } + +// #[derive(Clone, Default, Debug)] +// pub(crate) struct ReadonlySourceRootInner { +// file_map: HashMap, +// module_map: ModuleMap, +// } diff --git a/crates/libanalysis/src/symbol_index.rs b/crates/libanalysis/src/symbol_index.rs index 2cad3f6eb..54952cb94 100644 --- a/crates/libanalysis/src/symbol_index.rs +++ b/crates/libanalysis/src/symbol_index.rs @@ -8,12 +8,12 @@ use {Query, FileId, JobToken}; #[derive(Debug)] pub(crate) struct FileSymbols { - symbols: Vec, + symbols: Vec<(FileId, FileSymbol)>, map: fst::Map, } 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) .into_iter() .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.dedup_by(|s1, s2| s1.0 == s2.0); - let (names, symbols): (Vec, Vec) = - symbols.into_iter().unzip(); + let (names, symbols): (Vec, Vec<(FileId, FileSymbol)>) = + symbols.into_iter() + .map(|(name, symbol)| (name, (file_id, symbol))) + .unzip(); let map = fst::Map::from_iter( names.into_iter().zip(0u64..) @@ -34,12 +36,12 @@ impl FileSymbols { impl Query { pub(crate) fn search( mut self, - indices: &[(FileId, &FileSymbols)], + indices: &[&FileSymbols], token: &JobToken, ) -> Vec<(FileId, FileSymbol)> { 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); op = op.add(file_symbols.map.search(automaton)) } @@ -50,10 +52,10 @@ impl Query { break; } 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 symbol = &file_symbols.symbols[idx]; + let (file_id, symbol) = &file_symbols.symbols[idx]; if self.only_types && !is_type(symbol.kind) { continue; } -- cgit v1.2.3