diff options
Diffstat (limited to 'crates/libanalysis/src/queries.rs')
-rw-r--r-- | crates/libanalysis/src/queries.rs | 21 |
1 files changed, 16 insertions, 5 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 | } | ||