mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-25 12:33:33 +00:00
store file id inside symbol
This commit is contained in:
parent
a5e319ec7e
commit
83e2ab434c
2 changed files with 27 additions and 14 deletions
|
@ -59,18 +59,18 @@ impl SourceRoot {
|
|||
}
|
||||
}
|
||||
}
|
||||
pub(crate) fn symbols(&self) -> Vec<(FileId, &FileSymbols)> {
|
||||
pub(crate) fn symbols(&self) -> Vec<&FileSymbols> {
|
||||
self.file_map
|
||||
.iter()
|
||||
.map(|(&file_id, data)| (file_id, symbols(data)))
|
||||
.map(|(&file_id, data)| symbols(file_id, data))
|
||||
.collect()
|
||||
}
|
||||
pub fn reindex(&self) {
|
||||
let now = Instant::now();
|
||||
self.file_map
|
||||
.par_iter()
|
||||
.for_each(|(_, data)| {
|
||||
symbols(data);
|
||||
.for_each(|(&file_id, data)| {
|
||||
symbols(file_id, data);
|
||||
});
|
||||
info!("parallel indexing took {:?}", now.elapsed());
|
||||
|
||||
|
@ -83,9 +83,9 @@ impl SourceRoot {
|
|||
}
|
||||
}
|
||||
|
||||
fn symbols((data, symbols): &(FileData, OnceCell<FileSymbols>)) -> &FileSymbols {
|
||||
fn symbols(file_id: FileId, (data, symbols): &(FileData, OnceCell<FileSymbols>)) -> &FileSymbols {
|
||||
let syntax = data.syntax_transient();
|
||||
symbols.get_or_init(|| FileSymbols::new(&syntax))
|
||||
symbols.get_or_init(|| FileSymbols::new(file_id, &syntax))
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
|
@ -108,3 +108,14 @@ impl FileData {
|
|||
.unwrap_or_else(|| File::parse(&self.text))
|
||||
}
|
||||
}
|
||||
|
||||
// #[derive(Clone, Default, Debug)]
|
||||
// pub(crate) struct ReadonlySourceRoot {
|
||||
// data: Arc<ReadonlySourceRoot>
|
||||
// }
|
||||
|
||||
// #[derive(Clone, Default, Debug)]
|
||||
// pub(crate) struct ReadonlySourceRootInner {
|
||||
// file_map: HashMap<FileId, FileData>,
|
||||
// module_map: ModuleMap,
|
||||
// }
|
||||
|
|
|
@ -8,12 +8,12 @@ use {Query, FileId, JobToken};
|
|||
|
||||
#[derive(Debug)]
|
||||
pub(crate) struct FileSymbols {
|
||||
symbols: Vec<FileSymbol>,
|
||||
symbols: Vec<(FileId, FileSymbol)>,
|
||||
map: fst::Map,
|
||||
}
|
||||
|
||||
impl FileSymbols {
|
||||
pub(crate) fn new(file: &File) -> FileSymbols {
|
||||
pub(crate) fn new(file_id: FileId, file: &File) -> FileSymbols {
|
||||
let mut symbols = file_symbols(file)
|
||||
.into_iter()
|
||||
.map(|s| (s.name.as_str().to_lowercase(), s))
|
||||
|
@ -21,8 +21,10 @@ impl FileSymbols {
|
|||
|
||||
symbols.sort_by(|s1, s2| s1.0.cmp(&s2.0));
|
||||
symbols.dedup_by(|s1, s2| s1.0 == s2.0);
|
||||
let (names, symbols): (Vec<String>, Vec<FileSymbol>) =
|
||||
symbols.into_iter().unzip();
|
||||
let (names, symbols): (Vec<String>, Vec<(FileId, FileSymbol)>) =
|
||||
symbols.into_iter()
|
||||
.map(|(name, symbol)| (name, (file_id, symbol)))
|
||||
.unzip();
|
||||
|
||||
let map = fst::Map::from_iter(
|
||||
names.into_iter().zip(0u64..)
|
||||
|
@ -34,12 +36,12 @@ impl FileSymbols {
|
|||
impl Query {
|
||||
pub(crate) fn search(
|
||||
mut self,
|
||||
indices: &[(FileId, &FileSymbols)],
|
||||
indices: &[&FileSymbols],
|
||||
token: &JobToken,
|
||||
) -> Vec<(FileId, FileSymbol)> {
|
||||
|
||||
let mut op = fst::map::OpBuilder::new();
|
||||
for (_, file_symbols) in indices.iter() {
|
||||
for file_symbols in indices.iter() {
|
||||
let automaton = fst::automaton::Subsequence::new(&self.lowercased);
|
||||
op = op.add(file_symbols.map.search(automaton))
|
||||
}
|
||||
|
@ -50,10 +52,10 @@ impl Query {
|
|||
break;
|
||||
}
|
||||
for indexed_value in indexed_values {
|
||||
let (file_id, file_symbols) = &indices[indexed_value.index];
|
||||
let file_symbols = &indices[indexed_value.index];
|
||||
let idx = indexed_value.value as usize;
|
||||
|
||||
let symbol = &file_symbols.symbols[idx];
|
||||
let (file_id, symbol) = &file_symbols.symbols[idx];
|
||||
if self.only_types && !is_type(symbol.kind) {
|
||||
continue;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue