Move to a crate

This commit is contained in:
Aleksey Kladov 2020-02-06 12:43:56 +01:00
parent 1bfb111cf9
commit 939f05f3e3
11 changed files with 111 additions and 31 deletions

31
Cargo.lock generated
View file

@ -1122,6 +1122,37 @@ dependencies = [
[[package]] [[package]]
name = "ra_ide" name = "ra_ide"
version = "0.1.0" 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 = [ dependencies = [
"either", "either",
"format-buf", "format-buf",

View file

@ -28,6 +28,7 @@ once_cell = "1.2.0"
ra_syntax = { path = "../ra_syntax" } ra_syntax = { path = "../ra_syntax" }
ra_text_edit = { path = "../ra_text_edit" } ra_text_edit = { path = "../ra_text_edit" }
ra_db = { path = "../ra_db" } ra_db = { path = "../ra_db" }
ra_ide_db = { path = "../ra_ide_db" }
ra_cfg = { path = "../ra_cfg" } ra_cfg = { path = "../ra_cfg" }
ra_fmt = { path = "../ra_fmt" } ra_fmt = { path = "../ra_fmt" }
ra_prof = { path = "../ra_prof" } ra_prof = { path = "../ra_prof" }

View file

@ -10,7 +10,9 @@
// For proving that RootDatabase is RefUnwindSafe. // For proving that RootDatabase is RefUnwindSafe.
#![recursion_limit = "128"] #![recursion_limit = "128"]
mod ide_db; mod ide_db {
pub use ra_ide_db::*;
}
mod db; mod db;
pub mod mock_analysis; pub mod mock_analysis;
@ -39,7 +41,6 @@ mod typing;
mod matching_brace; mod matching_brace;
mod display; mod display;
mod inlay_hints; mod inlay_hints;
mod wasm_shims;
mod expand; mod expand;
mod expand_macro; mod expand_macro;

View file

@ -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"]

View file

@ -13,7 +13,7 @@ use ra_syntax::SourceFile;
use rayon::prelude::*; use rayon::prelude::*;
use rustc_hash::FxHashMap; use rustc_hash::FxHashMap;
use crate::ide_db::{ use crate::{
symbol_index::{SymbolIndex, SymbolsDatabase}, symbol_index::{SymbolIndex, SymbolsDatabase},
DebugData, RootDatabase, DebugData, RootDatabase,
}; };
@ -168,12 +168,12 @@ impl LibraryData {
const GC_COOLDOWN: time::Duration = time::Duration::from_millis(100); const GC_COOLDOWN: time::Duration = time::Duration::from_millis(100);
impl RootDatabase { impl RootDatabase {
pub(crate) fn request_cancellation(&mut self) { pub fn request_cancellation(&mut self) {
let _p = profile("RootDatabase::request_cancellation"); let _p = profile("RootDatabase::request_cancellation");
self.salsa_runtime_mut().synthetic_write(Durability::LOW); 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"); let _p = profile("RootDatabase::apply_change");
self.request_cancellation(); self.request_cancellation();
log::info!("apply_change {:?}", change); log::info!("apply_change {:?}", change);
@ -245,7 +245,7 @@ impl RootDatabase {
self.set_source_root_with_durability(root_id, Arc::new(source_root), durability); 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") { if cfg!(feature = "wasm") {
return; return;
} }
@ -255,7 +255,7 @@ impl RootDatabase {
} }
} }
pub(crate) fn collect_garbage(&mut self) { pub fn collect_garbage(&mut self) {
if cfg!(feature = "wasm") { if cfg!(feature = "wasm") {
return; return;
} }
@ -282,7 +282,7 @@ impl RootDatabase {
self.query(hir::db::BodyQuery).sweep(sweep); 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 mut acc: Vec<(String, Bytes)> = vec![];
let sweep = SweepStrategy::default().discard_values().sweep_all_revisions(); let sweep = SweepStrategy::default().discard_values().sweep_all_revisions();
macro_rules! sweep_each_query { macro_rules! sweep_each_query {

View file

@ -5,6 +5,7 @@ pub mod line_index_utils;
pub mod feature_flags; pub mod feature_flags;
pub mod symbol_index; pub mod symbol_index;
pub mod change; pub mod change;
mod wasm_shims;
use std::sync::Arc; use std::sync::Arc;
@ -15,9 +16,7 @@ use ra_db::{
}; };
use rustc_hash::FxHashMap; use rustc_hash::FxHashMap;
use crate::ide_db::{ use crate::{feature_flags::FeatureFlags, line_index::LineIndex, symbol_index::SymbolsDatabase};
feature_flags::FeatureFlags, line_index::LineIndex, symbol_index::SymbolsDatabase,
};
#[salsa::database( #[salsa::database(
ra_db::SourceDatabaseStorage, ra_db::SourceDatabaseStorage,
@ -30,12 +29,12 @@ use crate::ide_db::{
hir::db::HirDatabaseStorage hir::db::HirDatabaseStorage
)] )]
#[derive(Debug)] #[derive(Debug)]
pub(crate) struct RootDatabase { pub struct RootDatabase {
runtime: salsa::Runtime<RootDatabase>, runtime: salsa::Runtime<RootDatabase>,
pub(crate) feature_flags: Arc<FeatureFlags>, pub feature_flags: Arc<FeatureFlags>,
pub(crate) debug_data: Arc<DebugData>, pub(crate) debug_data: Arc<DebugData>,
pub(crate) last_gc: crate::wasm_shims::Instant, pub last_gc: crate::wasm_shims::Instant,
pub(crate) last_gc_check: crate::wasm_shims::Instant, pub last_gc_check: crate::wasm_shims::Instant,
} }
impl FileLoader for RootDatabase { impl FileLoader for RootDatabase {
@ -114,7 +113,7 @@ impl salsa::ParallelDatabase for RootDatabase {
} }
#[salsa::query_group(LineIndexDatabaseStorage)] #[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<LineIndex>; fn line_index(&self, file_id: FileId) -> Arc<LineIndex>;
} }

View file

@ -3,7 +3,7 @@
use ra_syntax::{TextRange, TextUnit}; use ra_syntax::{TextRange, TextUnit};
use ra_text_edit::{AtomTextEdit, TextEdit}; 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)] #[derive(Debug, Clone)]
enum Step { enum Step {
@ -297,7 +297,7 @@ mod test {
use ra_text_edit::test_utils::{arb_offset, arb_text_with_edit}; use ra_text_edit::test_utils::{arb_offset, arb_text_with_edit};
use ra_text_edit::TextEdit; use ra_text_edit::TextEdit;
use crate::ide_db::line_index; use crate::line_index;
use super::*; use super::*;

View file

@ -40,7 +40,7 @@ use ra_syntax::{
#[cfg(not(feature = "wasm"))] #[cfg(not(feature = "wasm"))]
use rayon::prelude::*; use rayon::prelude::*;
use crate::ide_db::RootDatabase; use crate::RootDatabase;
#[derive(Debug)] #[derive(Debug)]
pub struct Query { pub struct Query {
@ -83,7 +83,7 @@ impl Query {
} }
#[salsa::query_group(SymbolsDatabaseStorage)] #[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<SymbolIndex>; fn file_symbols(&self, file_id: FileId) -> Arc<SymbolIndex>;
#[salsa::input] #[salsa::input]
fn library_symbols(&self, id: SourceRootId) -> Arc<SymbolIndex>; fn library_symbols(&self, id: SourceRootId) -> Arc<SymbolIndex>;
@ -108,7 +108,7 @@ fn file_symbols(db: &impl SymbolsDatabase, file_id: FileId) -> Arc<SymbolIndex>
Arc::new(SymbolIndex::new(symbols)) Arc::new(SymbolIndex::new(symbols))
} }
pub(crate) fn world_symbols(db: &RootDatabase, query: Query) -> Vec<FileSymbol> { pub fn world_symbols(db: &RootDatabase, query: Query) -> Vec<FileSymbol> {
/// Need to wrap Snapshot to provide `Clone` impl for `map_with` /// Need to wrap Snapshot to provide `Clone` impl for `map_with`
struct Snap(salsa::Snapshot<RootDatabase>); struct Snap(salsa::Snapshot<RootDatabase>);
impl Clone for Snap { impl Clone for Snap {
@ -150,7 +150,7 @@ pub(crate) fn world_symbols(db: &RootDatabase, query: Query) -> Vec<FileSymbol>
query.search(&buf) query.search(&buf)
} }
pub(crate) fn index_resolve(db: &RootDatabase, name_ref: &ast::NameRef) -> Vec<FileSymbol> { pub fn index_resolve(db: &RootDatabase, name_ref: &ast::NameRef) -> Vec<FileSymbol> {
let name = name_ref.text(); let name = name_ref.text();
let mut query = Query::new(name.to_string()); let mut query = Query::new(name.to_string());
query.exact(); query.exact();
@ -159,7 +159,7 @@ pub(crate) fn index_resolve(db: &RootDatabase, name_ref: &ast::NameRef) -> Vec<F
} }
#[derive(Default)] #[derive(Default)]
pub(crate) struct SymbolIndex { pub struct SymbolIndex {
symbols: Vec<FileSymbol>, symbols: Vec<FileSymbol>,
map: fst::Map, map: fst::Map,
} }
@ -218,11 +218,11 @@ impl SymbolIndex {
SymbolIndex { symbols, map } SymbolIndex { symbols, map }
} }
pub(crate) fn len(&self) -> usize { pub fn len(&self) -> usize {
self.symbols.len() 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::<FileSymbol>() self.map.as_fst().size() + self.symbols.len() * mem::size_of::<FileSymbol>()
} }
@ -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 /// The actual data that is stored in the index. It should be as compact as
/// possible. /// possible.
#[derive(Debug, Clone, PartialEq, Eq, Hash)] #[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub(crate) struct FileSymbol { pub struct FileSymbol {
pub(crate) file_id: FileId, pub file_id: FileId,
pub(crate) name: SmolStr, pub name: SmolStr,
pub(crate) ptr: SyntaxNodePtr, pub ptr: SyntaxNodePtr,
pub(crate) name_range: Option<TextRange>, pub name_range: Option<TextRange>,
pub(crate) container_name: Option<SmolStr>, pub container_name: Option<SmolStr>,
} }
fn source_file_to_file_symbols(source_file: &SourceFile, file_id: FileId) -> Vec<FileSymbol> { fn source_file_to_file_symbols(source_file: &SourceFile, file_id: FileId) -> Vec<FileSymbol> {