diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/libanalysis/src/descriptors.rs | 10 | ||||
-rw-r--r-- | 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 { | |||
42 | pub name: SmolStr, | 42 | pub name: SmolStr, |
43 | } | 43 | } |
44 | 44 | ||
45 | #[derive(Hash)] | 45 | #[derive(Hash, Debug)] |
46 | pub(crate) struct ModuleTreeDescriptor { | 46 | pub(crate) struct ModuleTreeDescriptor { |
47 | nodes: Vec<NodeData>, | 47 | nodes: Vec<NodeData>, |
48 | links: Vec<LinkData>, | 48 | links: Vec<LinkData>, |
49 | file_id2node: BTreeMap<FileId, Node>, | 49 | file_id2node: BTreeMap<FileId, Node>, |
50 | } | 50 | } |
51 | 51 | ||
52 | #[derive(Clone, Copy, PartialEq, Eq, Hash)] | 52 | #[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)] |
53 | struct Node(usize); | 53 | struct Node(usize); |
54 | #[derive(Hash)] | 54 | #[derive(Hash, Debug)] |
55 | struct NodeData { | 55 | struct NodeData { |
56 | file_id: FileId, | 56 | file_id: FileId, |
57 | links: Vec<Link>, | 57 | links: Vec<Link>, |
58 | parents: Vec<Link> | 58 | parents: Vec<Link> |
59 | } | 59 | } |
60 | 60 | ||
61 | #[derive(Clone, Copy, PartialEq, Eq, Hash)] | 61 | #[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)] |
62 | pub(crate) struct Link(usize); | 62 | pub(crate) struct Link(usize); |
63 | #[derive(Hash)] | 63 | #[derive(Hash, Debug)] |
64 | struct LinkData { | 64 | struct LinkData { |
65 | owner: Node, | 65 | owner: Node, |
66 | name: SmolStr, | 66 | 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 { | |||
15 | imp::FileResolverImp, | 15 | imp::FileResolverImp, |
16 | module_map::{ModuleMap, ChangeKind}, | 16 | module_map::{ModuleMap, ChangeKind}, |
17 | symbol_index::SymbolIndex, | 17 | symbol_index::SymbolIndex, |
18 | descriptors::ModuleTreeDescriptor, | 18 | descriptors::{ModuleDescriptor, ModuleTreeDescriptor}, |
19 | }; | 19 | }; |
20 | 20 | ||
21 | pub(crate) trait SourceRoot { | 21 | pub(crate) trait SourceRoot { |
@@ -137,30 +137,35 @@ impl FileData { | |||
137 | pub(crate) struct ReadonlySourceRoot { | 137 | pub(crate) struct ReadonlySourceRoot { |
138 | symbol_index: SymbolIndex, | 138 | symbol_index: SymbolIndex, |
139 | file_map: HashMap<FileId, FileData>, | 139 | file_map: HashMap<FileId, FileData>, |
140 | module_map: ModuleMap, | 140 | module_tree: Arc<ModuleTreeDescriptor>, |
141 | } | 141 | } |
142 | 142 | ||
143 | impl ReadonlySourceRoot { | 143 | impl ReadonlySourceRoot { |
144 | pub(crate) fn new(files: Vec<(FileId, String)>, file_resolver: FileResolverImp) -> ReadonlySourceRoot { | 144 | pub(crate) fn new(files: Vec<(FileId, String)>, file_resolver: FileResolverImp) -> ReadonlySourceRoot { |
145 | let mut module_map = ModuleMap::new(); | 145 | let modules = files.par_iter() |
146 | module_map.set_file_resolver(file_resolver); | 146 | .map(|(file_id, text)| { |
147 | let symbol_index = SymbolIndex::for_files( | 147 | let syntax = File::parse(text); |
148 | files.par_iter().map(|(file_id, text)| { | 148 | let mod_descr = ModuleDescriptor::new(syntax.ast()); |
149 | (*file_id, File::parse(text)) | 149 | (*file_id, syntax, mod_descr) |
150 | }) | 150 | }) |
151 | .collect::<Vec<_>>(); | ||
152 | let module_tree = ModuleTreeDescriptor::new( | ||
153 | modules.iter().map(|it| (it.0, &it.2)), | ||
154 | &file_resolver, | ||
155 | ); | ||
156 | |||
157 | let symbol_index = SymbolIndex::for_files( | ||
158 | modules.par_iter().map(|it| (it.0, it.1.clone())) | ||
151 | ); | 159 | ); |
152 | let file_map: HashMap<FileId, FileData> = files | 160 | let file_map: HashMap<FileId, FileData> = files |
153 | .into_iter() | 161 | .into_iter() |
154 | .map(|(id, text)| { | 162 | .map(|(id, text)| (id, FileData::new(text))) |
155 | module_map.update_file(id, ChangeKind::Insert); | ||
156 | (id, FileData::new(text)) | ||
157 | }) | ||
158 | .collect(); | 163 | .collect(); |
159 | 164 | ||
160 | ReadonlySourceRoot { | 165 | ReadonlySourceRoot { |
161 | symbol_index, | 166 | symbol_index, |
162 | file_map, | 167 | file_map, |
163 | module_map, | 168 | module_tree: Arc::new(module_tree), |
164 | } | 169 | } |
165 | } | 170 | } |
166 | 171 | ||
@@ -173,6 +178,9 @@ impl ReadonlySourceRoot { | |||
173 | } | 178 | } |
174 | 179 | ||
175 | impl SourceRoot for ReadonlySourceRoot { | 180 | impl SourceRoot for ReadonlySourceRoot { |
181 | fn module_tree(&self) -> Arc<ModuleTreeDescriptor> { | ||
182 | Arc::clone(&self.module_tree) | ||
183 | } | ||
176 | fn contains(&self, file_id: FileId) -> bool { | 184 | fn contains(&self, file_id: FileId) -> bool { |
177 | self.file_map.contains_key(&file_id) | 185 | self.file_map.contains_key(&file_id) |
178 | } | 186 | } |