blob: 0c413becd85aa35230d8bc67c37acf31b634ea98 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
use crate::{
Cancelable,
db::SyntaxDatabase,
descriptors::{ModuleDescriptor, ModuleTreeDescriptor},
FileId,
};
use std::sync::Arc;
salsa::query_group! {
pub(crate) trait ModulesDatabase: SyntaxDatabase {
fn module_tree() -> Cancelable<Arc<ModuleTreeDescriptor>> {
type ModuleTreeQuery;
}
fn module_descriptor(file_id: FileId) -> Cancelable<Arc<ModuleDescriptor>> {
type ModuleDescriptorQuery;
}
}
}
fn module_descriptor(db: &impl ModulesDatabase, file_id: FileId) -> Cancelable<Arc<ModuleDescriptor>> {
let file = db.file_syntax(file_id);
Ok(Arc::new(ModuleDescriptor::new(file.ast())))
}
fn module_tree(db: &impl ModulesDatabase) -> Cancelable<Arc<ModuleTreeDescriptor>> {
let file_set = db.file_set();
let mut files = Vec::new();
for &file_id in file_set.files.iter() {
let module_descr = db.module_descriptor(file_id)?;
files.push((file_id, module_descr));
}
let res = ModuleTreeDescriptor::new(
files.iter().map(|(file_id, descr)| (*file_id, &**descr)),
&file_set.resolver,
);
Ok(Arc::new(res))
}
|