mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-17 01:13:11 +00:00
Move to a crate
This commit is contained in:
parent
1bfb111cf9
commit
939f05f3e3
31
Cargo.lock
generated
31
Cargo.lock
generated
@ -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",
|
||||
|
@ -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" }
|
||||
|
@ -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;
|
||||
|
||||
|
48
crates/ra_ide_db/Cargo.toml
Normal file
48
crates/ra_ide_db/Cargo.toml
Normal 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"]
|
@ -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 {
|
@ -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<RootDatabase>,
|
||||
pub(crate) feature_flags: Arc<FeatureFlags>,
|
||||
pub feature_flags: Arc<FeatureFlags>,
|
||||
pub(crate) debug_data: Arc<DebugData>,
|
||||
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<LineIndex>;
|
||||
}
|
||||
|
@ -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::*;
|
||||
|
@ -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<SymbolIndex>;
|
||||
#[salsa::input]
|
||||
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))
|
||||
}
|
||||
|
||||
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`
|
||||
struct Snap(salsa::Snapshot<RootDatabase>);
|
||||
impl Clone for Snap {
|
||||
@ -150,7 +150,7 @@ pub(crate) fn world_symbols(db: &RootDatabase, query: Query) -> Vec<FileSymbol>
|
||||
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 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<F
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
pub(crate) struct SymbolIndex {
|
||||
pub struct SymbolIndex {
|
||||
symbols: Vec<FileSymbol>,
|
||||
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::<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
|
||||
/// 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<TextRange>,
|
||||
pub(crate) container_name: Option<SmolStr>,
|
||||
pub struct FileSymbol {
|
||||
pub file_id: FileId,
|
||||
pub name: SmolStr,
|
||||
pub ptr: SyntaxNodePtr,
|
||||
pub name_range: Option<TextRange>,
|
||||
pub container_name: Option<SmolStr>,
|
||||
}
|
||||
|
||||
fn source_file_to_file_symbols(source_file: &SourceFile, file_id: FileId) -> Vec<FileSymbol> {
|
Loading…
Reference in New Issue
Block a user