diff options
Diffstat (limited to 'crates/ra_analysis/src/symbol_index.rs')
-rw-r--r-- | crates/ra_analysis/src/symbol_index.rs | 36 |
1 files changed, 18 insertions, 18 deletions
diff --git a/crates/ra_analysis/src/symbol_index.rs b/crates/ra_analysis/src/symbol_index.rs index 10d8e8059..b355b14ed 100644 --- a/crates/ra_analysis/src/symbol_index.rs +++ b/crates/ra_analysis/src/symbol_index.rs | |||
@@ -58,10 +58,7 @@ fn file_symbols(db: &impl SyntaxDatabase, file_id: FileId) -> Cancelable<Arc<Sym | |||
58 | Ok(Arc::new(SymbolIndex::for_file(file_id, syntax))) | 58 | Ok(Arc::new(SymbolIndex::for_file(file_id, syntax))) |
59 | } | 59 | } |
60 | 60 | ||
61 | pub(crate) fn world_symbols( | 61 | pub(crate) fn world_symbols(db: &RootDatabase, query: Query) -> Cancelable<Vec<FileSymbol>> { |
62 | db: &RootDatabase, | ||
63 | query: Query, | ||
64 | ) -> Cancelable<Vec<(FileId, FileSymbol)>> { | ||
65 | /// Need to wrap Snapshot to provide `Clone` impl for `map_with` | 62 | /// Need to wrap Snapshot to provide `Clone` impl for `map_with` |
66 | struct Snap(salsa::Snapshot<RootDatabase>); | 63 | struct Snap(salsa::Snapshot<RootDatabase>); |
67 | impl Clone for Snap { | 64 | impl Clone for Snap { |
@@ -95,7 +92,7 @@ pub(crate) fn world_symbols( | |||
95 | 92 | ||
96 | #[derive(Default, Debug)] | 93 | #[derive(Default, Debug)] |
97 | pub(crate) struct SymbolIndex { | 94 | pub(crate) struct SymbolIndex { |
98 | symbols: Vec<(FileId, FileSymbol)>, | 95 | symbols: Vec<FileSymbol>, |
99 | map: fst::Map, | 96 | map: fst::Map, |
100 | } | 97 | } |
101 | 98 | ||
@@ -126,14 +123,18 @@ impl SymbolIndex { | |||
126 | file.syntax() | 123 | file.syntax() |
127 | .descendants() | 124 | .descendants() |
128 | .filter_map(to_symbol) | 125 | .filter_map(to_symbol) |
129 | .map(move |symbol| (symbol.name.as_str().to_lowercase(), (file_id, symbol))) | 126 | .map(move |(name, ptr)| { |
127 | ( | ||
128 | name.as_str().to_lowercase(), | ||
129 | FileSymbol { name, ptr, file_id }, | ||
130 | ) | ||
131 | }) | ||
130 | .collect::<Vec<_>>() | 132 | .collect::<Vec<_>>() |
131 | }) | 133 | }) |
132 | .collect::<Vec<_>>(); | 134 | .collect::<Vec<_>>(); |
133 | symbols.par_sort_by(|s1, s2| s1.0.cmp(&s2.0)); | 135 | symbols.par_sort_by(|s1, s2| s1.0.cmp(&s2.0)); |
134 | symbols.dedup_by(|s1, s2| s1.0 == s2.0); | 136 | symbols.dedup_by(|s1, s2| s1.0 == s2.0); |
135 | let (names, symbols): (Vec<String>, Vec<(FileId, FileSymbol)>) = | 137 | let (names, symbols): (Vec<String>, Vec<FileSymbol>) = symbols.into_iter().unzip(); |
136 | symbols.into_iter().unzip(); | ||
137 | let map = fst::Map::from_iter(names.into_iter().zip(0u64..)).unwrap(); | 138 | let map = fst::Map::from_iter(names.into_iter().zip(0u64..)).unwrap(); |
138 | SymbolIndex { symbols, map } | 139 | SymbolIndex { symbols, map } |
139 | } | 140 | } |
@@ -144,7 +145,7 @@ impl SymbolIndex { | |||
144 | } | 145 | } |
145 | 146 | ||
146 | impl Query { | 147 | impl Query { |
147 | pub(crate) fn search(self, indices: &[Arc<SymbolIndex>]) -> Vec<(FileId, FileSymbol)> { | 148 | pub(crate) fn search(self, indices: &[Arc<SymbolIndex>]) -> Vec<FileSymbol> { |
148 | let mut op = fst::map::OpBuilder::new(); | 149 | let mut op = fst::map::OpBuilder::new(); |
149 | for file_symbols in indices.iter() { | 150 | for file_symbols in indices.iter() { |
150 | let automaton = fst::automaton::Subsequence::new(&self.lowercased); | 151 | let automaton = fst::automaton::Subsequence::new(&self.lowercased); |
@@ -160,14 +161,14 @@ impl Query { | |||
160 | let file_symbols = &indices[indexed_value.index]; | 161 | let file_symbols = &indices[indexed_value.index]; |
161 | let idx = indexed_value.value as usize; | 162 | let idx = indexed_value.value as usize; |
162 | 163 | ||
163 | let (file_id, symbol) = &file_symbols.symbols[idx]; | 164 | let symbol = &file_symbols.symbols[idx]; |
164 | if self.only_types && !is_type(symbol.ptr.kind()) { | 165 | if self.only_types && !is_type(symbol.ptr.kind()) { |
165 | continue; | 166 | continue; |
166 | } | 167 | } |
167 | if self.exact && symbol.name != self.query { | 168 | if self.exact && symbol.name != self.query { |
168 | continue; | 169 | continue; |
169 | } | 170 | } |
170 | res.push((*file_id, symbol.clone())); | 171 | res.push(symbol.clone()); |
171 | } | 172 | } |
172 | } | 173 | } |
173 | res | 174 | res |
@@ -185,17 +186,16 @@ fn is_type(kind: SyntaxKind) -> bool { | |||
185 | /// possible. | 186 | /// possible. |
186 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 187 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
187 | pub(crate) struct FileSymbol { | 188 | pub(crate) struct FileSymbol { |
189 | pub(crate) file_id: FileId, | ||
188 | pub(crate) name: SmolStr, | 190 | pub(crate) name: SmolStr, |
189 | pub(crate) ptr: LocalSyntaxPtr, | 191 | pub(crate) ptr: LocalSyntaxPtr, |
190 | } | 192 | } |
191 | 193 | ||
192 | fn to_symbol(node: SyntaxNodeRef) -> Option<FileSymbol> { | 194 | fn to_symbol(node: SyntaxNodeRef) -> Option<(SmolStr, LocalSyntaxPtr)> { |
193 | fn decl<'a, N: NameOwner<'a>>(node: N) -> Option<FileSymbol> { | 195 | fn decl<'a, N: NameOwner<'a>>(node: N) -> Option<(SmolStr, LocalSyntaxPtr)> { |
194 | let name = node.name()?; | 196 | let name = node.name()?.text(); |
195 | Some(FileSymbol { | 197 | let ptr = LocalSyntaxPtr::new(node.syntax()); |
196 | name: name.text(), | 198 | Some((name, ptr)) |
197 | ptr: LocalSyntaxPtr::new(node.syntax()), | ||
198 | }) | ||
199 | } | 199 | } |
200 | visitor() | 200 | visitor() |
201 | .visit(decl::<ast::FnDef>) | 201 | .visit(decl::<ast::FnDef>) |