everysalsa
This commit is contained in:
parent
e69ff21207
commit
fcdf3a52b4
@ -3,13 +3,11 @@ use libsyntax2::File;
|
||||
use libeditor::LineIndex;
|
||||
use {
|
||||
FileId,
|
||||
db::{Query, QueryCtx, QueryRegistry, file_text},
|
||||
db::{Query, QueryCtx, QueryRegistry},
|
||||
symbol_index::SymbolIndex,
|
||||
};
|
||||
|
||||
pub(crate) fn register_queries(reg: &mut QueryRegistry) {
|
||||
reg.add(FILE_SYNTAX, "FILE_SYNTAX");
|
||||
reg.add(FILE_LINES, "FILE_LINES");
|
||||
}
|
||||
pub(crate) use db::{file_text, file_set};
|
||||
|
||||
pub(crate) fn file_syntax(ctx: QueryCtx, file_id: FileId) -> File {
|
||||
(&*ctx.get(FILE_SYNTAX, file_id)).clone()
|
||||
@ -17,6 +15,9 @@ pub(crate) fn file_syntax(ctx: QueryCtx, file_id: FileId) -> File {
|
||||
pub(crate) fn file_lines(ctx: QueryCtx, file_id: FileId) -> Arc<LineIndex> {
|
||||
ctx.get(FILE_LINES, file_id)
|
||||
}
|
||||
pub(crate) fn file_symbols(ctx: QueryCtx, file_id: FileId) -> Arc<SymbolIndex> {
|
||||
ctx.get(FILE_SYMBOLS, file_id)
|
||||
}
|
||||
|
||||
const FILE_SYNTAX: Query<FileId, File> = Query(16, |ctx, file_id: &FileId| {
|
||||
let text = file_text(ctx, *file_id);
|
||||
@ -26,3 +27,13 @@ const FILE_LINES: Query<FileId, LineIndex> = Query(17, |ctx, file_id: &FileId| {
|
||||
let text = file_text(ctx, *file_id);
|
||||
LineIndex::new(&*text)
|
||||
});
|
||||
const FILE_SYMBOLS: Query<FileId, SymbolIndex> = Query(18, |ctx, file_id: &FileId| {
|
||||
let syntax = file_syntax(ctx, *file_id);
|
||||
SymbolIndex::for_file(*file_id, syntax)
|
||||
});
|
||||
|
||||
pub(crate) fn register_queries(reg: &mut QueryRegistry) {
|
||||
reg.add(FILE_SYNTAX, "FILE_SYNTAX");
|
||||
reg.add(FILE_LINES, "FILE_LINES");
|
||||
reg.add(FILE_SYMBOLS, "FILE_SYMBOLS");
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ pub(crate) trait SourceRoot {
|
||||
fn module_tree(&self) -> Arc<ModuleTreeDescriptor>;
|
||||
fn lines(&self, file_id: FileId) -> Arc<LineIndex>;
|
||||
fn syntax(&self, file_id: FileId) -> File;
|
||||
fn symbols<'a>(&'a self, acc: &mut Vec<&'a SymbolIndex>);
|
||||
fn symbols(&self, acc: &mut Vec<Arc<SymbolIndex>>);
|
||||
}
|
||||
|
||||
#[derive(Default, Debug)]
|
||||
@ -74,20 +74,16 @@ impl SourceRoot for WritableSourceRoot {
|
||||
fn syntax(&self, file_id: FileId) -> File {
|
||||
self.db.make_query(|ctx| ::queries::file_syntax(ctx, file_id))
|
||||
}
|
||||
fn symbols<'a>(&'a self, acc: &mut Vec<&'a SymbolIndex>) {
|
||||
// acc.extend(
|
||||
// self.file_map
|
||||
// .iter()
|
||||
// .map(|(&file_id, data)| symbols(file_id, data))
|
||||
// )
|
||||
fn symbols<'a>(&'a self, acc: &mut Vec<Arc<SymbolIndex>>) {
|
||||
self.db.make_query(|ctx| {
|
||||
let file_set = ::queries::file_set(ctx);
|
||||
let syms = file_set.0.iter()
|
||||
.map(|file_id| ::queries::file_symbols(ctx, *file_id));
|
||||
acc.extend(syms);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
fn symbols(file_id: FileId, (data, symbols): &(FileData, OnceCell<SymbolIndex>)) -> &SymbolIndex {
|
||||
let syntax = data.syntax_transient();
|
||||
symbols.get_or_init(|| SymbolIndex::for_file(file_id, syntax))
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
struct FileData {
|
||||
text: String,
|
||||
@ -121,7 +117,7 @@ impl FileData {
|
||||
|
||||
#[derive(Debug)]
|
||||
pub(crate) struct ReadonlySourceRoot {
|
||||
symbol_index: SymbolIndex,
|
||||
symbol_index: Arc<SymbolIndex>,
|
||||
file_map: HashMap<FileId, FileData>,
|
||||
module_tree: Arc<ModuleTreeDescriptor>,
|
||||
}
|
||||
@ -149,7 +145,7 @@ impl ReadonlySourceRoot {
|
||||
.collect();
|
||||
|
||||
ReadonlySourceRoot {
|
||||
symbol_index,
|
||||
symbol_index: Arc::new(symbol_index),
|
||||
file_map,
|
||||
module_tree: Arc::new(module_tree),
|
||||
}
|
||||
@ -176,7 +172,7 @@ impl SourceRoot for ReadonlySourceRoot {
|
||||
fn syntax(&self, file_id: FileId) -> File {
|
||||
self.data(file_id).syntax().clone()
|
||||
}
|
||||
fn symbols<'a>(&'a self, acc: &mut Vec<&'a SymbolIndex>) {
|
||||
acc.push(&self.symbol_index)
|
||||
fn symbols(&self, acc: &mut Vec<Arc<SymbolIndex>>) {
|
||||
acc.push(Arc::clone(&self.symbol_index))
|
||||
}
|
||||
}
|
||||
|
@ -1,3 +1,7 @@
|
||||
use std::{
|
||||
sync::Arc,
|
||||
hash::{Hash, Hasher},
|
||||
};
|
||||
use libeditor::{FileSymbol, file_symbols};
|
||||
use libsyntax2::{
|
||||
File,
|
||||
@ -13,6 +17,12 @@ pub(crate) struct SymbolIndex {
|
||||
map: fst::Map,
|
||||
}
|
||||
|
||||
impl Hash for SymbolIndex {
|
||||
fn hash<H: Hasher>(&self, hasher: &mut H) {
|
||||
self.symbols.hash(hasher)
|
||||
}
|
||||
}
|
||||
|
||||
impl SymbolIndex {
|
||||
pub(crate) fn for_files(files: impl ParallelIterator<Item=(FileId, File)>) -> SymbolIndex {
|
||||
let mut symbols = files
|
||||
@ -43,7 +53,7 @@ impl SymbolIndex {
|
||||
impl Query {
|
||||
pub(crate) fn search(
|
||||
self,
|
||||
indices: &[&SymbolIndex],
|
||||
indices: &[Arc<SymbolIndex>],
|
||||
token: &JobToken,
|
||||
) -> Vec<(FileId, FileSymbol)> {
|
||||
|
||||
|
@ -17,7 +17,7 @@ pub struct StructureNode {
|
||||
pub kind: SyntaxKind,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
#[derive(Debug, Clone, Hash)]
|
||||
pub struct FileSymbol {
|
||||
pub name: SmolStr,
|
||||
pub node_range: TextRange,
|
||||
|
Loading…
x
Reference in New Issue
Block a user