aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_analysis/src
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-11-27 23:22:25 +0000
committerAleksey Kladov <[email protected]>2018-11-27 23:22:25 +0000
commit65c064b2a99fb9c0589672ae6c9848aaa9e0efcf (patch)
tree5327715b5c1ada71b1b7411922444e63dabf7bf7 /crates/ra_analysis/src
parent201aa7ea2ae75f9599dc74ad2f4d3f41c1540e73 (diff)
introduce SymbolsDatabase
Diffstat (limited to 'crates/ra_analysis/src')
-rw-r--r--crates/ra_analysis/src/db.rs28
-rw-r--r--crates/ra_analysis/src/imp.rs4
-rw-r--r--crates/ra_analysis/src/input.rs6
-rw-r--r--crates/ra_analysis/src/symbol_index.rs29
4 files changed, 40 insertions, 27 deletions
diff --git a/crates/ra_analysis/src/db.rs b/crates/ra_analysis/src/db.rs
index 4c9c84e4f..0901c2bba 100644
--- a/crates/ra_analysis/src/db.rs
+++ b/crates/ra_analysis/src/db.rs
@@ -7,7 +7,7 @@ use salsa::{self, Database};
7 7
8use crate::{ 8use crate::{
9 hir, 9 hir,
10 symbol_index::SymbolIndex, 10 symbol_index,
11 loc2id::{IdMaps}, 11 loc2id::{IdMaps},
12 Cancelable, Canceled, FileId, 12 Cancelable, Canceled, FileId,
13}; 13};
@@ -114,23 +114,25 @@ salsa::database_storage! {
114 fn file_source_root() for crate::input::FileSourceRootQuery; 114 fn file_source_root() for crate::input::FileSourceRootQuery;
115 fn source_root() for crate::input::SourceRootQuery; 115 fn source_root() for crate::input::SourceRootQuery;
116 fn libraries() for crate::input::LibrariesQuery; 116 fn libraries() for crate::input::LibrariesQuery;
117 fn library_symbols() for crate::input::LibrarySymbolsQuery;
118 fn crate_graph() for crate::input::CrateGraphQuery; 117 fn crate_graph() for crate::input::CrateGraphQuery;
119 } 118 }
120 impl SyntaxDatabase { 119 impl SyntaxDatabase {
121 fn file_syntax() for FileSyntaxQuery; 120 fn file_syntax() for FileSyntaxQuery;
122 fn file_lines() for FileLinesQuery; 121 fn file_lines() for FileLinesQuery;
123 fn file_symbols() for FileSymbolsQuery; 122 }
123 impl symbol_index::SymbolsDatabase {
124 fn file_symbols() for symbol_index::FileSymbolsQuery;
125 fn library_symbols() for symbol_index::LibrarySymbolsQuery;
124 } 126 }
125 impl hir::db::HirDatabase { 127 impl hir::db::HirDatabase {
126 fn module_tree() for hir::db::ModuleTreeQuery; 128 fn module_tree() for hir::db::ModuleTreeQuery;
127 fn fn_scopes() for hir::db::FnScopesQuery; 129 fn fn_scopes() for hir::db::FnScopesQuery;
128 fn _file_items() for hir::db::SourceFileItemsQuery; 130 fn file_items() for hir::db::SourceFileItemsQuery;
129 fn _file_item() for hir::db::FileItemQuery; 131 fn file_item() for hir::db::FileItemQuery;
130 fn _input_module_items() for hir::db::InputModuleItemsQuery; 132 fn input_module_items() for hir::db::InputModuleItemsQuery;
131 fn _item_map() for hir::db::ItemMapQuery; 133 fn item_map() for hir::db::ItemMapQuery;
132 fn _fn_syntax() for hir::db::FnSyntaxQuery; 134 fn fn_syntax() for hir::db::FnSyntaxQuery;
133 fn _submodules() for hir::db::SubmodulesQuery; 135 fn submodules() for hir::db::SubmodulesQuery;
134 } 136 }
135 } 137 }
136} 138}
@@ -143,9 +145,6 @@ salsa::query_group! {
143 fn file_lines(file_id: FileId) -> Arc<LineIndex> { 145 fn file_lines(file_id: FileId) -> Arc<LineIndex> {
144 type FileLinesQuery; 146 type FileLinesQuery;
145 } 147 }
146 fn file_symbols(file_id: FileId) -> Cancelable<Arc<SymbolIndex>> {
147 type FileSymbolsQuery;
148 }
149 } 148 }
150} 149}
151 150
@@ -157,8 +156,3 @@ fn file_lines(db: &impl SyntaxDatabase, file_id: FileId) -> Arc<LineIndex> {
157 let text = db.file_text(file_id); 156 let text = db.file_text(file_id);
158 Arc::new(LineIndex::new(&*text)) 157 Arc::new(LineIndex::new(&*text))
159} 158}
160fn file_symbols(db: &impl SyntaxDatabase, file_id: FileId) -> Cancelable<Arc<SymbolIndex>> {
161 db.check_canceled()?;
162 let syntax = db.file_syntax(file_id);
163 Ok(Arc::new(SymbolIndex::for_file(file_id, syntax)))
164}
diff --git a/crates/ra_analysis/src/imp.rs b/crates/ra_analysis/src/imp.rs
index 2e5853949..e3b78bb1a 100644
--- a/crates/ra_analysis/src/imp.rs
+++ b/crates/ra_analysis/src/imp.rs
@@ -25,7 +25,7 @@ use crate::{
25 Problem, 25 Problem,
26 }, 26 },
27 input::{FilesDatabase, SourceRoot, SourceRootId, WORKSPACE}, 27 input::{FilesDatabase, SourceRoot, SourceRootId, WORKSPACE},
28 symbol_index::SymbolIndex, 28 symbol_index::{SymbolIndex, SymbolsDatabase},
29 AnalysisChange, Cancelable, CrateGraph, CrateId, Diagnostic, FileId, FileResolver, 29 AnalysisChange, Cancelable, CrateGraph, CrateId, Diagnostic, FileId, FileResolver,
30 FileSystemEdit, FilePosition, Query, SourceChange, SourceFileNodeEdit, 30 FileSystemEdit, FilePosition, Query, SourceChange, SourceFileNodeEdit,
31}; 31};
@@ -161,7 +161,7 @@ impl AnalysisHostImpl {
161 .query_mut(crate::input::SourceRootQuery) 161 .query_mut(crate::input::SourceRootQuery)
162 .set(source_root_id, Arc::new(source_root)); 162 .set(source_root_id, Arc::new(source_root));
163 self.db 163 self.db
164 .query_mut(crate::input::LibrarySymbolsQuery) 164 .query_mut(crate::symbol_index::LibrarySymbolsQuery)
165 .set(source_root_id, Arc::new(library.symbol_index)); 165 .set(source_root_id, Arc::new(library.symbol_index));
166 } 166 }
167 self.db 167 self.db
diff --git a/crates/ra_analysis/src/input.rs b/crates/ra_analysis/src/input.rs
index 60086d1ae..e601cd58a 100644
--- a/crates/ra_analysis/src/input.rs
+++ b/crates/ra_analysis/src/input.rs
@@ -5,7 +5,7 @@ use rustc_hash::FxHashMap;
5use rustc_hash::FxHashSet; 5use rustc_hash::FxHashSet;
6use salsa; 6use salsa;
7 7
8use crate::{symbol_index::SymbolIndex, FileResolverImp}; 8use crate::FileResolverImp;
9 9
10#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] 10#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
11pub struct FileId(pub u32); 11pub struct FileId(pub u32);
@@ -56,10 +56,6 @@ salsa::query_group! {
56 type LibrariesQuery; 56 type LibrariesQuery;
57 storage input; 57 storage input;
58 } 58 }
59 fn library_symbols(id: SourceRootId) -> Arc<SymbolIndex> {
60 type LibrarySymbolsQuery;
61 storage input;
62 }
63 fn crate_graph() -> Arc<CrateGraph> { 59 fn crate_graph() -> Arc<CrateGraph> {
64 type CrateGraphQuery; 60 type CrateGraphQuery;
65 storage input; 61 storage input;
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<_>>()