mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-30 13:51:31 +00:00
everysalsa
This commit is contained in:
parent
e69ff21207
commit
fcdf3a52b4
4 changed files with 40 additions and 23 deletions
|
@ -3,13 +3,11 @@ use libsyntax2::File;
|
||||||
use libeditor::LineIndex;
|
use libeditor::LineIndex;
|
||||||
use {
|
use {
|
||||||
FileId,
|
FileId,
|
||||||
db::{Query, QueryCtx, QueryRegistry, file_text},
|
db::{Query, QueryCtx, QueryRegistry},
|
||||||
|
symbol_index::SymbolIndex,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub(crate) fn register_queries(reg: &mut QueryRegistry) {
|
pub(crate) use db::{file_text, file_set};
|
||||||
reg.add(FILE_SYNTAX, "FILE_SYNTAX");
|
|
||||||
reg.add(FILE_LINES, "FILE_LINES");
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn file_syntax(ctx: QueryCtx, file_id: FileId) -> File {
|
pub(crate) fn file_syntax(ctx: QueryCtx, file_id: FileId) -> File {
|
||||||
(&*ctx.get(FILE_SYNTAX, file_id)).clone()
|
(&*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> {
|
pub(crate) fn file_lines(ctx: QueryCtx, file_id: FileId) -> Arc<LineIndex> {
|
||||||
ctx.get(FILE_LINES, file_id)
|
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| {
|
const FILE_SYNTAX: Query<FileId, File> = Query(16, |ctx, file_id: &FileId| {
|
||||||
let text = file_text(ctx, *file_id);
|
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);
|
let text = file_text(ctx, *file_id);
|
||||||
LineIndex::new(&*text)
|
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 module_tree(&self) -> Arc<ModuleTreeDescriptor>;
|
||||||
fn lines(&self, file_id: FileId) -> Arc<LineIndex>;
|
fn lines(&self, file_id: FileId) -> Arc<LineIndex>;
|
||||||
fn syntax(&self, file_id: FileId) -> File;
|
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)]
|
#[derive(Default, Debug)]
|
||||||
|
@ -74,20 +74,16 @@ impl SourceRoot for WritableSourceRoot {
|
||||||
fn syntax(&self, file_id: FileId) -> File {
|
fn syntax(&self, file_id: FileId) -> File {
|
||||||
self.db.make_query(|ctx| ::queries::file_syntax(ctx, file_id))
|
self.db.make_query(|ctx| ::queries::file_syntax(ctx, file_id))
|
||||||
}
|
}
|
||||||
fn symbols<'a>(&'a self, acc: &mut Vec<&'a SymbolIndex>) {
|
fn symbols<'a>(&'a self, acc: &mut Vec<Arc<SymbolIndex>>) {
|
||||||
// acc.extend(
|
self.db.make_query(|ctx| {
|
||||||
// self.file_map
|
let file_set = ::queries::file_set(ctx);
|
||||||
// .iter()
|
let syms = file_set.0.iter()
|
||||||
// .map(|(&file_id, data)| symbols(file_id, data))
|
.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)]
|
#[derive(Debug)]
|
||||||
struct FileData {
|
struct FileData {
|
||||||
text: String,
|
text: String,
|
||||||
|
@ -121,7 +117,7 @@ impl FileData {
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub(crate) struct ReadonlySourceRoot {
|
pub(crate) struct ReadonlySourceRoot {
|
||||||
symbol_index: SymbolIndex,
|
symbol_index: Arc<SymbolIndex>,
|
||||||
file_map: HashMap<FileId, FileData>,
|
file_map: HashMap<FileId, FileData>,
|
||||||
module_tree: Arc<ModuleTreeDescriptor>,
|
module_tree: Arc<ModuleTreeDescriptor>,
|
||||||
}
|
}
|
||||||
|
@ -149,7 +145,7 @@ impl ReadonlySourceRoot {
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
ReadonlySourceRoot {
|
ReadonlySourceRoot {
|
||||||
symbol_index,
|
symbol_index: Arc::new(symbol_index),
|
||||||
file_map,
|
file_map,
|
||||||
module_tree: Arc::new(module_tree),
|
module_tree: Arc::new(module_tree),
|
||||||
}
|
}
|
||||||
|
@ -176,7 +172,7 @@ impl SourceRoot for ReadonlySourceRoot {
|
||||||
fn syntax(&self, file_id: FileId) -> File {
|
fn syntax(&self, file_id: FileId) -> File {
|
||||||
self.data(file_id).syntax().clone()
|
self.data(file_id).syntax().clone()
|
||||||
}
|
}
|
||||||
fn symbols<'a>(&'a self, acc: &mut Vec<&'a SymbolIndex>) {
|
fn symbols(&self, acc: &mut Vec<Arc<SymbolIndex>>) {
|
||||||
acc.push(&self.symbol_index)
|
acc.push(Arc::clone(&self.symbol_index))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,7 @@
|
||||||
|
use std::{
|
||||||
|
sync::Arc,
|
||||||
|
hash::{Hash, Hasher},
|
||||||
|
};
|
||||||
use libeditor::{FileSymbol, file_symbols};
|
use libeditor::{FileSymbol, file_symbols};
|
||||||
use libsyntax2::{
|
use libsyntax2::{
|
||||||
File,
|
File,
|
||||||
|
@ -13,6 +17,12 @@ pub(crate) struct SymbolIndex {
|
||||||
map: fst::Map,
|
map: fst::Map,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Hash for SymbolIndex {
|
||||||
|
fn hash<H: Hasher>(&self, hasher: &mut H) {
|
||||||
|
self.symbols.hash(hasher)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl SymbolIndex {
|
impl SymbolIndex {
|
||||||
pub(crate) fn for_files(files: impl ParallelIterator<Item=(FileId, File)>) -> SymbolIndex {
|
pub(crate) fn for_files(files: impl ParallelIterator<Item=(FileId, File)>) -> SymbolIndex {
|
||||||
let mut symbols = files
|
let mut symbols = files
|
||||||
|
@ -43,7 +53,7 @@ impl SymbolIndex {
|
||||||
impl Query {
|
impl Query {
|
||||||
pub(crate) fn search(
|
pub(crate) fn search(
|
||||||
self,
|
self,
|
||||||
indices: &[&SymbolIndex],
|
indices: &[Arc<SymbolIndex>],
|
||||||
token: &JobToken,
|
token: &JobToken,
|
||||||
) -> Vec<(FileId, FileSymbol)> {
|
) -> Vec<(FileId, FileSymbol)> {
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,7 @@ pub struct StructureNode {
|
||||||
pub kind: SyntaxKind,
|
pub kind: SyntaxKind,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone, Hash)]
|
||||||
pub struct FileSymbol {
|
pub struct FileSymbol {
|
||||||
pub name: SmolStr,
|
pub name: SmolStr,
|
||||||
pub node_range: TextRange,
|
pub node_range: TextRange,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue