diff options
Diffstat (limited to 'crates/ra_analysis/src')
-rw-r--r-- | crates/ra_analysis/src/symbol_index.rs | 29 |
1 files changed, 16 insertions, 13 deletions
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. |
22 | use std::{ | 22 | use 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 | ||
113 | impl SymbolIndex { | 114 | impl 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 | } |