diff options
-rw-r--r-- | Cargo.lock | 31 | ||||
-rw-r--r-- | crates/ra_ide/Cargo.toml | 1 | ||||
-rw-r--r-- | crates/ra_ide/src/lib.rs | 5 | ||||
-rw-r--r-- | crates/ra_ide_db/Cargo.toml | 48 | ||||
-rw-r--r-- | crates/ra_ide_db/src/change.rs (renamed from crates/ra_ide/src/ide_db/change.rs) | 12 | ||||
-rw-r--r-- | crates/ra_ide_db/src/feature_flags.rs (renamed from crates/ra_ide/src/ide_db/feature_flags.rs) | 0 | ||||
-rw-r--r-- | crates/ra_ide_db/src/lib.rs (renamed from crates/ra_ide/src/ide_db/mod.rs) | 15 | ||||
-rw-r--r-- | crates/ra_ide_db/src/line_index.rs (renamed from crates/ra_ide/src/ide_db/line_index.rs) | 0 | ||||
-rw-r--r-- | crates/ra_ide_db/src/line_index_utils.rs (renamed from crates/ra_ide/src/ide_db/line_index_utils.rs) | 4 | ||||
-rw-r--r-- | crates/ra_ide_db/src/symbol_index.rs (renamed from crates/ra_ide/src/ide_db/symbol_index.rs) | 26 | ||||
-rw-r--r-- | crates/ra_ide_db/src/wasm_shims.rs (renamed from crates/ra_ide/src/wasm_shims.rs) | 0 |
11 files changed, 111 insertions, 31 deletions
diff --git a/Cargo.lock b/Cargo.lock index 1aa121030..3ddf01dbf 100644 --- a/Cargo.lock +++ b/Cargo.lock | |||
@@ -1138,6 +1138,37 @@ dependencies = [ | |||
1138 | "ra_db", | 1138 | "ra_db", |
1139 | "ra_fmt", | 1139 | "ra_fmt", |
1140 | "ra_hir", | 1140 | "ra_hir", |
1141 | "ra_ide_db", | ||
1142 | "ra_prof", | ||
1143 | "ra_syntax", | ||
1144 | "ra_text_edit", | ||
1145 | "rand 0.7.3", | ||
1146 | "rayon", | ||
1147 | "rustc-hash", | ||
1148 | "superslice", | ||
1149 | "test_utils", | ||
1150 | "unicase", | ||
1151 | ] | ||
1152 | |||
1153 | [[package]] | ||
1154 | name = "ra_ide_db" | ||
1155 | version = "0.1.0" | ||
1156 | dependencies = [ | ||
1157 | "either", | ||
1158 | "format-buf", | ||
1159 | "fst", | ||
1160 | "indexmap", | ||
1161 | "insta", | ||
1162 | "itertools", | ||
1163 | "join_to_string", | ||
1164 | "log", | ||
1165 | "once_cell", | ||
1166 | "proptest", | ||
1167 | "ra_assists", | ||
1168 | "ra_cfg", | ||
1169 | "ra_db", | ||
1170 | "ra_fmt", | ||
1171 | "ra_hir", | ||
1141 | "ra_prof", | 1172 | "ra_prof", |
1142 | "ra_syntax", | 1173 | "ra_syntax", |
1143 | "ra_text_edit", | 1174 | "ra_text_edit", |
diff --git a/crates/ra_ide/Cargo.toml b/crates/ra_ide/Cargo.toml index 53817d1f7..9ace35229 100644 --- a/crates/ra_ide/Cargo.toml +++ b/crates/ra_ide/Cargo.toml | |||
@@ -28,6 +28,7 @@ once_cell = "1.2.0" | |||
28 | ra_syntax = { path = "../ra_syntax" } | 28 | ra_syntax = { path = "../ra_syntax" } |
29 | ra_text_edit = { path = "../ra_text_edit" } | 29 | ra_text_edit = { path = "../ra_text_edit" } |
30 | ra_db = { path = "../ra_db" } | 30 | ra_db = { path = "../ra_db" } |
31 | ra_ide_db = { path = "../ra_ide_db" } | ||
31 | ra_cfg = { path = "../ra_cfg" } | 32 | ra_cfg = { path = "../ra_cfg" } |
32 | ra_fmt = { path = "../ra_fmt" } | 33 | ra_fmt = { path = "../ra_fmt" } |
33 | ra_prof = { path = "../ra_prof" } | 34 | ra_prof = { path = "../ra_prof" } |
diff --git a/crates/ra_ide/src/lib.rs b/crates/ra_ide/src/lib.rs index 66f365cc3..1527b27d4 100644 --- a/crates/ra_ide/src/lib.rs +++ b/crates/ra_ide/src/lib.rs | |||
@@ -10,7 +10,9 @@ | |||
10 | // For proving that RootDatabase is RefUnwindSafe. | 10 | // For proving that RootDatabase is RefUnwindSafe. |
11 | #![recursion_limit = "128"] | 11 | #![recursion_limit = "128"] |
12 | 12 | ||
13 | mod ide_db; | 13 | mod ide_db { |
14 | pub use ra_ide_db::*; | ||
15 | } | ||
14 | 16 | ||
15 | mod db; | 17 | mod db; |
16 | pub mod mock_analysis; | 18 | pub mod mock_analysis; |
@@ -39,7 +41,6 @@ mod typing; | |||
39 | mod matching_brace; | 41 | mod matching_brace; |
40 | mod display; | 42 | mod display; |
41 | mod inlay_hints; | 43 | mod inlay_hints; |
42 | mod wasm_shims; | ||
43 | mod expand; | 44 | mod expand; |
44 | mod expand_macro; | 45 | mod expand_macro; |
45 | 46 | ||
diff --git a/crates/ra_ide_db/Cargo.toml b/crates/ra_ide_db/Cargo.toml new file mode 100644 index 000000000..1b7905eb3 --- /dev/null +++ b/crates/ra_ide_db/Cargo.toml | |||
@@ -0,0 +1,48 @@ | |||
1 | [package] | ||
2 | edition = "2018" | ||
3 | name = "ra_ide_db" | ||
4 | version = "0.1.0" | ||
5 | authors = ["rust-analyzer developers"] | ||
6 | |||
7 | [lib] | ||
8 | doctest = false | ||
9 | |||
10 | [features] | ||
11 | wasm = [] | ||
12 | |||
13 | [dependencies] | ||
14 | either = "1.5" | ||
15 | format-buf = "1.0.0" | ||
16 | indexmap = "1.3.0" | ||
17 | itertools = "0.8.0" | ||
18 | join_to_string = "0.1.3" | ||
19 | log = "0.4.5" | ||
20 | rayon = "1.0.2" | ||
21 | fst = { version = "0.3.1", default-features = false } | ||
22 | rustc-hash = "1.0" | ||
23 | unicase = "2.2.0" | ||
24 | superslice = "1.0.0" | ||
25 | rand = { version = "0.7.0", features = ["small_rng"] } | ||
26 | once_cell = "1.2.0" | ||
27 | |||
28 | ra_syntax = { path = "../ra_syntax" } | ||
29 | ra_text_edit = { path = "../ra_text_edit" } | ||
30 | ra_db = { path = "../ra_db" } | ||
31 | ra_cfg = { path = "../ra_cfg" } | ||
32 | ra_fmt = { path = "../ra_fmt" } | ||
33 | ra_prof = { path = "../ra_prof" } | ||
34 | test_utils = { path = "../test_utils" } | ||
35 | ra_assists = { path = "../ra_assists" } | ||
36 | |||
37 | # ra_ide should depend only on the top-level `hir` package. if you need | ||
38 | # something from some `hir_xxx` subpackage, reexport the API via `hir`. | ||
39 | hir = { path = "../ra_hir", package = "ra_hir" } | ||
40 | |||
41 | [dev-dependencies] | ||
42 | insta = "0.13.0" | ||
43 | |||
44 | [dev-dependencies.proptest] | ||
45 | version = "0.9.0" | ||
46 | # Disable `fork` feature to allow compiling on webassembly | ||
47 | default-features = false | ||
48 | features = ["std", "bit-set", "break-dead-code"] | ||
diff --git a/crates/ra_ide/src/ide_db/change.rs b/crates/ra_ide_db/src/change.rs index 62ffa6920..95a6ff287 100644 --- a/crates/ra_ide/src/ide_db/change.rs +++ b/crates/ra_ide_db/src/change.rs | |||
@@ -13,7 +13,7 @@ use ra_syntax::SourceFile; | |||
13 | use rayon::prelude::*; | 13 | use rayon::prelude::*; |
14 | use rustc_hash::FxHashMap; | 14 | use rustc_hash::FxHashMap; |
15 | 15 | ||
16 | use crate::ide_db::{ | 16 | use crate::{ |
17 | symbol_index::{SymbolIndex, SymbolsDatabase}, | 17 | symbol_index::{SymbolIndex, SymbolsDatabase}, |
18 | DebugData, RootDatabase, | 18 | DebugData, RootDatabase, |
19 | }; | 19 | }; |
@@ -168,12 +168,12 @@ impl LibraryData { | |||
168 | const GC_COOLDOWN: time::Duration = time::Duration::from_millis(100); | 168 | const GC_COOLDOWN: time::Duration = time::Duration::from_millis(100); |
169 | 169 | ||
170 | impl RootDatabase { | 170 | impl RootDatabase { |
171 | pub(crate) fn request_cancellation(&mut self) { | 171 | pub fn request_cancellation(&mut self) { |
172 | let _p = profile("RootDatabase::request_cancellation"); | 172 | let _p = profile("RootDatabase::request_cancellation"); |
173 | self.salsa_runtime_mut().synthetic_write(Durability::LOW); | 173 | self.salsa_runtime_mut().synthetic_write(Durability::LOW); |
174 | } | 174 | } |
175 | 175 | ||
176 | pub(crate) fn apply_change(&mut self, change: AnalysisChange) { | 176 | pub fn apply_change(&mut self, change: AnalysisChange) { |
177 | let _p = profile("RootDatabase::apply_change"); | 177 | let _p = profile("RootDatabase::apply_change"); |
178 | self.request_cancellation(); | 178 | self.request_cancellation(); |
179 | log::info!("apply_change {:?}", change); | 179 | log::info!("apply_change {:?}", change); |
@@ -245,7 +245,7 @@ impl RootDatabase { | |||
245 | self.set_source_root_with_durability(root_id, Arc::new(source_root), durability); | 245 | self.set_source_root_with_durability(root_id, Arc::new(source_root), durability); |
246 | } | 246 | } |
247 | 247 | ||
248 | pub(crate) fn maybe_collect_garbage(&mut self) { | 248 | pub fn maybe_collect_garbage(&mut self) { |
249 | if cfg!(feature = "wasm") { | 249 | if cfg!(feature = "wasm") { |
250 | return; | 250 | return; |
251 | } | 251 | } |
@@ -255,7 +255,7 @@ impl RootDatabase { | |||
255 | } | 255 | } |
256 | } | 256 | } |
257 | 257 | ||
258 | pub(crate) fn collect_garbage(&mut self) { | 258 | pub fn collect_garbage(&mut self) { |
259 | if cfg!(feature = "wasm") { | 259 | if cfg!(feature = "wasm") { |
260 | return; | 260 | return; |
261 | } | 261 | } |
@@ -282,7 +282,7 @@ impl RootDatabase { | |||
282 | self.query(hir::db::BodyQuery).sweep(sweep); | 282 | self.query(hir::db::BodyQuery).sweep(sweep); |
283 | } | 283 | } |
284 | 284 | ||
285 | pub(crate) fn per_query_memory_usage(&mut self) -> Vec<(String, Bytes)> { | 285 | pub fn per_query_memory_usage(&mut self) -> Vec<(String, Bytes)> { |
286 | let mut acc: Vec<(String, Bytes)> = vec![]; | 286 | let mut acc: Vec<(String, Bytes)> = vec![]; |
287 | let sweep = SweepStrategy::default().discard_values().sweep_all_revisions(); | 287 | let sweep = SweepStrategy::default().discard_values().sweep_all_revisions(); |
288 | macro_rules! sweep_each_query { | 288 | macro_rules! sweep_each_query { |
diff --git a/crates/ra_ide/src/ide_db/feature_flags.rs b/crates/ra_ide_db/src/feature_flags.rs index 85617640d..85617640d 100644 --- a/crates/ra_ide/src/ide_db/feature_flags.rs +++ b/crates/ra_ide_db/src/feature_flags.rs | |||
diff --git a/crates/ra_ide/src/ide_db/mod.rs b/crates/ra_ide_db/src/lib.rs index 0df4d510f..d04c59a4a 100644 --- a/crates/ra_ide/src/ide_db/mod.rs +++ b/crates/ra_ide_db/src/lib.rs | |||
@@ -5,6 +5,7 @@ pub mod line_index_utils; | |||
5 | pub mod feature_flags; | 5 | pub mod feature_flags; |
6 | pub mod symbol_index; | 6 | pub mod symbol_index; |
7 | pub mod change; | 7 | pub mod change; |
8 | mod wasm_shims; | ||
8 | 9 | ||
9 | use std::sync::Arc; | 10 | use std::sync::Arc; |
10 | 11 | ||
@@ -15,9 +16,7 @@ use ra_db::{ | |||
15 | }; | 16 | }; |
16 | use rustc_hash::FxHashMap; | 17 | use rustc_hash::FxHashMap; |
17 | 18 | ||
18 | use crate::ide_db::{ | 19 | use crate::{feature_flags::FeatureFlags, line_index::LineIndex, symbol_index::SymbolsDatabase}; |
19 | feature_flags::FeatureFlags, line_index::LineIndex, symbol_index::SymbolsDatabase, | ||
20 | }; | ||
21 | 20 | ||
22 | #[salsa::database( | 21 | #[salsa::database( |
23 | ra_db::SourceDatabaseStorage, | 22 | ra_db::SourceDatabaseStorage, |
@@ -30,12 +29,12 @@ use crate::ide_db::{ | |||
30 | hir::db::HirDatabaseStorage | 29 | hir::db::HirDatabaseStorage |
31 | )] | 30 | )] |
32 | #[derive(Debug)] | 31 | #[derive(Debug)] |
33 | pub(crate) struct RootDatabase { | 32 | pub struct RootDatabase { |
34 | runtime: salsa::Runtime<RootDatabase>, | 33 | runtime: salsa::Runtime<RootDatabase>, |
35 | pub(crate) feature_flags: Arc<FeatureFlags>, | 34 | pub feature_flags: Arc<FeatureFlags>, |
36 | pub(crate) debug_data: Arc<DebugData>, | 35 | pub(crate) debug_data: Arc<DebugData>, |
37 | pub(crate) last_gc: crate::wasm_shims::Instant, | 36 | pub last_gc: crate::wasm_shims::Instant, |
38 | pub(crate) last_gc_check: crate::wasm_shims::Instant, | 37 | pub last_gc_check: crate::wasm_shims::Instant, |
39 | } | 38 | } |
40 | 39 | ||
41 | impl FileLoader for RootDatabase { | 40 | impl FileLoader for RootDatabase { |
@@ -114,7 +113,7 @@ impl salsa::ParallelDatabase for RootDatabase { | |||
114 | } | 113 | } |
115 | 114 | ||
116 | #[salsa::query_group(LineIndexDatabaseStorage)] | 115 | #[salsa::query_group(LineIndexDatabaseStorage)] |
117 | pub(crate) trait LineIndexDatabase: ra_db::SourceDatabase + CheckCanceled { | 116 | pub trait LineIndexDatabase: ra_db::SourceDatabase + CheckCanceled { |
118 | fn line_index(&self, file_id: FileId) -> Arc<LineIndex>; | 117 | fn line_index(&self, file_id: FileId) -> Arc<LineIndex>; |
119 | } | 118 | } |
120 | 119 | ||
diff --git a/crates/ra_ide/src/ide_db/line_index.rs b/crates/ra_ide_db/src/line_index.rs index 6f99ca3a7..6f99ca3a7 100644 --- a/crates/ra_ide/src/ide_db/line_index.rs +++ b/crates/ra_ide_db/src/line_index.rs | |||
diff --git a/crates/ra_ide/src/ide_db/line_index_utils.rs b/crates/ra_ide_db/src/line_index_utils.rs index faa3d665f..daf9d8ab9 100644 --- a/crates/ra_ide/src/ide_db/line_index_utils.rs +++ b/crates/ra_ide_db/src/line_index_utils.rs | |||
@@ -3,7 +3,7 @@ | |||
3 | use ra_syntax::{TextRange, TextUnit}; | 3 | use ra_syntax::{TextRange, TextUnit}; |
4 | use ra_text_edit::{AtomTextEdit, TextEdit}; | 4 | use ra_text_edit::{AtomTextEdit, TextEdit}; |
5 | 5 | ||
6 | use crate::ide_db::line_index::{LineCol, LineIndex, Utf16Char}; | 6 | use crate::line_index::{LineCol, LineIndex, Utf16Char}; |
7 | 7 | ||
8 | #[derive(Debug, Clone)] | 8 | #[derive(Debug, Clone)] |
9 | enum Step { | 9 | enum Step { |
@@ -297,7 +297,7 @@ mod test { | |||
297 | use ra_text_edit::test_utils::{arb_offset, arb_text_with_edit}; | 297 | use ra_text_edit::test_utils::{arb_offset, arb_text_with_edit}; |
298 | use ra_text_edit::TextEdit; | 298 | use ra_text_edit::TextEdit; |
299 | 299 | ||
300 | use crate::ide_db::line_index; | 300 | use crate::line_index; |
301 | 301 | ||
302 | use super::*; | 302 | use super::*; |
303 | 303 | ||
diff --git a/crates/ra_ide/src/ide_db/symbol_index.rs b/crates/ra_ide_db/src/symbol_index.rs index c66eeb8e2..33f042d88 100644 --- a/crates/ra_ide/src/ide_db/symbol_index.rs +++ b/crates/ra_ide_db/src/symbol_index.rs | |||
@@ -40,7 +40,7 @@ use ra_syntax::{ | |||
40 | #[cfg(not(feature = "wasm"))] | 40 | #[cfg(not(feature = "wasm"))] |
41 | use rayon::prelude::*; | 41 | use rayon::prelude::*; |
42 | 42 | ||
43 | use crate::ide_db::RootDatabase; | 43 | use crate::RootDatabase; |
44 | 44 | ||
45 | #[derive(Debug)] | 45 | #[derive(Debug)] |
46 | pub struct Query { | 46 | pub struct Query { |
@@ -83,7 +83,7 @@ impl Query { | |||
83 | } | 83 | } |
84 | 84 | ||
85 | #[salsa::query_group(SymbolsDatabaseStorage)] | 85 | #[salsa::query_group(SymbolsDatabaseStorage)] |
86 | pub(crate) trait SymbolsDatabase: hir::db::HirDatabase { | 86 | pub trait SymbolsDatabase: hir::db::HirDatabase { |
87 | fn file_symbols(&self, file_id: FileId) -> Arc<SymbolIndex>; | 87 | fn file_symbols(&self, file_id: FileId) -> Arc<SymbolIndex>; |
88 | #[salsa::input] | 88 | #[salsa::input] |
89 | fn library_symbols(&self, id: SourceRootId) -> Arc<SymbolIndex>; | 89 | fn library_symbols(&self, id: SourceRootId) -> Arc<SymbolIndex>; |
@@ -108,7 +108,7 @@ fn file_symbols(db: &impl SymbolsDatabase, file_id: FileId) -> Arc<SymbolIndex> | |||
108 | Arc::new(SymbolIndex::new(symbols)) | 108 | Arc::new(SymbolIndex::new(symbols)) |
109 | } | 109 | } |
110 | 110 | ||
111 | pub(crate) fn world_symbols(db: &RootDatabase, query: Query) -> Vec<FileSymbol> { | 111 | pub fn world_symbols(db: &RootDatabase, query: Query) -> Vec<FileSymbol> { |
112 | /// Need to wrap Snapshot to provide `Clone` impl for `map_with` | 112 | /// Need to wrap Snapshot to provide `Clone` impl for `map_with` |
113 | struct Snap(salsa::Snapshot<RootDatabase>); | 113 | struct Snap(salsa::Snapshot<RootDatabase>); |
114 | impl Clone for Snap { | 114 | impl Clone for Snap { |
@@ -150,7 +150,7 @@ pub(crate) fn world_symbols(db: &RootDatabase, query: Query) -> Vec<FileSymbol> | |||
150 | query.search(&buf) | 150 | query.search(&buf) |
151 | } | 151 | } |
152 | 152 | ||
153 | pub(crate) fn index_resolve(db: &RootDatabase, name_ref: &ast::NameRef) -> Vec<FileSymbol> { | 153 | pub fn index_resolve(db: &RootDatabase, name_ref: &ast::NameRef) -> Vec<FileSymbol> { |
154 | let name = name_ref.text(); | 154 | let name = name_ref.text(); |
155 | let mut query = Query::new(name.to_string()); | 155 | let mut query = Query::new(name.to_string()); |
156 | query.exact(); | 156 | query.exact(); |
@@ -159,7 +159,7 @@ pub(crate) fn index_resolve(db: &RootDatabase, name_ref: &ast::NameRef) -> Vec<F | |||
159 | } | 159 | } |
160 | 160 | ||
161 | #[derive(Default)] | 161 | #[derive(Default)] |
162 | pub(crate) struct SymbolIndex { | 162 | pub struct SymbolIndex { |
163 | symbols: Vec<FileSymbol>, | 163 | symbols: Vec<FileSymbol>, |
164 | map: fst::Map, | 164 | map: fst::Map, |
165 | } | 165 | } |
@@ -218,11 +218,11 @@ impl SymbolIndex { | |||
218 | SymbolIndex { symbols, map } | 218 | SymbolIndex { symbols, map } |
219 | } | 219 | } |
220 | 220 | ||
221 | pub(crate) fn len(&self) -> usize { | 221 | pub fn len(&self) -> usize { |
222 | self.symbols.len() | 222 | self.symbols.len() |
223 | } | 223 | } |
224 | 224 | ||
225 | pub(crate) fn memory_size(&self) -> usize { | 225 | pub fn memory_size(&self) -> usize { |
226 | self.map.as_fst().size() + self.symbols.len() * mem::size_of::<FileSymbol>() | 226 | self.map.as_fst().size() + self.symbols.len() * mem::size_of::<FileSymbol>() |
227 | } | 227 | } |
228 | 228 | ||
@@ -302,12 +302,12 @@ fn is_type(kind: SyntaxKind) -> bool { | |||
302 | /// The actual data that is stored in the index. It should be as compact as | 302 | /// The actual data that is stored in the index. It should be as compact as |
303 | /// possible. | 303 | /// possible. |
304 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 304 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
305 | pub(crate) struct FileSymbol { | 305 | pub struct FileSymbol { |
306 | pub(crate) file_id: FileId, | 306 | pub file_id: FileId, |
307 | pub(crate) name: SmolStr, | 307 | pub name: SmolStr, |
308 | pub(crate) ptr: SyntaxNodePtr, | 308 | pub ptr: SyntaxNodePtr, |
309 | pub(crate) name_range: Option<TextRange>, | 309 | pub name_range: Option<TextRange>, |
310 | pub(crate) container_name: Option<SmolStr>, | 310 | pub container_name: Option<SmolStr>, |
311 | } | 311 | } |
312 | 312 | ||
313 | fn source_file_to_file_symbols(source_file: &SourceFile, file_id: FileId) -> Vec<FileSymbol> { | 313 | fn source_file_to_file_symbols(source_file: &SourceFile, file_id: FileId) -> Vec<FileSymbol> { |
diff --git a/crates/ra_ide/src/wasm_shims.rs b/crates/ra_ide_db/src/wasm_shims.rs index 088cc9be4..088cc9be4 100644 --- a/crates/ra_ide/src/wasm_shims.rs +++ b/crates/ra_ide_db/src/wasm_shims.rs | |||