diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/libanalysis/src/queries.rs | 21 | ||||
-rw-r--r-- | crates/libanalysis/src/roots.rs | 28 | ||||
-rw-r--r-- | crates/libanalysis/src/symbol_index.rs | 12 | ||||
-rw-r--r-- | crates/libeditor/src/symbols.rs | 2 |
4 files changed, 40 insertions, 23 deletions
diff --git a/crates/libanalysis/src/queries.rs b/crates/libanalysis/src/queries.rs index 9d6754fd4..0b60316e6 100644 --- a/crates/libanalysis/src/queries.rs +++ b/crates/libanalysis/src/queries.rs | |||
@@ -3,13 +3,11 @@ use libsyntax2::File; | |||
3 | use libeditor::LineIndex; | 3 | use libeditor::LineIndex; |
4 | use { | 4 | use { |
5 | FileId, | 5 | FileId, |
6 | db::{Query, QueryCtx, QueryRegistry, file_text}, | 6 | db::{Query, QueryCtx, QueryRegistry}, |
7 | symbol_index::SymbolIndex, | ||
7 | }; | 8 | }; |
8 | 9 | ||
9 | pub(crate) fn register_queries(reg: &mut QueryRegistry) { | 10 | pub(crate) use db::{file_text, file_set}; |
10 | reg.add(FILE_SYNTAX, "FILE_SYNTAX"); | ||
11 | reg.add(FILE_LINES, "FILE_LINES"); | ||
12 | } | ||
13 | 11 | ||
14 | pub(crate) fn file_syntax(ctx: QueryCtx, file_id: FileId) -> File { | 12 | pub(crate) fn file_syntax(ctx: QueryCtx, file_id: FileId) -> File { |
15 | (&*ctx.get(FILE_SYNTAX, file_id)).clone() | 13 | (&*ctx.get(FILE_SYNTAX, file_id)).clone() |
@@ -17,6 +15,9 @@ pub(crate) fn file_syntax(ctx: QueryCtx, file_id: FileId) -> File { | |||
17 | pub(crate) fn file_lines(ctx: QueryCtx, file_id: FileId) -> Arc<LineIndex> { | 15 | pub(crate) fn file_lines(ctx: QueryCtx, file_id: FileId) -> Arc<LineIndex> { |
18 | ctx.get(FILE_LINES, file_id) | 16 | ctx.get(FILE_LINES, file_id) |
19 | } | 17 | } |
18 | pub(crate) fn file_symbols(ctx: QueryCtx, file_id: FileId) -> Arc<SymbolIndex> { | ||
19 | ctx.get(FILE_SYMBOLS, file_id) | ||
20 | } | ||
20 | 21 | ||
21 | const FILE_SYNTAX: Query<FileId, File> = Query(16, |ctx, file_id: &FileId| { | 22 | const FILE_SYNTAX: Query<FileId, File> = Query(16, |ctx, file_id: &FileId| { |
22 | let text = file_text(ctx, *file_id); | 23 | let text = file_text(ctx, *file_id); |
@@ -26,3 +27,13 @@ const FILE_LINES: Query<FileId, LineIndex> = Query(17, |ctx, file_id: &FileId| { | |||
26 | let text = file_text(ctx, *file_id); | 27 | let text = file_text(ctx, *file_id); |
27 | LineIndex::new(&*text) | 28 | LineIndex::new(&*text) |
28 | }); | 29 | }); |
30 | const FILE_SYMBOLS: Query<FileId, SymbolIndex> = Query(18, |ctx, file_id: &FileId| { | ||
31 | let syntax = file_syntax(ctx, *file_id); | ||
32 | SymbolIndex::for_file(*file_id, syntax) | ||
33 | }); | ||
34 | |||
35 | pub(crate) fn register_queries(reg: &mut QueryRegistry) { | ||
36 | reg.add(FILE_SYNTAX, "FILE_SYNTAX"); | ||
37 | reg.add(FILE_LINES, "FILE_LINES"); | ||
38 | reg.add(FILE_SYMBOLS, "FILE_SYMBOLS"); | ||
39 | } | ||
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 | } |
diff --git a/crates/libanalysis/src/symbol_index.rs b/crates/libanalysis/src/symbol_index.rs index 4c93761aa..d22187ac0 100644 --- a/crates/libanalysis/src/symbol_index.rs +++ b/crates/libanalysis/src/symbol_index.rs | |||
@@ -1,3 +1,7 @@ | |||
1 | use std::{ | ||
2 | sync::Arc, | ||
3 | hash::{Hash, Hasher}, | ||
4 | }; | ||
1 | use libeditor::{FileSymbol, file_symbols}; | 5 | use libeditor::{FileSymbol, file_symbols}; |
2 | use libsyntax2::{ | 6 | use libsyntax2::{ |
3 | File, | 7 | File, |
@@ -13,6 +17,12 @@ pub(crate) struct SymbolIndex { | |||
13 | map: fst::Map, | 17 | map: fst::Map, |
14 | } | 18 | } |
15 | 19 | ||
20 | impl Hash for SymbolIndex { | ||
21 | fn hash<H: Hasher>(&self, hasher: &mut H) { | ||
22 | self.symbols.hash(hasher) | ||
23 | } | ||
24 | } | ||
25 | |||
16 | impl SymbolIndex { | 26 | impl SymbolIndex { |
17 | pub(crate) fn for_files(files: impl ParallelIterator<Item=(FileId, File)>) -> SymbolIndex { | 27 | pub(crate) fn for_files(files: impl ParallelIterator<Item=(FileId, File)>) -> SymbolIndex { |
18 | let mut symbols = files | 28 | let mut symbols = files |
@@ -43,7 +53,7 @@ impl SymbolIndex { | |||
43 | impl Query { | 53 | impl Query { |
44 | pub(crate) fn search( | 54 | pub(crate) fn search( |
45 | self, | 55 | self, |
46 | indices: &[&SymbolIndex], | 56 | indices: &[Arc<SymbolIndex>], |
47 | token: &JobToken, | 57 | token: &JobToken, |
48 | ) -> Vec<(FileId, FileSymbol)> { | 58 | ) -> Vec<(FileId, FileSymbol)> { |
49 | 59 | ||
diff --git a/crates/libeditor/src/symbols.rs b/crates/libeditor/src/symbols.rs index 28b86c004..2f9cc9233 100644 --- a/crates/libeditor/src/symbols.rs +++ b/crates/libeditor/src/symbols.rs | |||
@@ -17,7 +17,7 @@ pub struct StructureNode { | |||
17 | pub kind: SyntaxKind, | 17 | pub kind: SyntaxKind, |
18 | } | 18 | } |
19 | 19 | ||
20 | #[derive(Debug, Clone)] | 20 | #[derive(Debug, Clone, Hash)] |
21 | pub struct FileSymbol { | 21 | pub struct FileSymbol { |
22 | pub name: SmolStr, | 22 | pub name: SmolStr, |
23 | pub node_range: TextRange, | 23 | pub node_range: TextRange, |