mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 21:05:02 +00:00
introduce SymbolsDatabase
This commit is contained in:
parent
201aa7ea2a
commit
65c064b2a9
4 changed files with 40 additions and 27 deletions
|
@ -7,7 +7,7 @@ use salsa::{self, Database};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
hir,
|
hir,
|
||||||
symbol_index::SymbolIndex,
|
symbol_index,
|
||||||
loc2id::{IdMaps},
|
loc2id::{IdMaps},
|
||||||
Cancelable, Canceled, FileId,
|
Cancelable, Canceled, FileId,
|
||||||
};
|
};
|
||||||
|
@ -114,23 +114,25 @@ salsa::database_storage! {
|
||||||
fn file_source_root() for crate::input::FileSourceRootQuery;
|
fn file_source_root() for crate::input::FileSourceRootQuery;
|
||||||
fn source_root() for crate::input::SourceRootQuery;
|
fn source_root() for crate::input::SourceRootQuery;
|
||||||
fn libraries() for crate::input::LibrariesQuery;
|
fn libraries() for crate::input::LibrariesQuery;
|
||||||
fn library_symbols() for crate::input::LibrarySymbolsQuery;
|
|
||||||
fn crate_graph() for crate::input::CrateGraphQuery;
|
fn crate_graph() for crate::input::CrateGraphQuery;
|
||||||
}
|
}
|
||||||
impl SyntaxDatabase {
|
impl SyntaxDatabase {
|
||||||
fn file_syntax() for FileSyntaxQuery;
|
fn file_syntax() for FileSyntaxQuery;
|
||||||
fn file_lines() for FileLinesQuery;
|
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 {
|
impl hir::db::HirDatabase {
|
||||||
fn module_tree() for hir::db::ModuleTreeQuery;
|
fn module_tree() for hir::db::ModuleTreeQuery;
|
||||||
fn fn_scopes() for hir::db::FnScopesQuery;
|
fn fn_scopes() for hir::db::FnScopesQuery;
|
||||||
fn _file_items() for hir::db::SourceFileItemsQuery;
|
fn file_items() for hir::db::SourceFileItemsQuery;
|
||||||
fn _file_item() for hir::db::FileItemQuery;
|
fn file_item() for hir::db::FileItemQuery;
|
||||||
fn _input_module_items() for hir::db::InputModuleItemsQuery;
|
fn input_module_items() for hir::db::InputModuleItemsQuery;
|
||||||
fn _item_map() for hir::db::ItemMapQuery;
|
fn item_map() for hir::db::ItemMapQuery;
|
||||||
fn _fn_syntax() for hir::db::FnSyntaxQuery;
|
fn fn_syntax() for hir::db::FnSyntaxQuery;
|
||||||
fn _submodules() for hir::db::SubmodulesQuery;
|
fn submodules() for hir::db::SubmodulesQuery;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -143,9 +145,6 @@ salsa::query_group! {
|
||||||
fn file_lines(file_id: FileId) -> Arc<LineIndex> {
|
fn file_lines(file_id: FileId) -> Arc<LineIndex> {
|
||||||
type FileLinesQuery;
|
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);
|
let text = db.file_text(file_id);
|
||||||
Arc::new(LineIndex::new(&*text))
|
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,
|
Problem,
|
||||||
},
|
},
|
||||||
input::{FilesDatabase, SourceRoot, SourceRootId, WORKSPACE},
|
input::{FilesDatabase, SourceRoot, SourceRootId, WORKSPACE},
|
||||||
symbol_index::SymbolIndex,
|
symbol_index::{SymbolIndex, SymbolsDatabase},
|
||||||
AnalysisChange, Cancelable, CrateGraph, CrateId, Diagnostic, FileId, FileResolver,
|
AnalysisChange, Cancelable, CrateGraph, CrateId, Diagnostic, FileId, FileResolver,
|
||||||
FileSystemEdit, FilePosition, Query, SourceChange, SourceFileNodeEdit,
|
FileSystemEdit, FilePosition, Query, SourceChange, SourceFileNodeEdit,
|
||||||
};
|
};
|
||||||
|
@ -161,7 +161,7 @@ impl AnalysisHostImpl {
|
||||||
.query_mut(crate::input::SourceRootQuery)
|
.query_mut(crate::input::SourceRootQuery)
|
||||||
.set(source_root_id, Arc::new(source_root));
|
.set(source_root_id, Arc::new(source_root));
|
||||||
self.db
|
self.db
|
||||||
.query_mut(crate::input::LibrarySymbolsQuery)
|
.query_mut(crate::symbol_index::LibrarySymbolsQuery)
|
||||||
.set(source_root_id, Arc::new(library.symbol_index));
|
.set(source_root_id, Arc::new(library.symbol_index));
|
||||||
}
|
}
|
||||||
self.db
|
self.db
|
||||||
|
|
|
@ -5,7 +5,7 @@ use rustc_hash::FxHashMap;
|
||||||
use rustc_hash::FxHashSet;
|
use rustc_hash::FxHashSet;
|
||||||
use salsa;
|
use salsa;
|
||||||
|
|
||||||
use crate::{symbol_index::SymbolIndex, FileResolverImp};
|
use crate::FileResolverImp;
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||||
pub struct FileId(pub u32);
|
pub struct FileId(pub u32);
|
||||||
|
@ -56,10 +56,6 @@ salsa::query_group! {
|
||||||
type LibrariesQuery;
|
type LibrariesQuery;
|
||||||
storage input;
|
storage input;
|
||||||
}
|
}
|
||||||
fn library_symbols(id: SourceRootId) -> Arc<SymbolIndex> {
|
|
||||||
type LibrarySymbolsQuery;
|
|
||||||
storage input;
|
|
||||||
}
|
|
||||||
fn crate_graph() -> Arc<CrateGraph> {
|
fn crate_graph() -> Arc<CrateGraph> {
|
||||||
type CrateGraphQuery;
|
type CrateGraphQuery;
|
||||||
storage input;
|
storage input;
|
||||||
|
|
|
@ -4,14 +4,37 @@ use std::{
|
||||||
};
|
};
|
||||||
|
|
||||||
use fst::{self, Streamer};
|
use fst::{self, Streamer};
|
||||||
use ra_editor::{file_symbols, FileSymbol};
|
use ra_editor::{self, FileSymbol};
|
||||||
use ra_syntax::{
|
use ra_syntax::{
|
||||||
SourceFileNode,
|
SourceFileNode,
|
||||||
SyntaxKind::{self, *},
|
SyntaxKind::{self, *},
|
||||||
};
|
};
|
||||||
use rayon::prelude::*;
|
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)]
|
#[derive(Default, Debug)]
|
||||||
pub(crate) struct SymbolIndex {
|
pub(crate) struct SymbolIndex {
|
||||||
|
@ -39,7 +62,7 @@ impl SymbolIndex {
|
||||||
) -> SymbolIndex {
|
) -> SymbolIndex {
|
||||||
let mut symbols = files
|
let mut symbols = files
|
||||||
.flat_map(|(file_id, file)| {
|
.flat_map(|(file_id, file)| {
|
||||||
file_symbols(&file)
|
ra_editor::file_symbols(&file)
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(move |symbol| (symbol.name.as_str().to_lowercase(), (file_id, symbol)))
|
.map(move |symbol| (symbol.name.as_str().to_lowercase(), (file_id, symbol)))
|
||||||
.collect::<Vec<_>>()
|
.collect::<Vec<_>>()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue