From 939f05f3e33e9f00d5205d60af3a862ae4d58bd6 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 6 Feb 2020 12:43:56 +0100 Subject: [PATCH] Move to a crate --- Cargo.lock | 31 ++++++++++++ crates/ra_ide/Cargo.toml | 1 + crates/ra_ide/src/lib.rs | 5 +- crates/ra_ide_db/Cargo.toml | 48 +++++++++++++++++++ .../src/ide_db => ra_ide_db/src}/change.rs | 12 ++--- .../ide_db => ra_ide_db/src}/feature_flags.rs | 0 .../ide_db/mod.rs => ra_ide_db/src/lib.rs} | 15 +++--- .../ide_db => ra_ide_db/src}/line_index.rs | 0 .../src}/line_index_utils.rs | 4 +- .../ide_db => ra_ide_db/src}/symbol_index.rs | 26 +++++----- .../{ra_ide => ra_ide_db}/src/wasm_shims.rs | 0 11 files changed, 111 insertions(+), 31 deletions(-) create mode 100644 crates/ra_ide_db/Cargo.toml rename crates/{ra_ide/src/ide_db => ra_ide_db/src}/change.rs (97%) rename crates/{ra_ide/src/ide_db => ra_ide_db/src}/feature_flags.rs (100%) rename crates/{ra_ide/src/ide_db/mod.rs => ra_ide_db/src/lib.rs} (91%) rename crates/{ra_ide/src/ide_db => ra_ide_db/src}/line_index.rs (100%) rename crates/{ra_ide/src/ide_db => ra_ide_db/src}/line_index_utils.rs (99%) rename crates/{ra_ide/src/ide_db => ra_ide_db/src}/symbol_index.rs (95%) rename crates/{ra_ide => ra_ide_db}/src/wasm_shims.rs (100%) diff --git a/Cargo.lock b/Cargo.lock index 1aa121030ee..3ddf01dbfa4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1122,6 +1122,37 @@ dependencies = [ [[package]] name = "ra_ide" version = "0.1.0" +dependencies = [ + "either", + "format-buf", + "fst", + "indexmap", + "insta", + "itertools", + "join_to_string", + "log", + "once_cell", + "proptest", + "ra_assists", + "ra_cfg", + "ra_db", + "ra_fmt", + "ra_hir", + "ra_ide_db", + "ra_prof", + "ra_syntax", + "ra_text_edit", + "rand 0.7.3", + "rayon", + "rustc-hash", + "superslice", + "test_utils", + "unicase", +] + +[[package]] +name = "ra_ide_db" +version = "0.1.0" dependencies = [ "either", "format-buf", diff --git a/crates/ra_ide/Cargo.toml b/crates/ra_ide/Cargo.toml index 53817d1f765..9ace35229da 100644 --- a/crates/ra_ide/Cargo.toml +++ b/crates/ra_ide/Cargo.toml @@ -28,6 +28,7 @@ once_cell = "1.2.0" ra_syntax = { path = "../ra_syntax" } ra_text_edit = { path = "../ra_text_edit" } ra_db = { path = "../ra_db" } +ra_ide_db = { path = "../ra_ide_db" } ra_cfg = { path = "../ra_cfg" } ra_fmt = { path = "../ra_fmt" } ra_prof = { path = "../ra_prof" } diff --git a/crates/ra_ide/src/lib.rs b/crates/ra_ide/src/lib.rs index 66f365cc361..1527b27d417 100644 --- a/crates/ra_ide/src/lib.rs +++ b/crates/ra_ide/src/lib.rs @@ -10,7 +10,9 @@ // For proving that RootDatabase is RefUnwindSafe. #![recursion_limit = "128"] -mod ide_db; +mod ide_db { + pub use ra_ide_db::*; +} mod db; pub mod mock_analysis; @@ -39,7 +41,6 @@ mod typing; mod matching_brace; mod display; mod inlay_hints; -mod wasm_shims; mod expand; mod expand_macro; diff --git a/crates/ra_ide_db/Cargo.toml b/crates/ra_ide_db/Cargo.toml new file mode 100644 index 00000000000..1b7905eb3d6 --- /dev/null +++ b/crates/ra_ide_db/Cargo.toml @@ -0,0 +1,48 @@ +[package] +edition = "2018" +name = "ra_ide_db" +version = "0.1.0" +authors = ["rust-analyzer developers"] + +[lib] +doctest = false + +[features] +wasm = [] + +[dependencies] +either = "1.5" +format-buf = "1.0.0" +indexmap = "1.3.0" +itertools = "0.8.0" +join_to_string = "0.1.3" +log = "0.4.5" +rayon = "1.0.2" +fst = { version = "0.3.1", default-features = false } +rustc-hash = "1.0" +unicase = "2.2.0" +superslice = "1.0.0" +rand = { version = "0.7.0", features = ["small_rng"] } +once_cell = "1.2.0" + +ra_syntax = { path = "../ra_syntax" } +ra_text_edit = { path = "../ra_text_edit" } +ra_db = { path = "../ra_db" } +ra_cfg = { path = "../ra_cfg" } +ra_fmt = { path = "../ra_fmt" } +ra_prof = { path = "../ra_prof" } +test_utils = { path = "../test_utils" } +ra_assists = { path = "../ra_assists" } + +# ra_ide should depend only on the top-level `hir` package. if you need +# something from some `hir_xxx` subpackage, reexport the API via `hir`. +hir = { path = "../ra_hir", package = "ra_hir" } + +[dev-dependencies] +insta = "0.13.0" + +[dev-dependencies.proptest] +version = "0.9.0" +# Disable `fork` feature to allow compiling on webassembly +default-features = false +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 similarity index 97% rename from crates/ra_ide/src/ide_db/change.rs rename to crates/ra_ide_db/src/change.rs index 62ffa6920db..95a6ff28784 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; use rayon::prelude::*; use rustc_hash::FxHashMap; -use crate::ide_db::{ +use crate::{ symbol_index::{SymbolIndex, SymbolsDatabase}, DebugData, RootDatabase, }; @@ -168,12 +168,12 @@ impl LibraryData { const GC_COOLDOWN: time::Duration = time::Duration::from_millis(100); impl RootDatabase { - pub(crate) fn request_cancellation(&mut self) { + pub fn request_cancellation(&mut self) { let _p = profile("RootDatabase::request_cancellation"); self.salsa_runtime_mut().synthetic_write(Durability::LOW); } - pub(crate) fn apply_change(&mut self, change: AnalysisChange) { + pub fn apply_change(&mut self, change: AnalysisChange) { let _p = profile("RootDatabase::apply_change"); self.request_cancellation(); log::info!("apply_change {:?}", change); @@ -245,7 +245,7 @@ impl RootDatabase { self.set_source_root_with_durability(root_id, Arc::new(source_root), durability); } - pub(crate) fn maybe_collect_garbage(&mut self) { + pub fn maybe_collect_garbage(&mut self) { if cfg!(feature = "wasm") { return; } @@ -255,7 +255,7 @@ impl RootDatabase { } } - pub(crate) fn collect_garbage(&mut self) { + pub fn collect_garbage(&mut self) { if cfg!(feature = "wasm") { return; } @@ -282,7 +282,7 @@ impl RootDatabase { self.query(hir::db::BodyQuery).sweep(sweep); } - pub(crate) fn per_query_memory_usage(&mut self) -> Vec<(String, Bytes)> { + pub fn per_query_memory_usage(&mut self) -> Vec<(String, Bytes)> { let mut acc: Vec<(String, Bytes)> = vec![]; let sweep = SweepStrategy::default().discard_values().sweep_all_revisions(); 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 similarity index 100% rename from crates/ra_ide/src/ide_db/feature_flags.rs rename to 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 similarity index 91% rename from crates/ra_ide/src/ide_db/mod.rs rename to crates/ra_ide_db/src/lib.rs index 0df4d510fa5..d04c59a4a1e 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; pub mod feature_flags; pub mod symbol_index; pub mod change; +mod wasm_shims; use std::sync::Arc; @@ -15,9 +16,7 @@ use ra_db::{ }; use rustc_hash::FxHashMap; -use crate::ide_db::{ - feature_flags::FeatureFlags, line_index::LineIndex, symbol_index::SymbolsDatabase, -}; +use crate::{feature_flags::FeatureFlags, line_index::LineIndex, symbol_index::SymbolsDatabase}; #[salsa::database( ra_db::SourceDatabaseStorage, @@ -30,12 +29,12 @@ use crate::ide_db::{ hir::db::HirDatabaseStorage )] #[derive(Debug)] -pub(crate) struct RootDatabase { +pub struct RootDatabase { runtime: salsa::Runtime, - pub(crate) feature_flags: Arc, + pub feature_flags: Arc, pub(crate) debug_data: Arc, - pub(crate) last_gc: crate::wasm_shims::Instant, - pub(crate) last_gc_check: crate::wasm_shims::Instant, + pub last_gc: crate::wasm_shims::Instant, + pub last_gc_check: crate::wasm_shims::Instant, } impl FileLoader for RootDatabase { @@ -114,7 +113,7 @@ impl salsa::ParallelDatabase for RootDatabase { } #[salsa::query_group(LineIndexDatabaseStorage)] -pub(crate) trait LineIndexDatabase: ra_db::SourceDatabase + CheckCanceled { +pub trait LineIndexDatabase: ra_db::SourceDatabase + CheckCanceled { fn line_index(&self, file_id: FileId) -> Arc; } diff --git a/crates/ra_ide/src/ide_db/line_index.rs b/crates/ra_ide_db/src/line_index.rs similarity index 100% rename from crates/ra_ide/src/ide_db/line_index.rs rename to 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 similarity index 99% rename from crates/ra_ide/src/ide_db/line_index_utils.rs rename to crates/ra_ide_db/src/line_index_utils.rs index faa3d665ffc..daf9d8ab9f4 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 @@ use ra_syntax::{TextRange, TextUnit}; use ra_text_edit::{AtomTextEdit, TextEdit}; -use crate::ide_db::line_index::{LineCol, LineIndex, Utf16Char}; +use crate::line_index::{LineCol, LineIndex, Utf16Char}; #[derive(Debug, Clone)] enum Step { @@ -297,7 +297,7 @@ mod test { use ra_text_edit::test_utils::{arb_offset, arb_text_with_edit}; use ra_text_edit::TextEdit; - use crate::ide_db::line_index; + use crate::line_index; use super::*; diff --git a/crates/ra_ide/src/ide_db/symbol_index.rs b/crates/ra_ide_db/src/symbol_index.rs similarity index 95% rename from crates/ra_ide/src/ide_db/symbol_index.rs rename to crates/ra_ide_db/src/symbol_index.rs index c66eeb8e22b..33f042d8809 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::{ #[cfg(not(feature = "wasm"))] use rayon::prelude::*; -use crate::ide_db::RootDatabase; +use crate::RootDatabase; #[derive(Debug)] pub struct Query { @@ -83,7 +83,7 @@ impl Query { } #[salsa::query_group(SymbolsDatabaseStorage)] -pub(crate) trait SymbolsDatabase: hir::db::HirDatabase { +pub trait SymbolsDatabase: hir::db::HirDatabase { fn file_symbols(&self, file_id: FileId) -> Arc; #[salsa::input] fn library_symbols(&self, id: SourceRootId) -> Arc; @@ -108,7 +108,7 @@ fn file_symbols(db: &impl SymbolsDatabase, file_id: FileId) -> Arc Arc::new(SymbolIndex::new(symbols)) } -pub(crate) fn world_symbols(db: &RootDatabase, query: Query) -> Vec { +pub fn world_symbols(db: &RootDatabase, query: Query) -> Vec { /// Need to wrap Snapshot to provide `Clone` impl for `map_with` struct Snap(salsa::Snapshot); impl Clone for Snap { @@ -150,7 +150,7 @@ pub(crate) fn world_symbols(db: &RootDatabase, query: Query) -> Vec query.search(&buf) } -pub(crate) fn index_resolve(db: &RootDatabase, name_ref: &ast::NameRef) -> Vec { +pub fn index_resolve(db: &RootDatabase, name_ref: &ast::NameRef) -> Vec { let name = name_ref.text(); let mut query = Query::new(name.to_string()); query.exact(); @@ -159,7 +159,7 @@ pub(crate) fn index_resolve(db: &RootDatabase, name_ref: &ast::NameRef) -> Vec, map: fst::Map, } @@ -218,11 +218,11 @@ impl SymbolIndex { SymbolIndex { symbols, map } } - pub(crate) fn len(&self) -> usize { + pub fn len(&self) -> usize { self.symbols.len() } - pub(crate) fn memory_size(&self) -> usize { + pub fn memory_size(&self) -> usize { self.map.as_fst().size() + self.symbols.len() * mem::size_of::() } @@ -302,12 +302,12 @@ fn is_type(kind: SyntaxKind) -> bool { /// The actual data that is stored in the index. It should be as compact as /// possible. #[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub(crate) struct FileSymbol { - pub(crate) file_id: FileId, - pub(crate) name: SmolStr, - pub(crate) ptr: SyntaxNodePtr, - pub(crate) name_range: Option, - pub(crate) container_name: Option, +pub struct FileSymbol { + pub file_id: FileId, + pub name: SmolStr, + pub ptr: SyntaxNodePtr, + pub name_range: Option, + pub container_name: Option, } fn source_file_to_file_symbols(source_file: &SourceFile, file_id: FileId) -> Vec { diff --git a/crates/ra_ide/src/wasm_shims.rs b/crates/ra_ide_db/src/wasm_shims.rs similarity index 100% rename from crates/ra_ide/src/wasm_shims.rs rename to crates/ra_ide_db/src/wasm_shims.rs