aboutsummaryrefslogtreecommitdiff
path: root/crates/libanalysis/src/module_map_db.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/libanalysis/src/module_map_db.rs')
-rw-r--r--crates/libanalysis/src/module_map_db.rs24
1 files changed, 16 insertions, 8 deletions
diff --git a/crates/libanalysis/src/module_map_db.rs b/crates/libanalysis/src/module_map_db.rs
index 25dbe8dd4..14b156b43 100644
--- a/crates/libanalysis/src/module_map_db.rs
+++ b/crates/libanalysis/src/module_map_db.rs
@@ -1,11 +1,14 @@
1use std::sync::Arc; 1use std::sync::Arc;
2use { 2use {
3 FileId, 3 FileId,
4 db::{Query, Eval, QueryCtx, FileSyntax, Files}, 4 db::{
5 Query, Eval, QueryCtx, FileSyntax, Files,
6 Cache, QueryCache,
7 },
5 module_map::resolve_submodule, 8 module_map::resolve_submodule,
6}; 9};
7 10
8enum ModuleDescr {} 11pub(crate) enum ModuleDescr {}
9impl Query for ModuleDescr { 12impl Query for ModuleDescr {
10 const ID: u32 = 30; 13 const ID: u32 = 30;
11 type Params = FileId; 14 type Params = FileId;
@@ -27,6 +30,9 @@ impl Query for ParentModule {
27} 30}
28 31
29impl Eval for ModuleDescr { 32impl Eval for ModuleDescr {
33 fn cache(cache: &mut Cache) -> Option<&mut QueryCache<Self>> {
34 Some(&mut cache.module_descr)
35 }
30 fn eval(ctx: &QueryCtx, file_id: &FileId) -> Arc<descr::ModuleDescr> { 36 fn eval(ctx: &QueryCtx, file_id: &FileId) -> Arc<descr::ModuleDescr> {
31 let file = ctx.get::<FileSyntax>(file_id); 37 let file = ctx.get::<FileSyntax>(file_id);
32 Arc::new(descr::ModuleDescr::new(file.ast())) 38 Arc::new(descr::ModuleDescr::new(file.ast()))
@@ -66,6 +72,7 @@ mod descr {
66 ast::{self, NameOwner}, 72 ast::{self, NameOwner},
67 }; 73 };
68 74
75 #[derive(Debug)]
69 pub struct ModuleDescr { 76 pub struct ModuleDescr {
70 pub submodules: Vec<Submodule> 77 pub submodules: Vec<Submodule>
71 } 78 }
@@ -85,7 +92,7 @@ mod descr {
85 ModuleDescr { submodules } } 92 ModuleDescr { submodules } }
86 } 93 }
87 94
88 #[derive(Clone, Hash)] 95 #[derive(Clone, Hash, PartialEq, Eq, Debug)]
89 pub struct Submodule { 96 pub struct Submodule {
90 pub name: SmolStr, 97 pub name: SmolStr,
91 } 98 }
@@ -98,7 +105,7 @@ mod tests {
98 use im; 105 use im;
99 use relative_path::{RelativePath, RelativePathBuf}; 106 use relative_path::{RelativePath, RelativePathBuf};
100 use { 107 use {
101 db::{Query, Db, TraceEventKind}, 108 db::{Query, DbHost, TraceEventKind},
102 imp::FileResolverImp, 109 imp::FileResolverImp,
103 FileId, FileResolver, 110 FileId, FileResolver,
104 }; 111 };
@@ -122,7 +129,7 @@ mod tests {
122 struct Fixture { 129 struct Fixture {
123 next_file_id: u32, 130 next_file_id: u32,
124 fm: im::HashMap<FileId, RelativePathBuf>, 131 fm: im::HashMap<FileId, RelativePathBuf>,
125 db: Db, 132 db: DbHost,
126 } 133 }
127 134
128 impl Fixture { 135 impl Fixture {
@@ -130,7 +137,7 @@ mod tests {
130 Fixture { 137 Fixture {
131 next_file_id: 1, 138 next_file_id: 1,
132 fm: im::HashMap::new(), 139 fm: im::HashMap::new(),
133 db: Db::new(), 140 db: DbHost::new(),
134 } 141 }
135 } 142 }
136 fn add_file(&mut self, path: &str, text: &str) -> FileId { 143 fn add_file(&mut self, path: &str, text: &str) -> FileId {
@@ -185,10 +192,11 @@ mod tests {
185 fn test_parent_module() { 192 fn test_parent_module() {
186 let mut f = Fixture::new(); 193 let mut f = Fixture::new();
187 let foo = f.add_file("/foo.rs", ""); 194 let foo = f.add_file("/foo.rs", "");
188 f.check_parent_modules(foo, &[], &[(FileSyntax::ID, 1)]); 195 f.check_parent_modules(foo, &[], &[(ModuleDescr::ID, 1)]);
189 196
190 let lib = f.add_file("/lib.rs", "mod foo;"); 197 let lib = f.add_file("/lib.rs", "mod foo;");
191 f.check_parent_modules(foo, &[lib], &[(FileSyntax::ID, 2)]); 198 f.check_parent_modules(foo, &[lib], &[(ModuleDescr::ID, 2)]);
199 f.check_parent_modules(foo, &[lib], &[(ModuleDescr::ID, 0)]);
192 200
193 f.change_file(lib, ""); 201 f.change_file(lib, "");
194 f.check_parent_modules(foo, &[], &[(ModuleDescr::ID, 2)]); 202 f.check_parent_modules(foo, &[], &[(ModuleDescr::ID, 2)]);