diff options
Diffstat (limited to 'crates/libanalysis/src/roots.rs')
-rw-r--r-- | crates/libanalysis/src/roots.rs | 28 |
1 files changed, 12 insertions, 16 deletions
diff --git a/crates/libanalysis/src/roots.rs b/crates/libanalysis/src/roots.rs index 0e7253ba2..191d0d821 100644 --- a/crates/libanalysis/src/roots.rs +++ b/crates/libanalysis/src/roots.rs | |||
@@ -22,7 +22,7 @@ pub(crate) trait SourceRoot { | |||
22 | fn module_tree(&self) -> Arc<ModuleTreeDescriptor>; | 22 | fn module_tree(&self) -> Arc<ModuleTreeDescriptor>; |
23 | fn lines(&self, file_id: FileId) -> Arc<LineIndex>; | 23 | fn lines(&self, file_id: FileId) -> Arc<LineIndex>; |
24 | fn syntax(&self, file_id: FileId) -> File; | 24 | fn syntax(&self, file_id: FileId) -> File; |
25 | fn symbols<'a>(&'a self, acc: &mut Vec<&'a SymbolIndex>); | 25 | fn symbols(&self, acc: &mut Vec<Arc<SymbolIndex>>); |
26 | } | 26 | } |
27 | 27 | ||
28 | #[derive(Default, Debug)] | 28 | #[derive(Default, Debug)] |
@@ -74,20 +74,16 @@ impl SourceRoot for WritableSourceRoot { | |||
74 | fn syntax(&self, file_id: FileId) -> File { | 74 | fn syntax(&self, file_id: FileId) -> File { |
75 | self.db.make_query(|ctx| ::queries::file_syntax(ctx, file_id)) | 75 | self.db.make_query(|ctx| ::queries::file_syntax(ctx, file_id)) |
76 | } | 76 | } |
77 | fn symbols<'a>(&'a self, acc: &mut Vec<&'a SymbolIndex>) { | 77 | fn symbols<'a>(&'a self, acc: &mut Vec<Arc<SymbolIndex>>) { |
78 | // acc.extend( | 78 | self.db.make_query(|ctx| { |
79 | // self.file_map | 79 | let file_set = ::queries::file_set(ctx); |
80 | // .iter() | 80 | let syms = file_set.0.iter() |
81 | // .map(|(&file_id, data)| symbols(file_id, data)) | 81 | .map(|file_id| ::queries::file_symbols(ctx, *file_id)); |
82 | // ) | 82 | acc.extend(syms); |
83 | }); | ||
83 | } | 84 | } |
84 | } | 85 | } |
85 | 86 | ||
86 | fn symbols(file_id: FileId, (data, symbols): &(FileData, OnceCell<SymbolIndex>)) -> &SymbolIndex { | ||
87 | let syntax = data.syntax_transient(); | ||
88 | symbols.get_or_init(|| SymbolIndex::for_file(file_id, syntax)) | ||
89 | } | ||
90 | |||
91 | #[derive(Debug)] | 87 | #[derive(Debug)] |
92 | struct FileData { | 88 | struct FileData { |
93 | text: String, | 89 | text: String, |
@@ -121,7 +117,7 @@ impl FileData { | |||
121 | 117 | ||
122 | #[derive(Debug)] | 118 | #[derive(Debug)] |
123 | pub(crate) struct ReadonlySourceRoot { | 119 | pub(crate) struct ReadonlySourceRoot { |
124 | symbol_index: SymbolIndex, | 120 | symbol_index: Arc<SymbolIndex>, |
125 | file_map: HashMap<FileId, FileData>, | 121 | file_map: HashMap<FileId, FileData>, |
126 | module_tree: Arc<ModuleTreeDescriptor>, | 122 | module_tree: Arc<ModuleTreeDescriptor>, |
127 | } | 123 | } |
@@ -149,7 +145,7 @@ impl ReadonlySourceRoot { | |||
149 | .collect(); | 145 | .collect(); |
150 | 146 | ||
151 | ReadonlySourceRoot { | 147 | ReadonlySourceRoot { |
152 | symbol_index, | 148 | symbol_index: Arc::new(symbol_index), |
153 | file_map, | 149 | file_map, |
154 | module_tree: Arc::new(module_tree), | 150 | module_tree: Arc::new(module_tree), |
155 | } | 151 | } |
@@ -176,7 +172,7 @@ impl SourceRoot for ReadonlySourceRoot { | |||
176 | fn syntax(&self, file_id: FileId) -> File { | 172 | fn syntax(&self, file_id: FileId) -> File { |
177 | self.data(file_id).syntax().clone() | 173 | self.data(file_id).syntax().clone() |
178 | } | 174 | } |
179 | fn symbols<'a>(&'a self, acc: &mut Vec<&'a SymbolIndex>) { | 175 | fn symbols(&self, acc: &mut Vec<Arc<SymbolIndex>>) { |
180 | acc.push(&self.symbol_index) | 176 | acc.push(Arc::clone(&self.symbol_index)) |
181 | } | 177 | } |
182 | } | 178 | } |