move world-symbols to file_symbols
This commit is contained in:
parent
29d8bfb9c9
commit
a94530afb3
@ -3,7 +3,6 @@
|
|||||||
sync::Arc,
|
sync::Arc,
|
||||||
};
|
};
|
||||||
|
|
||||||
use rayon::prelude::*;
|
|
||||||
use salsa::{Database, ParallelDatabase};
|
use salsa::{Database, ParallelDatabase};
|
||||||
|
|
||||||
use hir::{
|
use hir::{
|
||||||
@ -25,7 +24,7 @@
|
|||||||
completion::{CompletionItem, completions},
|
completion::{CompletionItem, completions},
|
||||||
CrateId, db, Diagnostic, FileId, FilePosition, FileRange, FileSystemEdit,
|
CrateId, db, Diagnostic, FileId, FilePosition, FileRange, FileSystemEdit,
|
||||||
Query, ReferenceResolution, RootChange, SourceChange, SourceFileEdit,
|
Query, ReferenceResolution, RootChange, SourceChange, SourceFileEdit,
|
||||||
symbol_index::{LibrarySymbolsQuery, SymbolIndex, SymbolsDatabase, FileSymbol},
|
symbol_index::{LibrarySymbolsQuery, FileSymbol},
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Debug, Default)]
|
#[derive(Debug, Default)]
|
||||||
@ -149,39 +148,6 @@ pub fn file_syntax(&self, file_id: FileId) -> SourceFileNode {
|
|||||||
pub fn file_line_index(&self, file_id: FileId) -> Arc<LineIndex> {
|
pub fn file_line_index(&self, file_id: FileId) -> Arc<LineIndex> {
|
||||||
self.db.file_lines(file_id)
|
self.db.file_lines(file_id)
|
||||||
}
|
}
|
||||||
pub fn world_symbols(&self, query: Query) -> Cancelable<Vec<(FileId, FileSymbol)>> {
|
|
||||||
/// Need to wrap Snapshot to provide `Clone` impl for `map_with`
|
|
||||||
struct Snap(salsa::Snapshot<db::RootDatabase>);
|
|
||||||
impl Clone for Snap {
|
|
||||||
fn clone(&self) -> Snap {
|
|
||||||
Snap(self.0.snapshot())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let buf: Vec<Arc<SymbolIndex>> = if query.libs {
|
|
||||||
let snap = Snap(self.db.snapshot());
|
|
||||||
self.db
|
|
||||||
.library_roots()
|
|
||||||
.par_iter()
|
|
||||||
.map_with(snap, |db, &lib_id| db.0.library_symbols(lib_id))
|
|
||||||
.collect()
|
|
||||||
} else {
|
|
||||||
let mut files = Vec::new();
|
|
||||||
for &root in self.db.local_roots().iter() {
|
|
||||||
let sr = self.db.source_root(root);
|
|
||||||
files.extend(sr.files.values().map(|&it| it))
|
|
||||||
}
|
|
||||||
|
|
||||||
let snap = Snap(self.db.snapshot());
|
|
||||||
files
|
|
||||||
.par_iter()
|
|
||||||
.map_with(snap, |db, &file_id| db.0.file_symbols(file_id))
|
|
||||||
.filter_map(|it| it.ok())
|
|
||||||
.collect()
|
|
||||||
};
|
|
||||||
Ok(query.search(&buf))
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn module_path(&self, position: FilePosition) -> Cancelable<Option<String>> {
|
pub(crate) fn module_path(&self, position: FilePosition) -> Cancelable<Option<String>> {
|
||||||
let descr = match source_binder::module_from_position(&*self.db, position)? {
|
let descr = match source_binder::module_from_position(&*self.db, position)? {
|
||||||
None => return Ok(None),
|
None => return Ok(None),
|
||||||
@ -555,7 +521,7 @@ fn index_resolve(&self, name_ref: ast::NameRef) -> Cancelable<Vec<(FileId, FileS
|
|||||||
let mut query = Query::new(name.to_string());
|
let mut query = Query::new(name.to_string());
|
||||||
query.exact();
|
query.exact();
|
||||||
query.limit(4);
|
query.limit(4);
|
||||||
self.world_symbols(query)
|
crate::symbol_index::world_symbols(&*self.db, query)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -342,9 +342,7 @@ pub fn folding_ranges(&self, file_id: FileId) -> Vec<Fold> {
|
|||||||
ra_editor::folding_ranges(&file)
|
ra_editor::folding_ranges(&file)
|
||||||
}
|
}
|
||||||
pub fn symbol_search(&self, query: Query) -> Cancelable<Vec<NavigationTarget>> {
|
pub fn symbol_search(&self, query: Query) -> Cancelable<Vec<NavigationTarget>> {
|
||||||
let res = self
|
let res = symbol_index::world_symbols(&*self.imp.db, query)?
|
||||||
.imp
|
|
||||||
.world_symbols(query)?
|
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|(file_id, symbol)| NavigationTarget { file_id, symbol })
|
.map(|(file_id, symbol)| NavigationTarget { file_id, symbol })
|
||||||
.collect();
|
.collect();
|
||||||
|
@ -10,12 +10,13 @@
|
|||||||
SyntaxKind::{self, *},
|
SyntaxKind::{self, *},
|
||||||
ast::{self, NameOwner, DocCommentsOwner},
|
ast::{self, NameOwner, DocCommentsOwner},
|
||||||
};
|
};
|
||||||
use ra_db::{SyntaxDatabase, SourceRootId};
|
use ra_db::{SyntaxDatabase, SourceRootId, FilesDatabase};
|
||||||
|
use salsa::ParallelDatabase;
|
||||||
use rayon::prelude::*;
|
use rayon::prelude::*;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
Cancelable,
|
Cancelable, FileId, Query,
|
||||||
FileId, Query,
|
db::RootDatabase,
|
||||||
};
|
};
|
||||||
|
|
||||||
salsa::query_group! {
|
salsa::query_group! {
|
||||||
@ -36,6 +37,41 @@ fn file_symbols(db: &impl SyntaxDatabase, file_id: FileId) -> Cancelable<Arc<Sym
|
|||||||
Ok(Arc::new(SymbolIndex::for_file(file_id, syntax)))
|
Ok(Arc::new(SymbolIndex::for_file(file_id, syntax)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(crate) fn world_symbols(
|
||||||
|
db: &RootDatabase,
|
||||||
|
query: Query,
|
||||||
|
) -> Cancelable<Vec<(FileId, FileSymbol)>> {
|
||||||
|
/// Need to wrap Snapshot to provide `Clone` impl for `map_with`
|
||||||
|
struct Snap(salsa::Snapshot<RootDatabase>);
|
||||||
|
impl Clone for Snap {
|
||||||
|
fn clone(&self) -> Snap {
|
||||||
|
Snap(self.0.snapshot())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let buf: Vec<Arc<SymbolIndex>> = if query.libs {
|
||||||
|
let snap = Snap(db.snapshot());
|
||||||
|
db.library_roots()
|
||||||
|
.par_iter()
|
||||||
|
.map_with(snap, |db, &lib_id| db.0.library_symbols(lib_id))
|
||||||
|
.collect()
|
||||||
|
} else {
|
||||||
|
let mut files = Vec::new();
|
||||||
|
for &root in db.local_roots().iter() {
|
||||||
|
let sr = db.source_root(root);
|
||||||
|
files.extend(sr.files.values().map(|&it| it))
|
||||||
|
}
|
||||||
|
|
||||||
|
let snap = Snap(db.snapshot());
|
||||||
|
files
|
||||||
|
.par_iter()
|
||||||
|
.map_with(snap, |db, &file_id| db.0.file_symbols(file_id))
|
||||||
|
.filter_map(|it| it.ok())
|
||||||
|
.collect()
|
||||||
|
};
|
||||||
|
Ok(query.search(&buf))
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Default, Debug)]
|
#[derive(Default, Debug)]
|
||||||
pub(crate) struct SymbolIndex {
|
pub(crate) struct SymbolIndex {
|
||||||
symbols: Vec<(FileId, FileSymbol)>,
|
symbols: Vec<(FileId, FileSymbol)>,
|
||||||
|
Loading…
Reference in New Issue
Block a user