aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_analysis/src/symbol_index.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_analysis/src/symbol_index.rs')
-rw-r--r--crates/ra_analysis/src/symbol_index.rs29
1 files changed, 26 insertions, 3 deletions
diff --git a/crates/ra_analysis/src/symbol_index.rs b/crates/ra_analysis/src/symbol_index.rs
index 3a0667ecd..a6937d7f2 100644
--- a/crates/ra_analysis/src/symbol_index.rs
+++ b/crates/ra_analysis/src/symbol_index.rs
@@ -4,14 +4,37 @@ use std::{
4}; 4};
5 5
6use fst::{self, Streamer}; 6use fst::{self, Streamer};
7use ra_editor::{file_symbols, FileSymbol}; 7use ra_editor::{self, FileSymbol};
8use ra_syntax::{ 8use ra_syntax::{
9 SourceFileNode, 9 SourceFileNode,
10 SyntaxKind::{self, *}, 10 SyntaxKind::{self, *},
11}; 11};
12use rayon::prelude::*; 12use rayon::prelude::*;
13 13
14use crate::{FileId, Query}; 14use crate::{
15 Cancelable,
16 FileId, Query,
17 db::SyntaxDatabase,
18 input::SourceRootId,
19};
20
21salsa::query_group! {
22 pub(crate) trait SymbolsDatabase: SyntaxDatabase {
23 fn file_symbols(file_id: FileId) -> Cancelable<Arc<SymbolIndex>> {
24 type FileSymbolsQuery;
25 }
26 fn library_symbols(id: SourceRootId) -> Arc<SymbolIndex> {
27 type LibrarySymbolsQuery;
28 storage input;
29 }
30 }
31}
32
33fn file_symbols(db: &impl SyntaxDatabase, file_id: FileId) -> Cancelable<Arc<SymbolIndex>> {
34 db.check_canceled()?;
35 let syntax = db.file_syntax(file_id);
36 Ok(Arc::new(SymbolIndex::for_file(file_id, syntax)))
37}
15 38
16#[derive(Default, Debug)] 39#[derive(Default, Debug)]
17pub(crate) struct SymbolIndex { 40pub(crate) struct SymbolIndex {
@@ -39,7 +62,7 @@ impl SymbolIndex {
39 ) -> SymbolIndex { 62 ) -> SymbolIndex {
40 let mut symbols = files 63 let mut symbols = files
41 .flat_map(|(file_id, file)| { 64 .flat_map(|(file_id, file)| {
42 file_symbols(&file) 65 ra_editor::file_symbols(&file)
43 .into_iter() 66 .into_iter()
44 .map(move |symbol| (symbol.name.as_str().to_lowercase(), (file_id, symbol))) 67 .map(move |symbol| (symbol.name.as_str().to_lowercase(), (file_id, symbol)))
45 .collect::<Vec<_>>() 68 .collect::<Vec<_>>()