From 3ebeb0db8de65434db79c86aeed5473bfb21334f Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 15 Sep 2018 20:56:19 +0300 Subject: move readonly source to module tree descr --- crates/libanalysis/src/descriptors.rs | 10 +++++----- crates/libanalysis/src/roots.rs | 32 ++++++++++++++++++++------------ 2 files changed, 25 insertions(+), 17 deletions(-) diff --git a/crates/libanalysis/src/descriptors.rs b/crates/libanalysis/src/descriptors.rs index e21ee728f..200f21576 100644 --- a/crates/libanalysis/src/descriptors.rs +++ b/crates/libanalysis/src/descriptors.rs @@ -42,25 +42,25 @@ pub struct Submodule { pub name: SmolStr, } -#[derive(Hash)] +#[derive(Hash, Debug)] pub(crate) struct ModuleTreeDescriptor { nodes: Vec, links: Vec, file_id2node: BTreeMap, } -#[derive(Clone, Copy, PartialEq, Eq, Hash)] +#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)] struct Node(usize); -#[derive(Hash)] +#[derive(Hash, Debug)] struct NodeData { file_id: FileId, links: Vec, parents: Vec } -#[derive(Clone, Copy, PartialEq, Eq, Hash)] +#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)] pub(crate) struct Link(usize); -#[derive(Hash)] +#[derive(Hash, Debug)] struct LinkData { owner: Node, name: SmolStr, diff --git a/crates/libanalysis/src/roots.rs b/crates/libanalysis/src/roots.rs index b925fd24d..e9527eeff 100644 --- a/crates/libanalysis/src/roots.rs +++ b/crates/libanalysis/src/roots.rs @@ -15,7 +15,7 @@ use { imp::FileResolverImp, module_map::{ModuleMap, ChangeKind}, symbol_index::SymbolIndex, - descriptors::ModuleTreeDescriptor, + descriptors::{ModuleDescriptor, ModuleTreeDescriptor}, }; pub(crate) trait SourceRoot { @@ -137,30 +137,35 @@ impl FileData { pub(crate) struct ReadonlySourceRoot { symbol_index: SymbolIndex, file_map: HashMap, - module_map: ModuleMap, + module_tree: Arc, } impl ReadonlySourceRoot { pub(crate) fn new(files: Vec<(FileId, String)>, file_resolver: FileResolverImp) -> ReadonlySourceRoot { - let mut module_map = ModuleMap::new(); - module_map.set_file_resolver(file_resolver); - let symbol_index = SymbolIndex::for_files( - files.par_iter().map(|(file_id, text)| { - (*file_id, File::parse(text)) + let modules = files.par_iter() + .map(|(file_id, text)| { + let syntax = File::parse(text); + let mod_descr = ModuleDescriptor::new(syntax.ast()); + (*file_id, syntax, mod_descr) }) + .collect::>(); + let module_tree = ModuleTreeDescriptor::new( + modules.iter().map(|it| (it.0, &it.2)), + &file_resolver, + ); + + let symbol_index = SymbolIndex::for_files( + modules.par_iter().map(|it| (it.0, it.1.clone())) ); let file_map: HashMap = files .into_iter() - .map(|(id, text)| { - module_map.update_file(id, ChangeKind::Insert); - (id, FileData::new(text)) - }) + .map(|(id, text)| (id, FileData::new(text))) .collect(); ReadonlySourceRoot { symbol_index, file_map, - module_map, + module_tree: Arc::new(module_tree), } } @@ -173,6 +178,9 @@ impl ReadonlySourceRoot { } impl SourceRoot for ReadonlySourceRoot { + fn module_tree(&self) -> Arc { + Arc::clone(&self.module_tree) + } fn contains(&self, file_id: FileId) -> bool { self.file_map.contains_key(&file_id) } -- cgit v1.2.3