introduce SymbolsDatabase
This commit is contained in:
parent
201aa7ea2a
commit
65c064b2a9
@ -7,7 +7,7 @@ use salsa::{self, Database};
|
||||
|
||||
use crate::{
|
||||
hir,
|
||||
symbol_index::SymbolIndex,
|
||||
symbol_index,
|
||||
loc2id::{IdMaps},
|
||||
Cancelable, Canceled, FileId,
|
||||
};
|
||||
@ -114,23 +114,25 @@ salsa::database_storage! {
|
||||
fn file_source_root() for crate::input::FileSourceRootQuery;
|
||||
fn source_root() for crate::input::SourceRootQuery;
|
||||
fn libraries() for crate::input::LibrariesQuery;
|
||||
fn library_symbols() for crate::input::LibrarySymbolsQuery;
|
||||
fn crate_graph() for crate::input::CrateGraphQuery;
|
||||
}
|
||||
impl SyntaxDatabase {
|
||||
fn file_syntax() for FileSyntaxQuery;
|
||||
fn file_lines() for FileLinesQuery;
|
||||
fn file_symbols() for FileSymbolsQuery;
|
||||
}
|
||||
impl symbol_index::SymbolsDatabase {
|
||||
fn file_symbols() for symbol_index::FileSymbolsQuery;
|
||||
fn library_symbols() for symbol_index::LibrarySymbolsQuery;
|
||||
}
|
||||
impl hir::db::HirDatabase {
|
||||
fn module_tree() for hir::db::ModuleTreeQuery;
|
||||
fn fn_scopes() for hir::db::FnScopesQuery;
|
||||
fn _file_items() for hir::db::SourceFileItemsQuery;
|
||||
fn _file_item() for hir::db::FileItemQuery;
|
||||
fn _input_module_items() for hir::db::InputModuleItemsQuery;
|
||||
fn _item_map() for hir::db::ItemMapQuery;
|
||||
fn _fn_syntax() for hir::db::FnSyntaxQuery;
|
||||
fn _submodules() for hir::db::SubmodulesQuery;
|
||||
fn file_items() for hir::db::SourceFileItemsQuery;
|
||||
fn file_item() for hir::db::FileItemQuery;
|
||||
fn input_module_items() for hir::db::InputModuleItemsQuery;
|
||||
fn item_map() for hir::db::ItemMapQuery;
|
||||
fn fn_syntax() for hir::db::FnSyntaxQuery;
|
||||
fn submodules() for hir::db::SubmodulesQuery;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -143,9 +145,6 @@ salsa::query_group! {
|
||||
fn file_lines(file_id: FileId) -> Arc<LineIndex> {
|
||||
type FileLinesQuery;
|
||||
}
|
||||
fn file_symbols(file_id: FileId) -> Cancelable<Arc<SymbolIndex>> {
|
||||
type FileSymbolsQuery;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -157,8 +156,3 @@ fn file_lines(db: &impl SyntaxDatabase, file_id: FileId) -> Arc<LineIndex> {
|
||||
let text = db.file_text(file_id);
|
||||
Arc::new(LineIndex::new(&*text))
|
||||
}
|
||||
fn file_symbols(db: &impl SyntaxDatabase, file_id: FileId) -> Cancelable<Arc<SymbolIndex>> {
|
||||
db.check_canceled()?;
|
||||
let syntax = db.file_syntax(file_id);
|
||||
Ok(Arc::new(SymbolIndex::for_file(file_id, syntax)))
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ use crate::{
|
||||
Problem,
|
||||
},
|
||||
input::{FilesDatabase, SourceRoot, SourceRootId, WORKSPACE},
|
||||
symbol_index::SymbolIndex,
|
||||
symbol_index::{SymbolIndex, SymbolsDatabase},
|
||||
AnalysisChange, Cancelable, CrateGraph, CrateId, Diagnostic, FileId, FileResolver,
|
||||
FileSystemEdit, FilePosition, Query, SourceChange, SourceFileNodeEdit,
|
||||
};
|
||||
@ -161,7 +161,7 @@ impl AnalysisHostImpl {
|
||||
.query_mut(crate::input::SourceRootQuery)
|
||||
.set(source_root_id, Arc::new(source_root));
|
||||
self.db
|
||||
.query_mut(crate::input::LibrarySymbolsQuery)
|
||||
.query_mut(crate::symbol_index::LibrarySymbolsQuery)
|
||||
.set(source_root_id, Arc::new(library.symbol_index));
|
||||
}
|
||||
self.db
|
||||
|
@ -5,7 +5,7 @@ use rustc_hash::FxHashMap;
|
||||
use rustc_hash::FxHashSet;
|
||||
use salsa;
|
||||
|
||||
use crate::{symbol_index::SymbolIndex, FileResolverImp};
|
||||
use crate::FileResolverImp;
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||
pub struct FileId(pub u32);
|
||||
@ -56,10 +56,6 @@ salsa::query_group! {
|
||||
type LibrariesQuery;
|
||||
storage input;
|
||||
}
|
||||
fn library_symbols(id: SourceRootId) -> Arc<SymbolIndex> {
|
||||
type LibrarySymbolsQuery;
|
||||
storage input;
|
||||
}
|
||||
fn crate_graph() -> Arc<CrateGraph> {
|
||||
type CrateGraphQuery;
|
||||
storage input;
|
||||
|
@ -4,14 +4,37 @@ use std::{
|
||||
};
|
||||
|
||||
use fst::{self, Streamer};
|
||||
use ra_editor::{file_symbols, FileSymbol};
|
||||
use ra_editor::{self, FileSymbol};
|
||||
use ra_syntax::{
|
||||
SourceFileNode,
|
||||
SyntaxKind::{self, *},
|
||||
};
|
||||
use rayon::prelude::*;
|
||||
|
||||
use crate::{FileId, Query};
|
||||
use crate::{
|
||||
Cancelable,
|
||||
FileId, Query,
|
||||
db::SyntaxDatabase,
|
||||
input::SourceRootId,
|
||||
};
|
||||
|
||||
salsa::query_group! {
|
||||
pub(crate) trait SymbolsDatabase: SyntaxDatabase {
|
||||
fn file_symbols(file_id: FileId) -> Cancelable<Arc<SymbolIndex>> {
|
||||
type FileSymbolsQuery;
|
||||
}
|
||||
fn library_symbols(id: SourceRootId) -> Arc<SymbolIndex> {
|
||||
type LibrarySymbolsQuery;
|
||||
storage input;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn file_symbols(db: &impl SyntaxDatabase, file_id: FileId) -> Cancelable<Arc<SymbolIndex>> {
|
||||
db.check_canceled()?;
|
||||
let syntax = db.file_syntax(file_id);
|
||||
Ok(Arc::new(SymbolIndex::for_file(file_id, syntax)))
|
||||
}
|
||||
|
||||
#[derive(Default, Debug)]
|
||||
pub(crate) struct SymbolIndex {
|
||||
@ -39,7 +62,7 @@ impl SymbolIndex {
|
||||
) -> SymbolIndex {
|
||||
let mut symbols = files
|
||||
.flat_map(|(file_id, file)| {
|
||||
file_symbols(&file)
|
||||
ra_editor::file_symbols(&file)
|
||||
.into_iter()
|
||||
.map(move |symbol| (symbol.name.as_str().to_lowercase(), (file_id, symbol)))
|
||||
.collect::<Vec<_>>()
|
||||
|
Loading…
x
Reference in New Issue
Block a user