From 9a7db8fa009c612168ef16f6ed72315b5406ed09 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 24 Oct 2018 17:25:10 +0300 Subject: simplify roots --- Cargo.lock | 12 ------------ crates/ra_analysis/Cargo.toml | 3 --- crates/ra_analysis/src/imp.rs | 25 +++++++++++++------------ crates/ra_analysis/src/lib.rs | 4 ---- crates/ra_analysis/src/roots.rs | 24 +++++------------------- 5 files changed, 18 insertions(+), 50 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 625f2aeac..d1a294c30 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -508,14 +508,6 @@ dependencies = [ "libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "once_cell" -version = "0.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "parking_lot 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "owning_ref" version = "0.3.3" @@ -610,9 +602,6 @@ name = "ra_analysis" version = "0.1.0" dependencies = [ "fst 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", - "once_cell 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", - "parking_lot 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)", "ra_editor 0.1.0", "ra_syntax 0.1.0", "rayon 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1330,7 +1319,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum num-integer 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)" = "e83d528d2677f0518c570baf2b7abdcf0cd2d248860b68507bdcb3e91d4c0cea" "checksum num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "0b3a5d7cc97d6d30d8b9bc8fa19bf45349ffe46241e8816f50f62f6d6aaabee1" "checksum num_cpus 1.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c51a3322e4bca9d212ad9a158a02abc6934d005490c054a2778df73a70aa0a30" -"checksum once_cell 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "d7ce3535d54560c937c1652ba4a0da66bfc63e0f8e07bed127483afb6e5ee925" "checksum owning_ref 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "cdf84f41639e037b484f93433aa3897863b561ed65c6e59c7073d7c561710f37" "checksum parking_lot 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)" = "f0802bff09003b291ba756dc7e79313e51cc31667e94afbe847def490424cde5" "checksum parking_lot_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ad7f7e6ebdc79edff6fdcb87a55b620174f7a989e3eb31b65231f4af57f00b8c" diff --git a/crates/ra_analysis/Cargo.toml b/crates/ra_analysis/Cargo.toml index 0f5ff6d24..75a9dc844 100644 --- a/crates/ra_analysis/Cargo.toml +++ b/crates/ra_analysis/Cargo.toml @@ -6,9 +6,6 @@ authors = ["Aleksey Kladov "] [dependencies] relative-path = "0.4.0" -log = "0.4.2" -parking_lot = "0.6.3" -once_cell = "0.1.5" rayon = "1.0.2" fst = "0.3.1" ra_syntax = { path = "../ra_syntax" } diff --git a/crates/ra_analysis/src/imp.rs b/crates/ra_analysis/src/imp.rs index 83a0dc445..f142b6c43 100644 --- a/crates/ra_analysis/src/imp.rs +++ b/crates/ra_analysis/src/imp.rs @@ -16,7 +16,8 @@ use relative_path::RelativePath; use rustc_hash::FxHashSet; use crate::{ - descriptors::module::{ModuleTree, Problem}, + db::SyntaxDatabase, + descriptors::module::{ModulesDatabase, ModuleTree, Problem}, descriptors::{FnDescriptor}, roots::{ReadonlySourceRoot, SourceRoot, WritableSourceRoot}, CrateGraph, CrateId, Diagnostic, FileId, FileResolver, FileSystemEdit, Position, @@ -143,10 +144,10 @@ impl AnalysisImpl { .unwrap() } pub fn file_syntax(&self, file_id: FileId) -> File { - self.root(file_id).syntax(file_id) + self.root(file_id).db().file_syntax(file_id) } pub fn file_line_index(&self, file_id: FileId) -> Arc { - self.root(file_id).lines(file_id) + self.root(file_id).db().file_lines(file_id) } pub fn world_symbols(&self, query: Query) -> Cancelable> { let mut buf = Vec::new(); @@ -161,14 +162,14 @@ impl AnalysisImpl { } pub fn parent_module(&self, file_id: FileId) -> Cancelable> { let root = self.root(file_id); - let module_tree = root.module_tree()?; + let module_tree = root.db().module_tree()?; let res = module_tree.modules_for_file(file_id) .into_iter() .filter_map(|module_id| { let link = module_id.parent_link(&module_tree)?; let file_id = link.owner(&module_tree).file_id(&module_tree); - let syntax = root.syntax(file_id); + let syntax = root.db().file_syntax(file_id); let decl = link.bind_source(&module_tree, syntax.ast()); let sym = FileSymbol { @@ -182,7 +183,7 @@ impl AnalysisImpl { Ok(res) } pub fn crate_for(&self, file_id: FileId) -> Cancelable> { - let module_tree = self.root(file_id).module_tree()?; + let module_tree = self.root(file_id).db().module_tree()?; let crate_graph = &self.data.crate_graph; let res = module_tree.modules_for_file(file_id) .into_iter() @@ -202,8 +203,8 @@ impl AnalysisImpl { offset: TextUnit, ) -> Cancelable> { let root = self.root(file_id); - let module_tree = root.module_tree()?; - let file = root.syntax(file_id); + let module_tree = root.db().module_tree()?; + let file = root.db().file_syntax(file_id); let syntax = file.syntax(); if let Some(name_ref) = find_node_at_offset::(syntax, offset) { // First try to resolve the symbol locally @@ -253,7 +254,7 @@ impl AnalysisImpl { pub fn find_all_refs(&self, file_id: FileId, offset: TextUnit) -> Vec<(FileId, TextRange)> { let root = self.root(file_id); - let file = root.syntax(file_id); + let file = root.db().file_syntax(file_id); let syntax = file.syntax(); let mut ret = vec![]; @@ -285,8 +286,8 @@ impl AnalysisImpl { pub fn diagnostics(&self, file_id: FileId) -> Cancelable> { let root = self.root(file_id); - let module_tree = root.module_tree()?; - let syntax = root.syntax(file_id); + let module_tree = root.db().module_tree()?; + let syntax = root.db().file_syntax(file_id); let mut res = ra_editor::diagnostics(&syntax) .into_iter() @@ -376,7 +377,7 @@ impl AnalysisImpl { offset: TextUnit, ) -> Cancelable)>> { let root = self.root(file_id); - let file = root.syntax(file_id); + let file = root.db().file_syntax(file_id); let syntax = file.syntax(); // Find the calling expression and it's NameRef diff --git a/crates/ra_analysis/src/lib.rs b/crates/ra_analysis/src/lib.rs index a03f44205..67a239a5c 100644 --- a/crates/ra_analysis/src/lib.rs +++ b/crates/ra_analysis/src/lib.rs @@ -1,8 +1,4 @@ -extern crate parking_lot; -#[macro_use] -extern crate log; extern crate fst; -extern crate once_cell; extern crate ra_editor; extern crate ra_syntax; extern crate rayon; diff --git a/crates/ra_analysis/src/roots.rs b/crates/ra_analysis/src/roots.rs index 15081f555..aa0243720 100644 --- a/crates/ra_analysis/src/roots.rs +++ b/crates/ra_analysis/src/roots.rs @@ -17,9 +17,7 @@ use crate::{ pub(crate) trait SourceRoot { fn contains(&self, file_id: FileId) -> bool; - fn module_tree(&self) -> Cancelable>; - fn lines(&self, file_id: FileId) -> Arc; - fn syntax(&self, file_id: FileId) -> File; + fn db(&self) -> &db::RootDatabase; fn symbols(&self, acc: &mut Vec>) -> Cancelable<()>; } @@ -63,17 +61,11 @@ impl WritableSourceRoot { } impl SourceRoot for WritableSourceRoot { - fn module_tree(&self) -> Cancelable> { - self.db.module_tree() - } fn contains(&self, file_id: FileId) -> bool { self.db.file_set().files.contains(&file_id) } - fn lines(&self, file_id: FileId) -> Arc { - self.db.file_lines(file_id) - } - fn syntax(&self, file_id: FileId) -> File { - self.db.file_syntax(file_id) + fn db(&self) -> &db::RootDatabase { + &self.db } fn symbols<'a>(&'a self, acc: &mut Vec>) -> Cancelable<()> { for &file_id in self.db.file_set().files.iter() { @@ -114,17 +106,11 @@ impl ReadonlySourceRoot { } impl SourceRoot for ReadonlySourceRoot { - fn module_tree(&self) -> Cancelable> { - self.db.module_tree() - } fn contains(&self, file_id: FileId) -> bool { self.db.file_set().files.contains(&file_id) } - fn lines(&self, file_id: FileId) -> Arc { - self.db.file_lines(file_id) - } - fn syntax(&self, file_id: FileId) -> File { - self.db.file_syntax(file_id) + fn db(&self) -> &db::RootDatabase { + &self.db } fn symbols(&self, acc: &mut Vec>) -> Cancelable<()> { acc.push(Arc::clone(&self.symbol_index)); -- cgit v1.2.3