construct index from symbols directly
This commit is contained in:
parent
6c0bca5984
commit
ebd7c04faa
10
Cargo.lock
generated
10
Cargo.lock
generated
@ -680,6 +680,7 @@ dependencies = [
|
||||
"rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"salsa 0.9.0 (git+https://github.com/matklad/salsa.git?branch=transitive-untracked)",
|
||||
"test_utils 0.1.0",
|
||||
"unicase 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -1353,6 +1354,14 @@ dependencies = [
|
||||
"unic-common 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unicase"
|
||||
version = "2.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"version_check 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unicode-bidi"
|
||||
version = "0.3.4"
|
||||
@ -1616,6 +1625,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
"checksum unic-segment 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c9ca47cbb09fb5fcd066b5867d11dc528302fa465277882797d6a836e1ee6f9e"
|
||||
"checksum unic-ucd-segment 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "48f1a08ce0409a9e391b88d1930118eec48af12742fc538bcec55f775865776e"
|
||||
"checksum unic-ucd-version 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "cf1f5e6c6c53c2d0ece4a5964bc55fcff8602153063cb4fab20958ff32998ff6"
|
||||
"checksum unicase 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9d3218ea14b4edcaccfa0df0a64a3792a2c32cc706f1b336e48867f9d3147f90"
|
||||
"checksum unicode-bidi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "49f2bd0c6468a8230e1db229cff8029217cf623c767ea5d60bfbd42729ea54d5"
|
||||
"checksum unicode-normalization 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "6a0180bc61fc5a987082bfa111f4cc95c4caff7f9799f3e46df09163a937aa25"
|
||||
"checksum unicode-segmentation 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "aa6024fc12ddfd1c6dbc14a80fa2324d4568849869b779f6bd37e5e4c03344d1"
|
||||
|
@ -13,6 +13,7 @@ fst = "0.3.1"
|
||||
salsa = "0.9.0"
|
||||
rustc-hash = "1.0"
|
||||
parking_lot = "0.7.0"
|
||||
unicase = "2.2.0"
|
||||
|
||||
ra_syntax = { path = "../ra_syntax" }
|
||||
ra_editor = { path = "../ra_editor" }
|
||||
|
@ -20,6 +20,7 @@
|
||||
//! file in the current workspace, and run a query aginst the union of all
|
||||
//! thouse fsts.
|
||||
use std::{
|
||||
cmp::Ordering,
|
||||
hash::{Hash, Hasher},
|
||||
sync::Arc,
|
||||
};
|
||||
@ -111,6 +112,17 @@ fn hash<H: Hasher>(&self, hasher: &mut H) {
|
||||
}
|
||||
|
||||
impl SymbolIndex {
|
||||
fn new(mut symbols: Vec<FileSymbol>) -> SymbolIndex {
|
||||
fn cmp(s1: &FileSymbol, s2: &FileSymbol) -> Ordering {
|
||||
unicase::Ascii::new(s1.name.as_str()).cmp(&unicase::Ascii::new(s2.name.as_str()))
|
||||
}
|
||||
symbols.par_sort_by(cmp);
|
||||
symbols.dedup_by(|s1, s2| cmp(s1, s2) == Ordering::Equal);
|
||||
let names = symbols.iter().map(|it| it.name.as_str().to_lowercase());
|
||||
let map = fst::Map::from_iter(names.into_iter().zip(0u64..)).unwrap();
|
||||
SymbolIndex { symbols, map }
|
||||
}
|
||||
|
||||
pub(crate) fn len(&self) -> usize {
|
||||
self.symbols.len()
|
||||
}
|
||||
@ -118,28 +130,19 @@ pub(crate) fn len(&self) -> usize {
|
||||
pub(crate) fn for_files(
|
||||
files: impl ParallelIterator<Item = (FileId, SourceFileNode)>,
|
||||
) -> SymbolIndex {
|
||||
let mut symbols = files
|
||||
let symbols = files
|
||||
.flat_map(|(file_id, file)| {
|
||||
file.syntax()
|
||||
.descendants()
|
||||
.filter_map(to_symbol)
|
||||
.map(move |(name, ptr)| {
|
||||
(
|
||||
name.as_str().to_lowercase(),
|
||||
FileSymbol { name, ptr, file_id },
|
||||
)
|
||||
})
|
||||
.map(move |(name, ptr)| FileSymbol { name, ptr, file_id })
|
||||
.collect::<Vec<_>>()
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
symbols.par_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 map = fst::Map::from_iter(names.into_iter().zip(0u64..)).unwrap();
|
||||
SymbolIndex { symbols, map }
|
||||
SymbolIndex::new(symbols)
|
||||
}
|
||||
|
||||
pub(crate) fn for_file(file_id: FileId, file: SourceFileNode) -> SymbolIndex {
|
||||
fn for_file(file_id: FileId, file: SourceFileNode) -> SymbolIndex {
|
||||
SymbolIndex::for_files(rayon::iter::once((file_id, file)))
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user