aboutsummaryrefslogtreecommitdiff
path: root/crates/libanalysis/src/db/mod.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/libanalysis/src/db/mod.rs')
-rw-r--r--crates/libanalysis/src/db/mod.rs12
1 files changed, 11 insertions, 1 deletions
diff --git a/crates/libanalysis/src/db/mod.rs b/crates/libanalysis/src/db/mod.rs
index a775b5f75..1111a4f87 100644
--- a/crates/libanalysis/src/db/mod.rs
+++ b/crates/libanalysis/src/db/mod.rs
@@ -68,22 +68,32 @@ pub(crate) fn file_set(ctx: QueryCtx) -> Arc<(Vec<FileId>, FileResolverImp)> {
68pub(crate) use self::queries::file_syntax; 68pub(crate) use self::queries::file_syntax;
69 69
70mod queries { 70mod queries {
71 use std::sync::Arc;
71 use libsyntax2::File; 72 use libsyntax2::File;
73 use libeditor::LineIndex;
72 use {FileId}; 74 use {FileId};
73 use super::{Query, QueryCtx, QueryRegistry, file_text}; 75 use super::{Query, QueryCtx, QueryRegistry, file_text};
74 76
75 pub(crate) fn register_queries(reg: &mut QueryRegistry) { 77 pub(crate) fn register_queries(reg: &mut QueryRegistry) {
76 reg.add(FILE_SYNTAX, "FILE_SYNTAX") 78 reg.add(FILE_SYNTAX, "FILE_SYNTAX");
79 reg.add(FILE_LINES, "FILE_LINES");
77 } 80 }
78 81
79 pub(crate) fn file_syntax(ctx: QueryCtx, file_id: FileId) -> File { 82 pub(crate) fn file_syntax(ctx: QueryCtx, file_id: FileId) -> File {
80 (&*ctx.get(FILE_SYNTAX, file_id)).clone() 83 (&*ctx.get(FILE_SYNTAX, file_id)).clone()
81 } 84 }
85 pub(crate) fn file_lines(ctx: QueryCtx, file_id: FileId) -> Arc<LineIndex> {
86 ctx.get(FILE_LINES, file_id)
87 }
82 88
83 pub(super) const FILE_SYNTAX: Query<FileId, File> = Query(16, |ctx, file_id: &FileId| { 89 pub(super) const FILE_SYNTAX: Query<FileId, File> = Query(16, |ctx, file_id: &FileId| {
84 let text = file_text(ctx, *file_id); 90 let text = file_text(ctx, *file_id);
85 File::parse(&*text) 91 File::parse(&*text)
86 }); 92 });
93 pub(super) const FILE_LINES: Query<FileId, LineIndex> = Query(17, |ctx, file_id: &FileId| {
94 let text = file_text(ctx, *file_id);
95 LineIndex::new(&*text)
96 });
87} 97}
88 98
89impl QueryRegistry { 99impl QueryRegistry {