aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-01-03 17:45:29 +0000
committerAleksey Kladov <[email protected]>2019-01-03 18:29:05 +0000
commitebd7c04faa27564ca3f03eed6d4a3636b7d3fc4c (patch)
tree016854c3312d4090bb9209523423ccf85ba3c888 /crates
parent6c0bca5984a6b66d306f9a413b0433c15d450500 (diff)
construct index from symbols directly
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_analysis/Cargo.toml1
-rw-r--r--crates/ra_analysis/src/symbol_index.rs29
2 files changed, 17 insertions, 13 deletions
diff --git a/crates/ra_analysis/Cargo.toml b/crates/ra_analysis/Cargo.toml
index c0174cdc5..7a4fdaed9 100644
--- a/crates/ra_analysis/Cargo.toml
+++ b/crates/ra_analysis/Cargo.toml
@@ -13,6 +13,7 @@ fst = "0.3.1"
13salsa = "0.9.0" 13salsa = "0.9.0"
14rustc-hash = "1.0" 14rustc-hash = "1.0"
15parking_lot = "0.7.0" 15parking_lot = "0.7.0"
16unicase = "2.2.0"
16 17
17ra_syntax = { path = "../ra_syntax" } 18ra_syntax = { path = "../ra_syntax" }
18ra_editor = { path = "../ra_editor" } 19ra_editor = { path = "../ra_editor" }
diff --git a/crates/ra_analysis/src/symbol_index.rs b/crates/ra_analysis/src/symbol_index.rs
index b355b14ed..55caae5c2 100644
--- a/crates/ra_analysis/src/symbol_index.rs
+++ b/crates/ra_analysis/src/symbol_index.rs
@@ -20,6 +20,7 @@
20//! file in the current workspace, and run a query aginst the union of all 20//! file in the current workspace, and run a query aginst the union of all
21//! thouse fsts. 21//! thouse fsts.
22use std::{ 22use std::{
23 cmp::Ordering,
23 hash::{Hash, Hasher}, 24 hash::{Hash, Hasher},
24 sync::Arc, 25 sync::Arc,
25}; 26};
@@ -111,6 +112,17 @@ impl Hash for SymbolIndex {
111} 112}
112 113
113impl SymbolIndex { 114impl SymbolIndex {
115 fn new(mut symbols: Vec<FileSymbol>) -> SymbolIndex {
116 fn cmp(s1: &FileSymbol, s2: &FileSymbol) -> Ordering {
117 unicase::Ascii::new(s1.name.as_str()).cmp(&unicase::Ascii::new(s2.name.as_str()))
118 }
119 symbols.par_sort_by(cmp);
120 symbols.dedup_by(|s1, s2| cmp(s1, s2) == Ordering::Equal);
121 let names = symbols.iter().map(|it| it.name.as_str().to_lowercase());
122 let map = fst::Map::from_iter(names.into_iter().zip(0u64..)).unwrap();
123 SymbolIndex { symbols, map }
124 }
125
114 pub(crate) fn len(&self) -> usize { 126 pub(crate) fn len(&self) -> usize {
115 self.symbols.len() 127 self.symbols.len()
116 } 128 }
@@ -118,28 +130,19 @@ impl SymbolIndex {
118 pub(crate) fn for_files( 130 pub(crate) fn for_files(
119 files: impl ParallelIterator<Item = (FileId, SourceFileNode)>, 131 files: impl ParallelIterator<Item = (FileId, SourceFileNode)>,
120 ) -> SymbolIndex { 132 ) -> SymbolIndex {
121 let mut symbols = files 133 let symbols = files
122 .flat_map(|(file_id, file)| { 134 .flat_map(|(file_id, file)| {
123 file.syntax() 135 file.syntax()
124 .descendants() 136 .descendants()
125 .filter_map(to_symbol) 137 .filter_map(to_symbol)
126 .map(move |(name, ptr)| { 138 .map(move |(name, ptr)| FileSymbol { name, ptr, file_id })
127 (
128 name.as_str().to_lowercase(),
129 FileSymbol { name, ptr, file_id },
130 )
131 })
132 .collect::<Vec<_>>() 139 .collect::<Vec<_>>()
133 }) 140 })
134 .collect::<Vec<_>>(); 141 .collect::<Vec<_>>();
135 symbols.par_sort_by(|s1, s2| s1.0.cmp(&s2.0)); 142 SymbolIndex::new(symbols)
136 symbols.dedup_by(|s1, s2| s1.0 == s2.0);
137 let (names, symbols): (Vec<String>, Vec<FileSymbol>) = symbols.into_iter().unzip();
138 let map = fst::Map::from_iter(names.into_iter().zip(0u64..)).unwrap();
139 SymbolIndex { symbols, map }
140 } 143 }
141 144
142 pub(crate) fn for_file(file_id: FileId, file: SourceFileNode) -> SymbolIndex { 145 fn for_file(file_id: FileId, file: SourceFileNode) -> SymbolIndex {
143 SymbolIndex::for_files(rayon::iter::once((file_id, file))) 146 SymbolIndex::for_files(rayon::iter::once((file_id, file)))
144 } 147 }
145} 148}